Inline Styles as Classes: A CSS Joke Taken Apart
If inline styles bother you, one suggestion is to move the style contents into a class attribute instead—provided you then have CSS that actually does what the attribute claims it does.
I've revolutionized CSS. pic.twitter.com/1AWCldyCwP
— sam "zerowidthspace" thor (@samthor) June 10, 2021
The author then breaks the joke down piece by piece.
- It is a joke, and shouldn't be used for real. Occasional inline styles for one-off cases are fine, but this goes well beyond that.
- The period (
.) character is the strangest part. Backslash-escaping unusual characters feels normal, but the period does not—until the update explains it comes from the space: the HTML holds two classes, not one. - The period trick fails when the next character is a number, as in
.padding:.1rem;. The update explains why: classes starting with a number are invalid. - An attribute selector such as
[class*="display: flex;"]avoids the escaping and trickery altogether. - This brings to mind Mathias Bynens' work on CSS character escape sequences, though it apparently no longer works—it is unclear whether browsers changed or the tool stopped outputting what it should (e.g., does
.color\3A \ #f06d06look right?).
The article rounds out with a demonstration of all this experimentation.
Sponsor CSS-Tricks!
There are many ways to connect with the front-end community.
CSS-Tricks Newsletter
Ads are self-hosted



