đ¨ cascading stylesheets
or, the "and you thought JS was bad" part.
ie6, or, âhow i think kids have it too easy these daysâ. (source unknown :-/)
tl;dr
- CSS for newbies: MDN guide, CodeSandbox, CodePen, CSS Zen Garden
- defining colors, a minor note:
oklch - beyond CSS: CSS Modules and CSS-in-JS: CSS Modules (guide), Farewell CSS, CSS in JS, A Unified Styling Language, emotion, vanilla-extract, StyleX, and more CSS-in-JS packages
- anti-Tailwind: an opinionated takedown.
- setup: PostCSS, browserslist, sanitize.css
- preprocessors: Sass
- looking ahead: CSS-Tricks, cssdb, New features for 2025
- resources: CSS-Tricks, Can I use�, Can I email�, MDN reference, Stack Overflow, Google Developers, State of CSS, CSS Zen Garden, Learn CSS
CSS for newbies
if youâre absolutely new to CSS, start here at the Mozilla Developer Network (or MDN). theyâre the people that make Firefox and have the best reference guides for CSS. in general though this guide assumes youâve got a base understanding of CSS so go forth and mess around with the language as much as you can before moving on to the rest of the more complicated stuff.
playgrounds
an easy way to get started is by checking out some of these tools that let you play around with the language:
- CodeSandbox: lets you mess around with a React app in real-time.
- CodePen: a social development environment for front-end designers and developers.
- CSS Zen Garden: shows you how a single HTML page can look a 1,000 different ways. this site goes way back and was inspiration to many a designer/developer. (you can mess around with the CSS via the Developer Tools in your browser.)
defining colors, a minor note
thereâs been a lot of standards around color, beginning with rgb and including other fancier things like hsl. the new âkingâ of color definition is oklch.
speaking of colors, if you need a good color palette picker here's Color Palette Pro.
beyond CSS: CSS Modules and CSS-in-JS
this guide is about writing an application not a regular webpage. to that end, you shouldnât be using regular CSS with <style> tags anymore â as your application grows and more contributors add to it, you will drown in a sea of madness and salty tears. yes, your mother taught you to wash behind your ears, brush your teeth, and never, EVER use inline styles in your HTML. but those days are over and a new era has come.
the truth is that this space is still rapidly in development and the dust isnât quite settled yet. i think there are compelling arguments for both CSS-in-JS and CSS Modules. youâll probably fine going with either these days.
finally, there's also truth in this: whatever you pick may never be enough
CSS Modules: a happy middle ground
CSS Modules are a great way to get a lot of the benefits of CSS-in-JS without leaving the CSS world altogether. hereâs a helpful primer on getting started.
CSS-in-JS: some compelling arguments
CSS-in-JS forgoes CSS files altogether and says we should have our styling where our components are. think about it this way. when youâre sharing HTML these days, we tend to do so via HTML-in-JS. in other words, one can create React components and publish them to the general web to share to fellow developers. similarly, one could argue, the best way to share CSS is to package them inside of something standard like JS.
great reads on the topic
- Farewell CSS: a great take on why you should probably be doing CSS-in-JS.
- CSS in JS: a watershed moment of a slideshow arguing for you to forget everything you now about how inline styles are bad.
- A Unified Styling Language: from the co-creator of CSS modules, an argument for CSS-in-JS and to leave behind things like BEM which are only conventions/opt-in vs. something thatâs baked-in to a methodology.
package options
again, thereâs so much action going on in this space that itâs still to be decided what paradigm will win here. for now though, my tentative recommendation is emotion.
- emotion: rapidly in development, new to the party. ânext-genâ.
- vanilla-extract
- StyleX
- Pigment CSS: MUI's companion CSS kit that may(?) end up being a thing one day?
- glamorous: uses objects in JS to declare CSS for a particular module.
- Aphrodite: uses objects and lets you do server-side rendering, too.
- polished: lets you write CSS rules in a more semantic way. the âlodashâ of CSS-in-JS.
- Linaria: zero-runtime CSS in JS.
- styletron: has some smart optimizations around CSS generation.
- JSS: one of the original packages â uses a dynamic stylesheet to add rules. (youâll need react-jss as well.)
- Radium: one of the original packages in this space.
- Atomic CSS: bleh. unreadable.
- styled-components: is dead â ď¸.
- to help you decide: an article going over (some of) the various libraries.
anti-Tailwind
this is an opinionated guide, remember? everything in my soul tells me to keep Tailwind away with a 10-foot pole. it's vendor lock-in embodied in a library, it has its own bespoke version of CSS that you have to learn, it becomes a garbled, cluttered mess within your HTML/JSX, ugh, ugh, ugh!
yes, it's very conveniently "spoken" by LLMs but trying to maintain it is untenable. Tailwind just ends up being a bloody mess once the codebase has any amount of real complexity or the number of collaborators grows. we webdevs went through this experience with CoffeeScript before. yes, it was elegant, neat, enticing â and, in the end, we needed to rewrite it all to stay relevant.
relevant reading:
there are so. many. libraries. coming out that are built on Tailwind, and, yeah, they look a peach. but ugh, mark my words, in 10 years, this madness will (hopefully) be behind us, leaving us to cleanup the strangling kudzu-like vines of unmaintainable code for decades to come.
setup
related to the previous section on JS, iâll mention again here the technologies included by default related to CSS for you to use out of the box.
- PostCSS: enables lots of nice CSS capabilities, including the following:
- postcss-preset-env: lets you use new/experimental (stage 3+) CSS features today. this depends on your
browserslistfield inpackage.json. (historical note: postcss-preset-env was previously known as âcssnextâ) - autoprefixing: adds compatibility support for different browsers.
- CSS Modules: letâs you import CSS into your JS. name your css files
*.module.cssto take advantage.
- postcss-preset-env: lets you use new/experimental (stage 3+) CSS features today. this depends on your
- Sass: provides support for a superset of CSS. (note: disabled by default. needs to be turned on by installing the
node-sasspackage.)
CSS Reset
sanitize.css is a CSS Reset that helps normalize things across browsers, a lesser problem these days but still important. Chris Coyier's "reset": an opinionated take on a reset.
conventions
CSS Modules
when you can, itâs suggested to use CSS Modules which provide great scoping for your CSS to a particular JS module. first, name your CSS file [name].module.css and then you can use it in your JS module as such (take note of the composes keyword and what itâs doing):
// Button.module.css.className {color: green;background: red;}.otherClassName {composes: className;color: yellow;}
// Button.module.css.className {color: green;background: red;}.otherClassName {composes: className;color: yellow;}
// Button.jsimport React, { Component } from 'react';import styles from './Button.module.css'; // Import css modules stylesheet as stylesimport './another-stylesheet.css'; // Import regular stylesheetclass Button extends Component {render() {// reference as a js objectreturn <button className={styles.otherClassName}>Button</button>;}}
// Button.jsimport React, { Component } from 'react';import styles from './Button.module.css'; // Import css modules stylesheet as stylesimport './another-stylesheet.css'; // Import regular stylesheetclass Button extends Component {render() {// reference as a js objectreturn <button className={styles.otherClassName}>Button</button>;}}
preprocessors
given the recommendation for CSS Modules/CSS-in-JS i might steer you away from CSS preprocessors (which would add yet another layer top of an already complex stack of technologies). but, if thatâs your thing, then take a look at Sass.
the advantages Sass can give you are things like:
- variables
- nesting of rules
- mixins
- operators
- and more!
(historical note: other packages in the space are things like Less but the community isnât as strong there and the support from other vendors isnât as robust.)
looking ahead
thereâs a bunch of CSS features constantly in the making. i had this section listing things from 2018 that were exciting and the neat thing is that the CSS development flywheel has only continued to produce great stuff!
- CSS-Tricks: always has the latest cool stuff in CSS, great place to learn in general.
- cssdb: a list of things being developed/discussed.
- New features for 2025
- custom variables: this is already pretty much out in the wild. letâs you specify variables much like you would in Sass or LESS.
- grid: simplifies existing layout patterns. here are some sites showing off its capabilities:
- all: initial: lets you reset the properties of an element.
- contain: not widely supported yet but can ostensibly give you some performance gains during rendering.
- will-change: gives a performance hint to the browser on how a particular element will change over time.
- scroll-snap-align: a way to give some control over scroll behavior to align with certain anchor points.
resources
- CSS-Tricks: always has the latest cool stuff in CSS, great place to learn in general.
- Can I use�: to check cross-browser support for a particular feature.
- âHell is other browsers â Sartreâ (from QuirksMode, the original support reference)
- Can I email�: email is its own hell.
- Mozilla Developer Network: the best reference for web technologies.
- Stack Overflow: the go-to place for when youâve RTFM and still donât WTF is broken.
- Google Developers: keep up-to-date on the latest upcoming changes in CSS.
- State of CSS: yearly survey of whatâs being used in the wild for CSS.
- CSS Zen Garden: shows you how a single HTML page can look a 1,000 different ways. this site goes way back and was inspiration to many a designer/developer.
- Learn CSS: from web.dev, an evergreen beginnerâs course.
- and, even more resources: +đ¤ resources and meetups