• Is CSS a Programming Language?
  • Originally by Chris Coyier
  • The Nuggets translation Project
  • Permanent link to this article: github.com/xitu/gold-m…
  • Translator: cncuckoo
  • Proofreader: Kimhooo, Chorer

I hate this question. On the surface, this seems like an interesting question to explore, but people rarely show sincerity when discussing it. There are ulterior motives involved in respect, emotional protection and a desire to disrupt or maintain the status quo.

If someone can prove that the CSS is not a programming language (this is a grey area, if this is your goal, to prove that it is not difficult), then they can because the “real” programming skills and continue to think superiority, at the same time also can rationalize their salary (may be) than focused on the fact that CSS front-end developer. This is the status quo.

The reverse is also possible. If you can prove that CSS is a programming language, then maybe you can push your own company or industry to treat the UI experts of front-end developers with equal respect and pay. This is breaking the status quo.

Assuming that CSS is not a programming language, we all agree on a Boolean value of true or false. And then what? Does true mean that salaries for all Web practitioners will converge? Does choosing False mean CSS experts should be paid less? True, does it mean that all people are free from prejudice and respect each other? False, does that mean that CSS writers have to eat boxed lunches in the boiler room? I doubt anything will ever change, which is why I hate talking about it.

Whatever the truth, it’s unrealistic for most people to accept CSS as a programming language. I mean, the program needs to be “executed,” right? No one questions whether JavaScript is a programming language, because it executes. You write code, and you execute it. Maybe you’ll write something like this in a terminal window:

> node my-program.js
Copy the code

No, really. This program will work. You can use console.log(“Hello World! ); The “Hello World!” Print to the console.

CSS can’t do it! Well, that’s fine, unless you write body::after {content: “Hello, World!” in style.css. ; }, then open the page where the CSS file is loaded. Look, CSS also executes. But in its own special way. It is a DSL (Domain-specific Language) rather than a GPL (General-purpose Language). In a browser environment, the way you make CSS run (usually ) isn’t even that different from the way you make JavaScript run (usually

If you want to compare CSS syntax and programming concepts, I think you can find the corresponding one. What is the selector doing if there isn’t some sort of if statement running the loop match? How does calc() get the answer if it doesn’t do the math? How do media queries work if there is no concept of switch? How do you use custom properties if there’s no place to save state? If Boolean logic is not present, when does :checked take effect? Eric recently proved that CSS is a strongly typed language, and he suggested earlier that CSS is full of functions.

In any case, the answer to whether CSS is a programming language matters. A university professor who once proved to his students that CSS was not Turing-complete is now rethinking the idea after learning that it is. Whatever the purpose, I think the fact that computer science professors speak to computer science students year after year like this definitely has an impact on the industry.

Lara Schenck has dug deep into Turing’s complete position. If you’re trying to solve this problem, Turing completeness is a good place to go. The bottom line is that CSS is basically Turing-complete (in terms of cellular automata Rule 110), just not entirely on its own. This involves the complex application of selectors and (somewhat surprisingly) checked. Lara makes a witty observation:

In isolation, CSS is not Turing-complete. CSS plus HTML plus user input is Turing-complete!

Suppose you still don’t buy it. But you understand, and even concede, well, CSS is basically Turing-complete, except that you don’t think OF CSS (or HTML) as a programming language. After all, it’s too declarative, too application-specific. Either way, I really don’t blame you. What I hope is that whatever conclusion you come to, the answer doesn’t affect what really matters [1], like pay and respect.

Respect is necessary regardless of which of us seeks an answer to this question. I don’t think CSS is a programming language, but that doesn’t mean I don’t think it’s important or that my CSS colleagues are less valuable than my Python colleagues. Wouldn’t that be great? I think declarative markup languages have an interesting difference from other types of languages, but they’re all code. Okay, that’s it. I’m embarrassed by an in-depth answer like that.

Hopefully, when similar discussions come up again, we’ll see more informed, respectful, less self-centered comments.


  1. Just like “website” and “Web application”. Whether you think there’s a difference or not, I hope people don’t make decisions that affect users based on their own subjective categorization.

If you find any mistakes in your translation or other areas that need to be improved, you are welcome to the Nuggets Translation Program to revise and PR your translation, and you can also get the corresponding reward points. The permanent link to this article at the beginning of this article is the MarkDown link to this article on GitHub.


The Nuggets Translation Project is a community that translates quality Internet technical articles from English sharing articles on nuggets. The content covers Android, iOS, front-end, back-end, blockchain, products, design, artificial intelligence and other fields. If you want to see more high-quality translation, please continue to pay attention to the Translation plan of Digging Gold, the official Weibo, Zhihu column.