Grammar is the broader set of rules for how a language works, while syntax is narrower and covers specifically how words are arranged into correct sentences. Memory hook: syntax is about the sequence of words, and both start with s. A missing semicolon in code is a syntax error, not a grammar error.
The core difference
Grammar is the overall system of rules structuring a language, while syntax is the part of that system dealing with word order and sentence arrangement.
- syntax — the rules governing how words are arranged to form correct phrases and sentences: Learning a new language means getting used to its syntax as well as its vocabulary.
- grammar — the rules governing how words are structured and combined into sentences in a language: She studied English grammar to improve her writing.
How to tell them apart
Think of grammar as the whole rulebook for a language, covering everything from word forms to punctuation, and syntax as one chapter of that rulebook: the part about word order. Every syntax rule is a grammar rule, but not every grammar rule is about syntax.
Syntax also has a specific meaning in computing, where it refers to the formal rules for writing valid statements in a programming language. A syntax error there, like a missing semicolon, means the code breaks a structural rule, which is why programmers say syntax rather than grammar even though the idea is similar.