Grammar= syntax + morphology. Morphology is the study of morphemes and how we understand them. Morphemes are the basic building blocks of words and the smallest units of meaning in language. They are groups of letters which make up a word’s root, pre-fix or suffix. When morphemes are combined, they create more nuanced meaning. For example, the word ‘played’ in English contains ‘play’ + ‘ed’ with the second morpheme letting us know the verb is in past tense.
Syntax requires us to zoom out a bit in scope and look at how words come together in a sentence to communicate meaning. Syntax rules are silent laws dictating how we assemble words in the correct order so people will understand us. If you want to have good grammar, you need to know your way around the syntax of a language to create a solid sentence. You also need to know your morphology, so the words arranged are in their correct form.
Note, some might also argue phonology, the pronunciation rules of a language, and semantics, the study of word relations and meaning, can be added to our grammar equation.