CSS Architecture That Survives a Redesign: Tokens, Layers and Deletion
Most stylesheets rot because nobody can prove a rule is unused. Design tokens, cascade layers and a deletion discipline that keeps CSS from becoming append-only.

Every large stylesheet we inherit has the same shape: a reasonable base, then eighteen months of additions, then a overrides.css loaded last, then !important scattered through the final third. Nobody deletes anything, because nobody can prove what a rule does. The file becomes append-only, and append-only CSS always ends the same way — a rewrite.
The fix is not a methodology war. It is making two things cheap: knowing where a value comes from, and knowing whether a rule is still used.
Tokens are the contract
A hex code in a component is a decision with no name. When the brand shifts, you are grepping for #1e3a5f and hoping the designer used the same one everywhere. Tokens give values names, and names can be re-pointed.
Two tiers, and only two. Primitives hold raw values; semantic tokens hold intent. Components only ever consume the semantic tier.
:root {
/* Tier 1 — primitives. Never referenced by a component. */
--navy-900: oklch(0.235 0.062 265);
--navy-500: oklch(0.53 0.088 250);
--paper-50: oklch(0.98 0.004 250);
/* Tier 2 — semantic. This is the public API. */
--color-surface: var(--paper-50);
--color-ink: var(--navy-900);
--color-accent: var(--navy-500);
--border-hairline: 1px solid oklch(0.235 0.062 265 / 14%);
}
[data-theme=class="text-code-string">"dark"] {
--color-surface: var(--navy-900);
--color-ink: var(--paper-50);
}Dark mode stops being a feature and becomes a re-point of tier two. If a component reads --navy-900 directly, it will not theme, and that is the rule worth enforcing in review.
Cascade layers end the specificity war
!important is a symptom of an ordering problem. Layers solve ordering explicitly: later layers win regardless of selector specificity, so a single-class utility can beat a three-selector component rule without escalation.
@layer reset, base, components, utilities;
@layer components {
.card__title:is(h1, h2, h3) {
font-size: 1.5rem; /* specificity 0,2,1 */
}
}
@layer utilities {
.text-sm { font-size: 0.875rem; } /* specificity 0,1,0 — still wins */
}Declare the layer order once, at the top, before any of them have content. Third-party CSS goes in its own low-priority layer on import, which is the cleanest way to tame a vendor stylesheet you cannot edit:
@import url(class="text-code-string">"vendor-widget.css") layer(vendor);
@layer vendor, reset, base, components, utilities;Scope styles to the component, not to a naming convention
BEM was a workaround for the lack of scoping. Modern CSS has actual scoping, and it handles the "style the children but stop at the next component" problem that BEM never solved.
@scope (.article-body) to (.embed, .code-block) {
p { max-width: 68ch; line-height: 1.7; }
a { text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
}Everything inside .article-body gets prose styling, and the cascade stops at any embed or code block. Previously that took a defensive :not() chain that broke every time a new embed type appeared.
Container queries kill the breakpoint pile
A card does not care how wide the viewport is. It cares how wide its slot is. Viewport breakpoints force you to encode layout context into media queries — which is why the same card needs different rules in the sidebar and in the grid.
.card-slot { container-type: inline-size; }
@container (min-width: 26rem) {
.card { display: grid; grid-template-columns: 8rem 1fr; gap: 1.25rem; }
}The component is now genuinely portable. Drop it in a narrow rail or a wide grid and it adapts without the parent knowing anything about it.
Make deletion possible
This is the discipline that actually prevents rot. Rules survive because removing them feels risky. Reduce the risk:
- One source of truth per component. If
.cardis styled in three files, nobody will ever delete any of them. - No global element selectors outside
base. A bareh2 { }in a component file has unbounded blast radius. - Date-stamp deprecations.
/ deprecated 2026-08 — remove after checkout redesign ships /gives the next person permission to act. - Measure before a redesign. Coverage tooling tells you what actually loaded on real routes.
class="text-code-comment"># Rough unused-selector pass across the built output
npx purgecss --css dist/assets/*.css --content class="text-code-string">'dist/**/*.html' class="text-code-string">'src/**/*.tsx' \
--output /tmp/purged/
class="text-code-comment">
# Then diff sizes — a large delta means a large deletion opportunity
du -b dist/assets/*.css /tmp/purged/*.cssTreat that output as a hint, not a verdict — anything built from a dynamic class name will look unused. Confirm with a grep for the string fragments before you cut.
What we do not do
| Pattern | Why we avoid it | | :--- | :--- | | Deep selector nesting (3+ levels) | Specificity that only !important can beat later | | z-index: 9999 | Define a token scale: --z-dropdown: 100, --z-modal: 400 | | Utility classes for one-off values | .mt-\[13px\] is a hex code with extra steps | | A global overrides.css | It is a confession that the layer order is wrong |
None of this is exotic. Tokens name your decisions, layers make ordering explicit, scope bounds the blast radius, and a deletion habit keeps the file from growing forever. A stylesheet you can confidently delete from is a stylesheet that does not need a rewrite.
Paj Digital Labs
The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.
Related reading

International Websites: Locale URLs, Hreflang and Formatting Without Guesswork
Language, country and formatting are related but different choices. Give translated pages stable URLs, preserve user selection and keep search signals aligned with real equivalents.

Progressive Enhancement for Article Sites: The Page Should Outlive Its Scripts
Core reading and navigation should remain available when hydration or a third-party script fails. Start with useful HTML and layer interactions without turning every link into an application dependency.

Website Search That Finds Answers: Ranking, Typos and Empty Results
Search quality depends on the documents and ranking rules, not the size of the input box. Index useful fields, handle imperfect queries and give readers a way forward when nothing matches.