DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Is CSS an Object-Oriented Programming Language?
Alvaro Montoro
Alvaro Montoro

Posted on • Originally published at alvaromontoro.com

Is CSS an Object-Oriented Programming Language?

For the past six months, I have been running comiCSS, an "experiment" in which I draw web-related cartoons and comics using HTML and CSS.

I published a version of the Angry NPC Wojak meme a couple of weeks ago. It went mostly unnoticed, but it didn't matter because it was just preparation for this week's comic. A larger version of the meme that explored a question that pops now and then on Twitter: Is CSS a programming language? Then I twisted and stretched it a little and took the joke further:

Modified version of the Angry Wojak meme showing two people talking. The first panel shows a person saying 'CSS is not a programming language'. The second panel has another person replying 'Of course it is! What are the main concepts of OOP?' Then proceeds to 'explain' how CSS 'has' encapsulation, inheritance, abstraction, and polymorphism, so it should be considered an object-oriented programming language. The last panels show the first person, first normal (without saying anything) then angry.

The comic seemed to go unnoticed again but then became viral on the /r/ProgrammerHumor channel on Reddit (without the poster adding a source or attribution for it πŸ˜“). And the answers from people were… interesting, to say the least –that's the Reddit way, no?

I had a blast reading the comments. From both sides, but especially the ones from people that are taking a joke way too seriously: people calling me an idiot for not knowing what OOP is, people defending CSS as their life depended on it, people debating if inheritance or polymorphism in CSS is possible considering this or that other factor…

As always, with the "XYZ is not a programming language" controversy, it's not a matter of proving a point. So many people want to drag other developers through the mud and diminish their contribution, which is sad. Whatever your opinion is, don't be that type of person.

But I digress. Now, for the question in this article's title: Is CSS an object-oriented programming language? The answer is "No." Even if it fulfilled the main concepts of OOP (which are exaggerated and stretched for comic purposes), that wouldn't make it an object-oriented programming language. But that doesn't matter because being OOP or not being OOP doesn't make CSS (or any other language) a lesser language. It is beautiful, useful, and incredible as it is (and will keep being.)

There will be more comiCSS cartoons and comic strips in the future. I hope all of them are as entertaining as this one 😊


If you liked this cartoon, follow comiCSS on Twitter or support it by becoming a patron on Patreon.

Top comments (21)

Collapse
raibtoffoletto profile image
RaΓ­ B. Toffoletto

CSSTricks proved you can do a calculator only with CSS... so I'll leave at that for those wanting to discuss what programing languages are.... 🀣.

I personally loved to cartoon!! Shows how labeling stuff is really not that important.

Collapse
alvaromontoro profile image
Alvaro Montoro Author

This. 1,000 times this!!!

Collapse
tandudev profile image
tandu-dev

Where? I'd love to see how that was done

Collapse
alvaromontoro profile image
Alvaro Montoro Author

Lillian Kodi coded one: codepen.io/lillian-kodi/pen/YzZLebR

Collapse
auroratide profile image
Timothy Foster

My God, attempting to read through the reddit comments was like trying to steer a cruise liner by pushing it with a safety raft. Perhaps the subreddit is more for people laughing at others than with others.

Collapse
alvaromontoro profile image
Alvaro Montoro Author

I guess that's the Reddit-way?

Collapse
afif profile image
Temani Afif

I warned you ...

Now, I won't be surprised if someone is killed in that reddit post.

Collapse
alvaromontoro profile image
Alvaro Montoro Author

You did warn me.

Did I do it anyway? Yes.

Will I do it again? Definitely yes. 😈

Collapse
alvaromontoro profile image
Alvaro Montoro Author • Edited on

Actually, I have an idea related to this that will get more people even more angry. I need to show it to you. I find it hilarious, but I doubt many people will ;P

Collapse
darkwiiplayer profile image
π’Š©Wii πŸ’–πŸ’›πŸ’šπŸ’™πŸ’œπŸ’πŸ’Ÿ

The comic seemed to go unnoticed again but then became viral on the /r/ProgrammerHumor channel on Reddit (without the poster adding a source or attribution for it πŸ˜“).

Yea, that subreddit is an absolute shitshow of dunning-kruger enthusiasts who think chanting "all code is copied from stack-overflow" while standing in a circle wearing dark hoods is somehow funny and original. Not surprised they wouldn't bother linking to the original.

That being said, I strongly disagree with calling CSS an object-oriented language (or even a programming language at all, albeit with a much weaker opinion). It shares some concepts of OOP, but it lacks the most central one: Objects. At the end of the day, CSS only lets you define classes (as in, OOP classes, which correspond to selectors, not CSS classes) but not instantiate them (that's what HTML does). Adding HTML, you then still lack another essential aspect, which is message-passing; HTML+CSS objects exist, but they don't interact. They can old state, but they don't have any behaviour. Once you addΒ JS to the mix, you do end up with a proper object-oriented system of sorts, where CSSΒ and JS define the classes and HTML instantiates the objects, but that's not normally the way developers think about websites (which is a shame, because it's a very powerful mental model).

Collapse
peerreynders profile image
peerreynders • Edited on

I've always viewed CSS as the language to create rule sets for a domain specific rules engine.

RulesEngine

martinfowler.com

One issue is that people will often try to define things in terms they (think they) understand rather than taking a step back and trying to evaluate whether they are missing some key information (in their "known unknowns" or "unknown unknowns" zones) that may explain things better.

Collapse
fyodorio profile image
Fyodor

The next one should be about Turing completeness of CSS, it will blow out

Collapse
alvaromontoro profile image
Alvaro Montoro Author

Something something calc() and attr() something something πŸ˜…

Collapse
kolja profile image
Kolja

Now i understand the principles of OOPπŸ˜ƒ

Collapse
alvaromontoro profile image
Alvaro Montoro Author • Edited on

animated gif showing a man (Nathan Filion) trying to correct or make a comment, the stop resigned

Collapse
natescode profile image
Nathan Hedglin

Love it. Yes, developers take everything too seriously. Great comic. Keep it up!

Collapse
alvaromontoro profile image
Alvaro Montoro Author

Thanks!

Collapse
sksallaj profile image
Sultan Sallaj

People have a problem trying to attack the concept because people bought so deeply into the concept of OOP and not the actual programming. There is no programming in CSS, like there is no concept of variables or functions - that's the programming part. What CSS can do is mimic how variables work - like creating 8,16, or 32 bit registers, and creating how functions work by utilizing html events. Is it scalable? Not for business logic. It's super amazing for the presentation of any html framework. That's why seeing applications built by html and css looks magical, but lets see them carry the business load of requirement revisions. There's no way code like that can be copied and pasted without some sort of architectural consideration.

Collapse
eunicejoslyn profile image
EuniceJoslyn
Collapse
akostadinov profile image
Aleksandar Kostadinov

I think with a descent standard library, CSS could make it..

Collapse
ravavyr profile image
Ravavyr

Anyone seriously contemplating the definition of CSS for a long time....needs to rethink things. In the mean time I'll be over here building websites and web applications. lol

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.