AddThisFeature

CSS Layer Strategy

Give the stylesheet an explicit order of precedence instead of one decided by accident.

involved CSS & Styling

What it adds

An ordered set of cascade layers — reset, tokens, base, components, utilities, overrides — that every stylesheet is assigned to.

What your agent is told to do

5
  1. 1

    Define the layer order once, in one file, and have every other stylesheet declare which layer it belongs to rather than relying on the order the bundler happens to emit.

  2. 2

    Assign the existing stylesheets to layers before changing any of them. The map from current file to intended layer is the whole design decision, and it should be reviewable on its own.

  3. 3

    Migrate in stages: place everything currently unlayered into a defined position relative to the new layers, then move files into their proper layer one at a time, checking the rendered result after each move.

  4. 4

    Put third-party and vendor stylesheets into a layer of their own, low in the order, so the app's own rules win without anyone reaching for higher specificity or forced importance to get there.

  5. 5

    Do not use this to replace what CSS Module Boundaries owns. Layers decide which rule wins when two rules collide; module boundaries decide who is permitted to write a colliding rule in the first place. Keep the two answers separate.

Edge cases it handles

7
  • Unlayered styles beat every layered style, which means a partial migration can leave the old code stronger than the new. Decide deliberately where unlayered styles sit during the transition, and track the count of unlayered files down to zero.
  • Third-party CSS that is not authored by the team must be wrapped into its own layer at import time. Left outside the system it will either overpower the app's components or be fought with importance flags that undo the whole strategy.
  • The topmost override layer will become a dumping ground unless entry to it is restricted and reviewed. Define what legitimately belongs there — genuinely exceptional, documented, temporary fixes — and require a reason for each addition.
  • Every layer needs a written statement of what may be authored in it and what may not, kept next to the layer definition. Without that, the order survives and the discipline does not.
  • Importance flags cut across layers in a way that inverts their order, so any remaining use of forced importance must be inventoried and removed rather than layered around.
  • Styles injected at runtime, including anything a component adds to the document head after load, land outside the declared order unless they are explicitly assigned to a layer.
  • Layer names that appear in more than one bundle must be declared in the same order in each, or the effective precedence will differ between routes.

Definition of done

8
  • The full layer order is declared in exactly one place and imported everywhere.
  • Every stylesheet in the app is assigned to a named layer, with no unlayered files remaining.
  • Third-party CSS is contained in its own low-precedence layer.
  • The override layer has documented entry rules and a listed, justified set of occupants.
  • Forced importance flags are inventoried and no longer used to win the cascade.
  • The rendered appearance of the app is unchanged at the end of the migration.
  • The feature matches the existing design system.
  • No existing functionality is broken.

Related features

How it works

  1. 1

    Copy the link

    Grab the Markdown instruction URL for this feature.

  2. 2

    Give it to your AI

    Paste it into Claude Code, Cursor, v0, Lovable — whatever you build with.

  3. 3

    It inspects, then implements

    Your agent reads your existing app first, then adds the feature to fit it.

Works with your stack

These instructions are written to adapt. They tell the agent to detect your framework, match your existing design system, and reuse what you already have — rather than assuming a particular stack.

Need it tighter than that? Customize the feature and tell it exactly what you're running.