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.