Object-Oriented HTML, and OOCSS
Published on August 6, 2013 (↻ July 8, 2024), filed under Development (RSS feed for all categories).
This and many other posts are also available as a pretty, well-behaved ebook: On Web Development.
“Object-oriented CSS” is the idea of treating page elements as objects, giving all these objects classes, treating objects’ classes as single entities in style sheets, and taking it from there. I’ve never commented on OOCSS as it was never relevant for my work. As supposedly so useful it should have been relevant though, so it piqued my interest and I reviewed the old OOCSS site and Smashing Magazine’s introduction.
Objects and HTML
The idea of objects in HTML seems generally compelling. I was interested in a possible terminology, and jotted down the following:
-
Simple objects: elements (headings, paragraphs, &c.).
-
Complex objects, or composite objects: multiple elements combined (for articles, widgets, &c.).
-
Native objects: developed specifically for a site or page.
-
External objects: all-purpose, both by other teams (like a video module developed by other in-house developers) or of truly external origin (like Twitter or Facebook widgets).
-
Combinations thereof.
Objects and CSS
Now we meet OOCSS, and to me (who may err), it looks like we’re dealing with a misunderstanding of HTML and CSS:
-
There are different types of objects in HTML, and without a clear distinction (as attempted above) an object-oriented approach seems misguided. There are different levels of interaction and complexity between simple, complex, native, and external objects.
-
There’s nothing wrong with IDs; IDs are an important part of the cascade. Similarly, there’s nothing wrong with descendant selectors (performance? that argument is none); these are also important. In my view, depriving authors of these cannot be an option.
Suggesting authors to think objects without differentiation and then to stay away from vital parts of CSS may not be enough to establish a different web development technique (let alone paradigm).
The arguments set forth with OOCSS also appear contradictory (easier to use but learning curve, good for performance but also not).
OOCSS supporters then admit OOCSS to be problematic (“for smaller sites and apps […] OOCSS would be overkill”).
This is not good. It’s not a sign of our maturity that the topic of object-oriented CSS, conceived in 2009, isn’t entirely clear—or dead by now.
About Me
I’m Jens (long: Jens Oliver Meiert), and I’m a frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, and I write and review books for O’Reilly and Frontend Dogma.
I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Please be critical, interpret charitably, and give feedback.)
Comments (Closed)
-
On August 7, 2013, 9:12 CEST, Raphael said:
Hi from France,
The “object CSS” (what a terrible name) are only useful for reusable behaviors (.module, .row, .clearfix, etc..) and this is also why the HTML classes were created at the beginning: to classify / group HTML elements on a common affiliation.
In the case of complex, single or external objects, the concept of “object CSS” has no reason to be: use a name (using id or class) for the “special” items.
-
On September 1, 2013, 6:32 CEST, Randy Merrill said:
A lot of these things are things that seem to be solved by the work being done with web components and projects like Polymer.
The idea of taking complex objects and either provide your own interface for styling, events, and logic in self contained units.
There is a lot of things still to be done on it but it allows for developers to create their own ‘object’ elements.
It also works well for embedding external components into pages since the component controls everything unless it gives specific access to the internals.
Read More
Maybe of interest to you, too:
- Next: The Meanings of Googliness
- Previous: Goodbye Google, San Francisco, California, and United States
- More under Development
- More from 2013
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.info—and The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.