# Long Tailwind class lists were never the problem

- Published: 2026-12-05
- Tags: Tailwind Without Repeating Yourself
- URL: https://devtrillo.com/writing/tailwind-dry-2-the-utility-first-mental-model/

> Part 2 of a series on writing Tailwind v4 without copy-pasting class lists. [Part 1](/writing/tailwind-dry-1-stop-repeating-yourself/) drew the map. This part is the idea underneath it.

Part 1 ended with a `Button` component that still has `rounded-full px-5 py-2 font-semibold shadow-md` inside it. Long. I promised that was never the problem.

So I tested the opposite worry. I generated 100 cards with random class lists and built them with Tailwind 4.3.3. Then I generated 1,000.[^lab]

```text title="minified output"
100 components     9,459 bytes
1,000 components   9,459 bytes
```

Ten times the markup, the same stylesheet to the byte. To see why, you have to stop reading a class list as styling and start reading it as something else.

## The class list that looks wrong

Here's the reaction most of us have the first time, and I had it too. `class="p-6 rounded-lg bg-white shadow-sm"` looks like inline styles in a trench coat. It breaks separation of concerns. The HTML spec even says so, kind of: authors "are encouraged to use values that describe the nature of the content, rather than values that describe the desired presentation of the content."[^spec]

Encouraged. The same sentence says there are "no additional restrictions on the tokens authors can use." It's advice, and the advice had a cost nobody put in the spec.

Adam Wathan wrote that cost down in 2017, in the essay that became Tailwind's founding text.[^wathan] He started with a content-named class, `.author-bio`, and kept refactoring. Name your classes after content and "your HTML is restyleable, but your CSS is not reusable." Name them after patterns, like `.media-card`, and "your CSS is reusable, but your HTML is not restyleable." The coupling never goes away. It only picks a direction. "Neither is inherently 'wrong'," he wrote, and he still had to invent a name for every box on the page: "Trying to come up with these component names all of the time is exhausting."

## A utility is a decision, not a declaration

Here's what `p-6` compiles to in 4.3.3:

```css title="out.css"
.p-6 {
  padding: calc(var(--spacing) * 6);
}
```

It doesn't say 24 pixels. It says step 6 of the spacing scale, and the theme decides what a step is. `text-slate-700` compiles to `color: var(--color-slate-700)`. Every utility points back at the theme.

That's the first answer to "isn't this inline styles?" The docs admit that "in some ways it is," then name the difference: "using inline styles, every value is a magic number. With utilities, you're choosing styles from a predefined design system."[^inline] A class list is a list of choices from a fixed menu. It's the same idea as treating [design values as decisions](/writing/frontend-design-1-the-skill-developers-skip/), with the menu written into the class names.

The second answer is what the `style` attribute can't hold. It takes declarations and nothing else.[^mdn] No selector, so no `:hover`. No at-rule, so no breakpoint. A utility can carry a condition, and each one carries exactly one:

```css title="out.css, inside @layer utilities"
@media (hover: hover) {
  .hover\:bg-sky-700:hover {
    background-color: var(--color-sky-700);
  }
}
@media (width >= 40rem) {
  .sm\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (prefers-color-scheme: dark) {
  .dark\:bg-gray-800 {
    background-color: var(--color-gray-800);
  }
}
```

The docs say `hover:bg-sky-700` "does nothing unless the element is hovered," and that a single class "will never include both the light and dark styles."[^thinking] A traditional `.btn` holds every state in one name. A utility holds one decision under one condition. (The `@media (hover: hover)` wrapper is new in v4. Part 3 covers it.)

## Why the stylesheet stops growing

The docs list the benefits, and three of them do the real work.[^docs]

**Locality.** "Adding or removing a utility class to an element only ever affects that element." No other page uses that list, so no other page breaks when you change it.

**Constraint.** Everyone picks from the same menu, so the menu stays small. Wathan's essay quotes 2017 stats for GitLab's stylesheet: "402 text colors, 239 background colors, 59 font sizes." Those are the essay's numbers, not GitLab's today. They show what happens when "every new chunk of CSS you write is a blank canvas."[^wathan]

**Bounded CSS.** Tailwind generates only the classes it finds in your source. Once every class on the menu is in use somewhere, a new component adds nothing to the stylesheet. That's the 9,459 bytes from the top.

To see the shape, here's the same generator with a second version. Each component gets its own named class, `.card-0` to `.card-999`, with the same utilities applied inside it. It stands in for "write new CSS for every component." It's synthetic: hand-written CSS would share some rules, and it would also drift in value, which is the essay's 402 colours.

**Stylesheet size as the number of components grows**

| Components | utilities in the markup | one class per component |
| --- | --- | --- |
| 1 | 6,791 B (2,067 gzipped) | 6,686 B (2,020 gzipped) |
| 10 | 9,108 B (2,509 gzipped) | 13,212 B (2,562 gzipped) |
| 100 | 9,459 B (2,567 gzipped) | 73,174 B (4,315 gzipped) |
| 1,000 | 9,459 B (2,567 gzipped) | 674,355 B (19,110 gzipped) |

Minified CSS from Tailwind 4.3.3. Bars share one 0–80 KB scale.

At 10 components the two are within 53 bytes gzipped. At 1,000, the per-component CSS is 674 KB minified, and gzip squeezes it to 19 KB, against 2.6 KB for utilities. Part 1's rule still holds: bundle size is a weak argument, and gzip takes most of it away. Part 23 measures a real app.

The argument is the shape. One line goes flat once the vocabulary is in use. The other climbs with every feature you ship. The docs put it as "your CSS doesn't continue to grow linearly with every new feature."[^docs] Your stylesheet ends up sized by your design system, not by your feature list.

## Tailwind reads your source as plain text

There's one practical rule that falls out of this model, and it bites everyone once.

If the menu is a vocabulary, Tailwind is the reader. It "treats all of your source files as plain text," and "has no way of understanding string concatenation or interpolation."[^detect] I put this in a Svelte file:

```svelte title="Badge.svelte"
<script>
  let { color } = $props();
</script>

<button class="bg-{color}-600">dynamic</button>
```

The build passed. The CSS had no `bg-*-600` rule from it at all. The string `bg-red-600` never appears in the source, so as far as Tailwind knows, nobody asked for it.

The fix is the one part 1's `looks` object already used: write every class name out in full, and pick between them.

**Quiz:** A Svelte Badge takes tone ("red" | "green") and renders class="bg-{tone}-600 text-white". The build succeeds. What does a red badge look like?

- A red background, because Svelte fills in {tone} before Tailwind runs
- White text with no background colour
- Nothing, the build fails on an unknown class

**Answer:** White text with no background colour — Tailwind scans the source as plain text, and bg-red-600 is never written out, so no rule exists for it. Map the prop to complete names instead: { red: "bg-red-600", green: "bg-green-600" }.

## What utilities replace, and what they don't

Here's a made-up profile card, written the BEM way: a name for each part, a rule for each name, and values picked by eye.

**Refactor a BEM-named card into utilities**

Before:

```html
<div class="profile-card">
  <h3 class="profile-card__name">Ada</h3>
</div>

<style>
  .profile-card {
    padding: 22px;
    border-radius: 7px;
    background: #fff;
  }
  .profile-card__name {
    font-size: 14px;
    font-weight: 600;
    color: #334155;
  }
</style>
```

After:

```html
<div class="rounded-lg bg-white p-6">
  <h3 class="text-sm font-semibold text-slate-700">Ada</h3>
</div>
```

The `<style>` block is gone, and with it two names nobody needed. The 22 pixels and the 7 pixels snapped to 24px and 8px, steps on the scale. Nobody has to ask "is `.profile-card__name` still used anywhere?" before deleting it, because there's nothing to delete.

That's the list of what utilities replace: the naming layer, the hop between HTML and CSS files, and the fear of dead CSS. They also replace making a component of everything up front. Wathan's rule was to "build everything I can out of utilities, and only extract repeating patterns as they emerge." His example was the navbar: it's written once in the layout, so it never needs a name.[^wathan]

In 2017 he extracted those patterns into CSS classes. The v4 docs and [part 1](/writing/tailwind-dry-1-stop-repeating-yourself/) now say to reach for a component first. The idea stayed. The tool for extracting changed.

What utilities don't replace is the rest of part 1's map. Repeated markup still wants a component. A repeated value still wants a token. And a value that only exists at runtime, like a colour from your database, still goes in `style`, as a CSS variable a utility can read.[^dynamic]

**Quiz:** Each customer picks a brand colour and a darker hover shade in your admin panel, saved in the database. Your buttons need both. What's the Tailwind way?

- Build bg-[${color}] from the value in a template string
- style="background-color: …" on the button, and skip the hover
- style="--brand: …; --brand-hover: …" with bg-(--brand) hover:bg-(--brand-hover)
- A @theme token per customer

**Answer:** style="--brand: …; --brand-hover: …" with bg-(--brand) hover:bg-(--brand-hover) — The value comes from data, so it goes in an inline CSS variable. The hover is a condition, so it stays a utility. A built class name is never detected, inline style can't do :hover, and @theme tokens are fixed at build time.

## What it costs

- **Long lists are hard to scan.** Twelve classes on one element take a moment to read. Part 20 is about keeping them readable.
- **The HTML isn't restyleable from CSS alone.** That's Wathan's trade, picked on purpose. A CSS Zen Garden redesign, where only the stylesheet changes, doesn't work here.
- **You have to learn the vocabulary.** `p-6` means nothing until you know the scale. It's a small menu, but it's a menu.
- **Arbitrary values bring magic numbers back.** `bg-[#316ff6]` is an escape hatch, and part 17 covers when to use it.

## The repetition is the point

The long class list is a list of decisions you already made. Seeing `font-semibold` in two hundred places isn't duplication. It's two hundred places that agree.

What part 1 fixes is different: the same _combination_ of classes, copied across files. That's a decision with no home yet. The repeated words were never the problem.

If you want to read ahead, the "Styling with utility classes" page in the Tailwind docs is the official version of this argument, and Wathan's 2017 essay is the long one.[^docs][^wathan]

[^lab]: `tailwindcss` and `@tailwindcss/cli` 4.3.3 on macOS, built with `npx @tailwindcss/cli -i in.css -o out.css --minify` and measured with `gzip -9`. Each component draws one class from each of 10 groups (padding, background, text colour, text size, radius, shadow, weight, display, gap, hover colour), 39 classes in total, from a seeded random generator. About 6.7 KB of every build is Preflight and the theme variables.

[^spec]: WHATWG, [HTML Living Standard: Classes](https://html.spec.whatwg.org/multipage/dom.html#classes).

[^wathan]: Adam Wathan, ["CSS Utility Classes and 'Separation of Concerns'"](https://adamwathan.me/css-utility-classes-and-separation-of-concerns/), August 7, 2017. It predates Tailwind v1, so read the extraction advice as history.

[^inline]: Tailwind CSS, [Styling with utility classes: Why not just use inline styles?](https://tailwindcss.com/docs/styling-with-utility-classes#why-not-just-use-inline-styles)

[^mdn]: MDN, [The style global attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/style).

[^thinking]: Tailwind CSS, [Styling with utility classes: Thinking in utility classes](https://tailwindcss.com/docs/styling-with-utility-classes#thinking-in-utility-classes). The docs' sample output is "slightly simplified"; the blocks above are the real 4.3.3 output.

[^docs]: Tailwind CSS, [Styling with utility classes](https://tailwindcss.com/docs/styling-with-utility-classes). The old `/docs/utility-first` URL redirects here.

[^detect]: Tailwind CSS, [Detecting classes in source files](https://tailwindcss.com/docs/detecting-classes-in-source-files).

[^dynamic]: Tailwind CSS, [Styling with utility classes: When to use inline styles](https://tailwindcss.com/docs/styling-with-utility-classes#when-to-use-inline-styles).

Next in the series:

- **Part 3 — What actually changed in Tailwind v4**: your config moved into CSS, and the upgrade tool fixes the syntax but not the defaults that changed underneath.
