A syntax error occurs when a program does not follow the syntactical rules of the programming language.