What Is Syntax?

Definition of syntax and why proper syntax is important

Syntax error in programming

Valentin Wolf / Getty Images

In the computer world, the syntax of a command refers to the rules in which the command must be run in order for a piece of software to understand it.

For example, a command's syntax may dictate case-sensitivity and what kinds of options are available that make the command operate in different ways.

Without proper syntax, the words and other characters that make up the command aren't strung together in a sequence that makes sense. What results from bad syntax is the inability for the syntax reader to understand what's trying to be conveyed.

Syntax Is Like a Language

Languages in a bubble

To better understand computer syntax, think of it as a language, like English, German, Spanish, etc.

A language syntax requires that certain words and punctuation be used in the right way so that someone hearing or reading the words can understand them correctly. If words and characters are placed incorrectly in a sentence, it'll be very difficult to understand.

Much like with language, the structure, or syntax, of a computer command must be coded or executed perfectly in order for it to be understood, with all the words, symbols, and other characters positioned in just the right way.

Why Is Syntax Important?

Would you expect someone who reads and speaks only in Russian to understand Japanese? Or what about someone who only understands English, to be able to read words written in Italian?

Similarly, different programs (much like different languages) require different rules that must be followed so that the software (or person, with spoken language) can interpret your requests.

For example, you wouldn't say "I down ran the hill large." because that hardly makes any sense given the rules English speakers have come to understand when it comes to comprehending words. The same is true for command syntax because the program reading the syntax only understands it when it's set up a specific way, as you'll see below.

It's important to not overlook syntax when it comes to working with computer commands because even a tiny, seemingly acceptable error in syntax will mean that a computer can't understand what it is that you're after.

Let's look at the ping command as an example of proper, and improper, syntax. The most common way that the ping command is used is by executing ping, followed by an IP address, like this:

ping 192.168.1.1

This syntax is 100 percent correct, and because it's correct, the command-line interpreter, probably Command Prompt in Windows, can understand that we're wanting to check if the computer can communicate with that specific device on the network.

However, the command will not work if we rearrange the text and put the IP address first, and then the word ping, like this:

192.168.1.1 ping

We're not using the right syntax, so although the command looks a bit like it should, it will not work at all because the computer has no idea how to handle it.

Computer commands that have the wrong syntax are often said to have a syntax error, and will not run as intended until the syntax is corrected.

Although it's certainly possible with simpler commands (as you saw with ping), you're much more likely to run into a syntax error as computer commands get more and more complex. Just look at these format command examples to see what we mean.

Syntax errors aren't just limited to commands like the ones just mentioned, but also to any other programming language like HTML or JavaScript. Just consider how many potential syntax mistakes could be made when coding something like a whole operating system like Windows XP, which required 45 million lines of code!

You can see in just this one example with ping that it's very important to be able to not only read syntax correctly but to of course be able to apply it perfectly.

Proper Syntax With Command Prompt Commands

Every command does something different, so they each have different syntax. Looking through our table of Command Prompt commands is a quick way to see just how many commands there are in Windows, all of which have certain rules that apply to how they can be used.

See How to Read Command Syntax for detailed help deciphering the syntax we use on this site when describing how a particular command can, or can not, be executed.