CSS Layer Strategy
Give the stylesheet an explicit order of precedence instead of one decided by accident.
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
What your agent is told to do
5-
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
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
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
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
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
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
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
Tokenized Inline Styles
Tokenized Inline Styles
Allow styles computed at runtime without letting arbitrary values escape the design system.
What it does
A constrained path for dynamically computed styles, where every value is either a design token or a number clamped to an approved range.
How it works
- 1 Find every place the app already sets a style value at runtime — progress widths, chart bar heights, avatar colours, drag positions, user-chosen accent colours — and sort them into two groups: values that must come from the token set, and values that are genuinely continuous numbers.
- 2 For the first group, accept only token names and resolve them to values at the boundary. A caller passing a raw colour or a raw pixel value should be rejected loudly in development rather than quietly rendered.
- 3 For the second group, clamp to a documented minimum and maximum and round to a sensible precision, so a percentage of 4000 or a width of 0.3847291 pixels never reaches the DOM.
Copy the prompt
No account needed
Add this feature to my app:
https://addthisfeature.com/x/tokenized-inline-styles
Variant Class Generator
Variant Class Generator
Declare a component's variants once instead of scattering conditionals through its markup.
What it does
A declarative variant definition per component mapping size, tone, and state to the classes each combination produces.
How it works
- 1 Find the components whose markup is threaded with conditional class logic and replace that logic with a single declaration listing each variant, its options, and its default.
- 2 Support combinations that are more than the sum of their parts, so a specific pairing of size and tone can produce classes that neither produces alone, without reintroducing a conditional in the markup.
- 3 Make invalid combinations impossible to express rather than merely undesirable, and give the component a defined appearance when it receives a combination it does not recognise.
Copy the prompt
No account needed
Add this feature to my app:
https://addthisfeature.com/x/variant-class-generator
Class Merge Helper
Class Merge Helper
Combine conditional classes in one place so the last one written actually wins.
What it does
A single helper every component uses to resolve base, conditional, and caller-supplied classes into one final list.
How it works
- 1 Find every component that currently builds a class string by hand and route all of them through one helper, so the resolution rules are identical everywhere.
- 2 Define the precedence plainly: the component's own base classes lose to its variant classes, and both lose to whatever the caller passed in. A caller that supplies a class expects it to take effect.
- 3 Accept the shapes calling code actually produces rather than forcing every call site to normalise first, and make the behaviour for absent and empty values explicit rather than incidental.
Copy the prompt
No account needed
Add this feature to my app:
https://addthisfeature.com/x/class-merge-helper
How it works
-
1
Copy the link
Grab the Markdown instruction URL for this feature.
-
2
Give it to your AI
Paste it into Claude Code, Cursor, v0, Lovable — whatever you build with.
-
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.