If you’re new to web development and are getting to know the languages involved, you may be wondering whether one of them—CSS—is a programming language.
Technically, Cascading Style Sheets, or CSS, is not a programming language. It’s a style sheet language used in conjunction with HTML to determine the look and feel of web pages. With that said, some still consider CSS a programming language.
What Is a Programming Language, Exactly?
There is a general consensus in the computer engineering community that a programming language is a language construct that allows developers to create sets of instructions that can be executed by computers. These sets of instructions are called “programs,” “applications,” or simply “apps.”
A computer program can be as sophisticated as Microsoft Office or Adobe Photoshop and at the same time as simple as your phone’s flashlight or calculator app. What is certain is that, no matter what the program is, it must contain a set of instructions that the computer can execute.
However, the consensus on what a programming language is ends here. And here, we enter murky waters, especially when it comes to CSS.
So, Is CSS a Programming Language or Not?
Well, let’s just say that there’s a case for and against CSS being a programming language.
There’s no doubt that HTML is not a programming language—it’s a markup language. It tells web browsers about the structure of a web page, but it doesn’t instruct them what to do regarding it.
For example, the following HTML markup tells browsers that the text enclosed in the <p>
tag is a paragraph:
<p>This is a paragraph.</p>
So where does this leave us when it comes to CSS?
Say we want to stick to the example above. To build on it, we can write a CSS rule that makes the text in all paragraphs—that is, any text that’s enclosed in a <p>
tag—16 pixels large and with a blue color. Our CSS rule would look like this:
p {
color: blue;
font-size: 16px;
}
Is this programming or not?
Most programmers I know would say that it isn’t because you’re describing something, but you’re not necessarily instructing anything. You’re simply stating, with CSS syntax, that the text in all paragraphs should have a blue color and be 16 pixels large.
In other words, you’re writing CSS code, but you’re not developing a computer program. You’re simply styling an HTML document. In a way, it isn’t much different from using BBcode to bold a sentence or two in a forum post.
By this definition, JavaScript, PHP, Python, and other languages used for developing websites and web applications are programming languages, but HTML and CSS aren’t.
And yet others disagree with this definition.
They claim that CSS is in fact a programming language because it gives instructions to the computer, even if those instructions are how to display the DOM elements of an HTML document.
Another reason why CSS may classify as a programming language may be that you can encode Rule 110 in CSS if you try really (and I mean really) hard.
Of course, actually using CSS for programming would be impractical, and it wouldn’t produce great results.
The Bottom Line
CSS is a style sheet language, and CSS syntax shares many similarities with certain scripting languages for the web, such as JavaScript.
Some say CSS is a programming language, others claim it’s not. As with many other things in life, the truth is in the eyes of the beholder. Then again, does it really matter?