In context of a programming language syntax refers to the structure of the program without concerning about it’s meaning. Syntax gives the emphasis on design or layout of the program.
Semantics term in a programming language is used to figure out the relationship among the syntax and the model of computation used in the program
Syntax errors occur during the parsing of input code and are caused by grammatically incorrect statements. … Semantic errors occur during the execution of the code, after it has been parsed as grammatically correct. These have to do not with how statements are constructed, but with what they mean.
A syntax error means the compiler can’t understand the code as written - there’s a token that’s not allowed according to grammar. The equivalent in natural language would be a sentence like “There watermelon ; is before the .wdf.es” - it doesn’t conform to punctuation rules at all, some of the letter sequences aren’t even words, there’s no making sense of it.
A semantic error means you got past the syntax step (i.e. tokenising and parsing) but (usually at runtime) the resulting logic makes no sense. For our natural language example “The smiling cadillacs went forward at great backwards - to thunderous blancmange.” is grammatically correct with good punctuation but is complete nonsense as a sentence.
Semantic errors often occur in weakly typed languages where a pointer can references anything, and are usually at runtime rather than compile time (though this is not universal)