Syntax Highlighting

Updated Sept 29, 2020 · 2 min read

What is syntax highlighting?

Syntax highlighting is a strategy for improving the readability of code by coloring or bolding elements of a programming or markup language. Elements include keywords, comments, control flow statements, and variables. Syntax highlighting doesn’t affect the meaning of the code. It simply reinforces the meaning of the code.

Evidence suggests that syntax highlighting greatly reduces the time taken for a developer to understand the semantics of a program. Through syntax highlighting, developers can more easily identify syntax errors and scan code for important segments. For example, syntax highlighting can help developers quickly pick out comments or find missing braces in their code.

Example of syntax highlighting

The following snippet of JavaScript is written as plain text. It’s difficult to identify the elements of the language quickly with how it’s written.

function msg(){
 alert("Hello World"); 
} 

The following snippet uses syntax highlighting to enhance the readability of the code so you can more easily pick out the elements of the language:

function msg(){
 alert("Hello World"); 
} 

Related Terms

Programming
Programming Languages

A programming language is a formal set of rules along with a unique syntax for instructing a computer to perform tasks.