Grammar consists of set rules regarding language and sentence structure, such as no splitting infinitives and no hanging prepositions.
Syntax is how a sentence is worded and structured. It consists of the type of sentence (Declarative, Interrogative, Exclamatory, Imperative) and word order (passive vs. active voice) It also refers to length of sentences (short vs. long).
Syntax can be used as a literary device to add extra meaning to your sentences, whereas grammar adds no greater meaning to your sentences. Example: “His long-held wish was to walk slowly through the tortuous mountain paths that his grandfather had carved out of the earth many years ago”.
Syntax would refer to the sentence being declarative: stating a wish that the boy had. It would also refer to the length of the sentence mimicking the long twisted paths in the mountain and the long time the boy had been wishing to walk them.
Grammar would refer to not splitting the infinitive: “to walk slowly” rather than “to slowly walk” and subject-verb agreement.
Syntax has literary meaning and use, while Grammar just shows good form. They are two different things that can be easily confused.
Other statement says that the different is that Morphology is how words change, add endings and stuff, like, I go, he goes, I went, he went, I have gone, he has gone; Syntax is how words are put in a particular order and how they depend
on each other and how that morphology stuff of one word depends on the
morphological stuff of other words and the other way round. Grammar is morphology plus syntax. However, people often think that grammar is only that morphology stuff only.