What is a programming language?
First, we need to define what a programming language is, right? Well, according to what I've read:
A programming language is a set of rules and symbols that allow programmers to communicate with a computer to write instructions that it can understand.
If you think about it this way, a programming language is anything that allows us to interact with a computer to make it do something specific. So, CSS falls into this category because the browser interprets its rules to display beautiful and organized web pages. However, pure CSS doesn't have things like loops or conditionals, which are important in "serious" languages like Python or JavaScript.
CSS: A declarative language
Something that helped me understand this is that CSS is declarative. That is, it describes the "what" and not the "how." For example, in CSS, you say you want text to be red and 16 pixels in size, but you can't tell it "if this happens, do that." For that, you need other things like JavaScript or SCSS. In other words, CSS doesn't have that "logic" as such.
SCSS and SASS: Closer to programming
This is where SCSS and SASS make a difference. These tools are like improved versions of CSS that do have programmatic logic. For example:
-
Variables and functions: In SCSS, you can store values and use them later. This makes everything more organized.
$primary-color: #3498db;
body {
background-color: $primary-color;
} -
Conditionals and loops: You can do things like "if this is so, do this" or repeat an action several times. This is already programming.
@for $i from 1 through 5 {
.item-#{$i} {
width: #{10 * $i}px;
}
}
-
Mixins and inheritance: These are basically blocks of styles that you can use in various places. Like copy and paste, but more elegant.
@mixin button-styles {
padding: 10px;
border-radius: 5px;
}
.button {
@include button-styles;
}
Thanks to these tools, I feel that SCSS and SASS are indeed programming languages, or at least very close.
So, does CSS count as a programming language?
Well, here's the dilemma. CSS has rules that the browser interprets, so technically you could say you "program" with CSS. But on the other hand, it doesn't have conditionals or loops, so many don't consider it a complete programming language. I think it depends on how you look at it.
If you use SCSS or SASS, things change. These tools let you write real logic, like conditionals or loops, which is super useful for large projects. Additionally, pure CSS has also evolved with things like calc() or clamp(), which add a bit of mathematical logic.
My conclusion
In my opinion, CSS by itself is not a "traditional" programming language. But if we add SCSS or SASS, then I would say it does fall into that category. In the end, I think the important thing is not so much the label, but how we use these tools to create amazing things on the web.
This is my first article, so if you've made it this far, thanks for reading! I hope it has been helpful or at least made you think a little more about this topic. What do you think? Is CSS a programming language or not? I'll read your thoughts!