Engineering

The CSS Bug That Silently Deleted a Design System

One attribute selector outranked every component class in the build. Nothing threw, nothing warned, and the page just looked wrong.

2 min readPublished June 9, 2026
Share on X

Every paragraph on this site lost its margins. List items lost their bullets. Buttons lost their borders. One of them rendered as white text on a white pill, so it was invisible.

Nothing threw. Nothing warned. The build passed, the page rendered, and it just looked subtly wrong in a way that took an afternoon to trace.

The cause is one character

The base resets were scoped with an attribute selector:

[data-page] p { margin: 0; }
[data-page] a { color: inherit; }
[data-page] button { border: 0; background: none; }

That is a specificity of (0,1,1) — one attribute, one type. A component class is (0,1,0) — one class, no type. And specificity does not care which rule is more specific in intent. It only counts.

So `.a-p { margin: 0 0 24px }` lost to `[data-page] p { margin: 0 }`, every single time, silently, forever.

The reset was applying to everything. The component was applying to nothing. Both were true at once.

The fix is zero specificity

`:where()` contributes nothing to specificity. Wrapping the scope in it means the reset still reaches every element inside the page, but it always loses to any class:

:where([data-page]) p { margin: 0; }
:where([data-page]) button { border: 0; background: none; }

The sibling trap

The same class of bug hides in media queries. A rule hid the "Get app" pill below 760px, and it did not work — because a `.btn { display: inline-flex }` rule was also (0,1,0) and appeared later in the file. Equal specificity is decided by source order, not by which rule looks more specific.

The fix was to scope the hiding rule through a parent, so it stopped being a tie: `.topbar__actions .topbar__cta { display: none }` beats `.btn` on specificity rather than on position.

The rule I now follow

Before setting `display: none` on a class, grep the stylesheet for a later rule of equal specificity that re-declares the same property. It is a thirty-second check and it has already saved an afternoon twice.

  • CSS
  • Design Systems
  • Debugging
KI

Kadirul IslamVerified author

Founder, A.K Solution

Follow on X

Founder of A.K Solution. Full-stack engineer building AI agent tools like KiCode, JSON form engines like ki-forms, and high-scale SEO systems. Obsessed with shipping fast, zero-bloat software that lasts.

More from Kadirul Islam

Cache Policy Is a Design Decision

Immutable, revalidate, or no-store. Choosing wrong is how you ship a 200 for a URL that should not exist.

2 min readCaching

Delete the Framework From Your Blog

A blog is the one project where the runtime is pure overhead. Here is the argument, and the build that settles it.

2 min readStatic Sites

The Router I Did Not Install

Two routes do not need a routing library. They need about forty lines and a hydration contract you can state in one sentence.

3 min readReact

Prerender Everything and Ship a Static Site

If two visitors receive identical bytes, a server runtime is a tax you agreed to pay for nothing.

2 min readWeb Development