Paj Digital Labs
All articles
Web Design & Engineering

The Cascade Is Not Your Enemy: Writing CSS You Can Delete

CSS fear comes from not knowing what a rule affects. Specificity budgets, cascade layers, and the naming convention that lets you remove code without a prayer.

Paj Digital Labs 2 min read
Web design workspace with desktop and laptop displays
Editorial illustration · Web Design & Engineering

Nobody is afraid of deleting JavaScript the way they are afraid of deleting CSS. Remove a function and the type checker tells you what breaks. Remove a CSS rule and you find out three weeks later, on a page you forgot existed, in a browser you do not use.

The fear is rational given how most CSS is written: global selectors, specificity wars, and !important as a conflict resolution strategy. But the fear is optional. CSS can be written so that every rule has a known blast radius.

The specificity budget

Specificity is a scoring system, and most stylesheets treat it like a suggestion. IDs beat classes beat elements, inline beats everything, and !important beats the concept of maintenance.

The fix is a budget: classes only, one level deep, no exceptions.

css
/* Allowed */
.card { }
.card-title { }

/* Banned */
class="text-code-comment">#sidebar .card h2.title { }

When every selector has identical specificity, the cascade becomes predictable: later rules win, and you can reason about order. The moment someone writes #main .card, the budget is blown and every future change requires a more specific selector to override it. That is the specificity war, and it only starts when someone fires first.

Cascade layers: order you declare, not order you debug

css
@layer reset, base, components, utilities;

@layer components {
    .button { padding: 0.5rem 1rem; }
}

@layer utilities {
    .p-0 { padding: 0; }
}

Layers make precedence explicit. A utility in the utilities layer beats a component rule even if the component selector is more specific. This inverts the old mental model, and it is the single biggest improvement to CSS maintainability in a decade. The layer order at the top of the file is the whole story — no more hunting through 4,000 lines to find what wins.

Name things by what they are, not where they live

css
/* Fragile — breaks when the element moves */
.sidebar-title { }

/* Durable — true wherever it renders */
.section-heading { }

Location-based names are lies waiting to happen. The .sidebar-title will be in the footer by Q3. Name the pattern, not the position, and the rule survives the redesign.

The deletion test

Here is the practice that changes everything: every component's styles live in one place, under one prefix, and nothing else references them.

css
/* pricing-table.css — everything for this component */
.pricing-table { }
.pricing-table-row { }
.pricing-table-price { }

When the pricing page is removed, you delete one file and one import. No grepping for orphaned selectors, no "is this still used?" archaeology. CSS you can delete is CSS you are not afraid of, and fearlessness is what keeps a stylesheet small.

What this costs

A naming convention, a layer declaration, and the discipline to say no to !important in review. That is the entire price. In exchange you get a stylesheet that shrinks when features are removed — which is to say, a stylesheet that tells the truth about the site it styles.

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