Tailwind v4 Ignores Your Custom CSS? The @layer Cascade Trap Fix

October 6, 2026  |  9 min read  |  Tailwind CSS

By Syed · Frontend Engineer & Creator of UITweak

The class is right there in the DOM. DevTools shows the CSS was generated. The utility is spelled correctly. And yet the style simply does not apply. You add px-8 and the padding stays zero. You add font-mono and the font does not change. It worked in v3, nothing about the markup changed, and there is no error anywhere. If you migrated to Tailwind v4 recently, you have probably met this ghost, and the culprit is almost always the same: cascade layers.

30-second diagnosis: in DevTools, find your utility's rule and look at the layer badge next to it (Chrome shows e.g. utilities). Now find the rule that is actually winning. If the winner has no layer badge, that is your answer: in v4, unlayered CSS beats all layered CSS, no matter the specificity or source order.

Why This Happens

Tailwind v4 moved everything into cascade layers, declared in this order:

@layer theme, base, components, utilities;

Layers later in the list beat layers earlier in the list, which is intuitive. What is not intuitive is the other rule: unlayered styles beat every layered style, period. It does not matter that your utility has higher specificity or comes later in the file. An unlayered * { padding: 0 } reset will defeat a layered px-8 every single time. An unlayered button { font-family: inherit } will kill font-mono on every button. In v3 there were no layers, so specificity and source order decided everything and your resets behaved. In v4, any CSS you wrote outside a layer quietly outranks the entire framework.

Fix 1: Put Your Custom CSS in a Layer

The main fix is mechanical: wrap your custom styles in the layer where they belong. Resets and element styles go in base, component classes in components:

/* broken: unlayered, beats every utility */
* {
  padding: 0;
}

/* fixed: lives in base, utilities win again */
@layer base {
  * {
    padding: 0;
  }
}

Once the reset is layered, the normal cascade works the way you expect: utilities comes after base, so px-8 applies. This single change resolves the majority of "v4 ignores my CSS" reports.

Fix 2: Define Custom Utilities with @utility

If you wrote custom utility-like classes as plain CSS, they are unlayered too, which means they beat Tailwind's own utilities and cause the reverse confusion: your .text-balance custom class overriding a text-center you actually wanted. Define them with @utility so they land in the utilities layer and compete fairly:

/* unlayered: beats Tailwind utilities unexpectedly */
.text-balance {
  text-wrap: balance;
}

/* layered: plays by the same rules as built-in utilities */
@utility text-balance {
  text-wrap: balance;
}

@utility also gives you variant support for free (hover:text-balance works), which plain classes never had.

Fix 3: Stop Fighting Preflight Twice

A frequent variant of this trap: teams keep their old v3-era reset file and v4's preflight, with the old reset unlayered. Now two resets fight, and the unlayered one wins over utilities in ways that look random. Pick one:

  • Keep preflight (it is already in base) and delete the old reset, or
  • Disable preflight with @import "tailwindcss" theme (inline) { --*: initial; }... in practice, simply remove the old reset file and let preflight do its job.

If you need reset behavior preflight does not provide, add it inside @layer base (Fix 1) rather than as a separate unlayered stylesheet.

Fix 4: Audit Third-Party CSS

Component libraries, embed widgets, and copied snippets often ship unlayered CSS. When a utility stops working only inside one component, check that component's stylesheet for unlayered rules. The quick containment is @layer wrapping at the import site:

/* demote an entire third-party stylesheet below utilities */
@layer components {
  @import "some-widget.css";
}

Importing into a named layer is supported in all modern browsers and instantly stops the library's unlayered rules from outranking your utilities.

Quick Recap

  1. v4 layers everything as theme, base, components, utilities; unlayered CSS beats all of it.
  2. Symptom: class in DOM, CSS generated, style not applied, worked in v3.
  3. Put resets in @layer base and custom utilities in @utility.
  4. Do not run an old unlayered reset alongside preflight.
  5. Wrap third-party stylesheets in @layer at import time.

# Expansion draft: tailwind-v4-layer-cascade-fix-guide

Debugging Walkthrough: Reading the Layer Badge in DevTools

The 30-second diagnosis in the main guide tells you to compare layer badges. Here is the full version of that check, because the badge tells you more than "layered versus unlayered" once you know how to read it.

Open DevTools, inspect the misbehaving element, and look at the Styles pane. In Chrome and Edge, every rule from a cascade layer shows its layer name next to the selector, something like utilities or base. Rules with no badge are unlayered. Find your utility's rule first and note its layer. Then scroll to the rule that is actually winning. There are exactly three outcomes:

1. **The winner has no badge.** Your utility is layered, the winner is not. Unlayered beats layered, full stop. Wrap the offending CSS in the right layer (Fix 1 of the main guide) or demote the third-party stylesheet (Fix 4).

2. **Both have badges, and the winner's layer is later in the order.** The layer order is theme, base, components, utilities, so a components-layer rule beating your utilities-layer rule should not happen by default. If it does, someone redeclared the layer order with @layer in a different sequence. Search the codebase for @layer declarations that list layers in a custom order and fix the sequence.

3. **Same layer, winner is later in source order or higher specificity.** This is the normal cascade behaving normally. Your instincts work here: reorder the rules, raise the specificity, or reconsider whether the custom rule should exist at all.

I run this check before changing any code because it distinguishes a layer problem from an ordinary specificity problem, and the fixes are completely different.

The Full Layer Order, Including the Theme Layer

The main guide shows @layer theme, base, components, utilities. Most discussions stop at "utilities last, so utilities win." The theme layer deserves its own explanation because it is where @theme tokens live, and misunderstanding it produces a subtle bug.

The theme layer holds variable declarations, not rules that style elements. Your --color-brand-500 token is declared in the theme layer on :root. Utilities in the utilities layer reference those variables. Because the theme layer comes first, it never competes with utilities directly. That is by design: tokens are inputs, utilities are outputs.

The bug this produces: someone tries to "override" a utility by redefining a variable in an unlayered :root block, expecting the later declaration to win. It does win, because unlayered beats layered, but it wins globally and unpredictably, and it looks like the theme is haunted. Redefine the variable under a more specific selector instead (like .dark, as the dark-mode guide shows). Variables follow the same layer rules as everything else.

When You Actually Want to Beat Utilities: Deliberate Overrides

Everything so far is about stopping accidental overrides. But sometimes you genuinely need custom CSS to win over utilities: a print stylesheet, a third-party embed you must visually contain, or a legacy component mid-migration. There are three honest ways, in order of preference:

**A later layer of your own.** Declare an additional layer after utilities and put the override there:

@layer theme, base, components, utilities, overrides;

@layer overrides {
  .legacy-card {
    padding: 2rem; /* beats p-4, deliberately */
  }
}

This is explicit, greppable, and scoped to the classes you choose. Anyone reading the code sees the intent.

**The important modifier.** Tailwind v4 supports the trailing ! (p-4!), which generates !important declarations. I use it for one-off exceptions, never as architecture. A codebase where every other class has a ! is a codebase where the cascade has been abandoned.

**Unlayered CSS, on purpose.** If you write unlayered styles knowing they beat all utilities, that is a valid choice for things like print stylesheets, where you want total control and utilities are irrelevant. The requirement is intent: a comment explaining why this file is unlayered, so the next person does not "fix" it by adding a layer and breaking print.

What I never do: sprinkling !important in unlayered CSS to win fights I started by accident. That is how specificity wars begin, and they end with nobody able to change anything.

Prevention Checklist

1. **Every stylesheet gets a layer decision at creation.** New CSS file? It goes in a layer, or it gets a comment explaining why it is unlayered. No file is unlayered by default or by accident.

2. **Grep for unlayered selectors in CI.** A simple check that flags element selectors (button {, * {, input {) outside @layer blocks catches the reset-file regression before it ships. The v3-era reset that someone re-adds "temporarily" is the classic offender.

3. **Document your layer order once.** If you add custom layers like overrides, write the full @layer declaration list in one canonical place, ideally the entry stylesheet, with a comment. Two files declaring different orders is a silent conflict.

4. **Audit third-party CSS on every major version bump.** Library updates rewrite stylesheets. A library that was layered in v2 might ship unlayered CSS in v3. The import-site wrapping from Fix 4 is cheap insurance; re-verify it when you upgrade dependencies.

Frequently Asked Questions

Can I just make my utilities !important instead?

You can, and v4 even has the important modifier, but it treats the symptom. The next unlayered rule will start the same fight, and you will end up sprinkling ! everywhere. Layering your CSS correctly fixes the whole category at once.

Does @layer affect specificity?

Layers are evaluated before specificity in the cascade. A layered rule with an ID selector still loses to any unlayered rule, even * {}. That is exactly why this bug is so disorienting: your instincts about specificity are correct, they just run after the layer check.

What about inline styles?

Inline styles are unlayered, so they beat layered utilities too, same as before. Nothing about v4 changes that; it only changes how your stylesheets compete with each other.

Try it now: while you untangle the cascade, define your design tokens in our free Tailwind Config Generator and export them straight into @theme. Tokens defined through @theme live in the theme layer where they belong, so your colors and spacing never end up as unlayered surprises. For the full @theme model, see our @theme complete guide.

Share this guide