2 ms·
The class attribute from HTML has about as much to do with CSS as the id attribute. Those "CSS class names" are just HTML classes. They were invented for HTML
by cxr 2y ago
The class attribute from HTML has about as much to do with CSS as the id attribute.
Those "CSS class names" are just HTML classes. They were invented for HTML, you write them in HTML, and they're part of the HTML spec.
It's become evident from comments on HN recently that people apparently think they're a CSS thing (because that's how they're taught CSS) but they're just an ordinary fixture of markup; they're for describing the class of something. Accordingly, stuff like class="alert-box warning" is the correct way to use classes (rather than e.g. class="3px-red-border" or whatever).
- nicbou 2y agoDo they have any other purpose besides CSS though? They were even hard to use as selectors in JS until querySelector appeared.
- cxr 2y agoI'm not sure you're grokking what I'm saying. The answer to your question is "yes, of course". The class attribute has _nothing_ to do with CSS (or JS). The CSS people didn't give us the class attribute (and the HTML people didn't put it in so that we could use CSS better). HTML had class attributes before CSS or JS ever existed.