Attributes-driven Styles: The Good, the Bad, and the Unknown
Why do we primarily use class selectors to style our elements?
Here are some common answers:
- They work
- That's what I learned
- That's what [insert framework here] uses
- I work quickly with them
Some more (slightly better) answers:
- Some of my toolset relies on CSS classes for processing
- They are pretty flexible
Sure, there are a lot of other combinatorial selectors we use, but overall, when targeting an element, we use class selectors most often.
I'm here to challenge your thinking and broaden our horizons a bit by using custom attributes for styling.
About Jonathan Cutrell
Jonathan is a builder, scholar, teacher, and advocate for craftsmanship in any field. Jonathan hosts Developer Tea, a top-listed podcast dedicated to exploring the development craft. Jonathan leads a team of developers daily at Whiteboard, and works in Chattanooga, TN where he lives with his wife Lauren (who also works at Whiteboard) and dog, Evie (who is currently unemployed).