Syntax refers to the set of rules that govern the structure and composition of a programming language or markup language, ensuring proper code formation.