'Cannot Apply Unknown Utility Class': Fixing Tailwind v4 @apply Errors

October 4, 2026  |  9 min read  |  Tailwind CSS

By Syed · Frontend Engineer & Creator of UITweak

You migrated to Tailwind v4, ran the build, and got this:

Cannot apply unknown utility class 'border-border'.
Are you using CSS modules or similar and missing @reference?

It worked in v3. Nothing about your classes changed. The frustrating part is that "unknown utility class" has five different causes in v4, and the error message only hints at one of them. Work through the fixes below in order; the 30-second diagnosis tells you where to start.

30-second diagnosis: look at where your @apply lives. In a CSS module, Vue scoped <style>, or Svelte component? Go to Fix 1. Applying one of your own classes instead of a Tailwind utility? Fix 2. Your custom utility ignores hover: or dark:? Fix 3. The class name comes from v3 (bg-gradient-to-*, shadow-sm habits)? Fix 4. None of those? Fix 5.

What Changed in v4

In v3, @apply resolved utilities more or less globally. Tailwind v4 is CSS-first: utilities live in the stylesheet that contains @import "tailwindcss", and an isolated stylesheet (a CSS module, a scoped style block) cannot see them. That isolation is the point of modules, but it breaks @apply unless you explicitly bridge the gap. Hence the error message asking about @reference.

Fix 1: Add @reference in CSS Modules and Scoped Styles

This is the cause the error message points at, and the most common one. Any isolated stylesheet that uses @apply needs a @reference line at the top pointing at the file that imports Tailwind:

/* components/Card.module.css (Next.js) */
@reference "../app/globals.css";

.card {
  @apply rounded-xl bg-white shadow-lg p-6;
}
<!-- Vue single-file component -->
<style scoped>
@reference "../assets/main.css";

.title {
  @apply text-2xl font-bold;
}
</style>

@reference imports Tailwind's theme, utilities, and keyframes for reference only: no CSS is emitted, so your bundle does not get duplicates. It just lets @apply see what it needs. Two rules: it must be the first statement in the file, and the path must actually resolve to your Tailwind entry file. A wrong relative path fails silently and you are back to the same error, so double-check it.

Fix 2: You Can Only @apply Utilities, Not Your Own Classes

@apply works with utility classes, not with arbitrary classes you defined yourself. This fails:

/* a plain class is invisible to @apply */
.btn-primary {
  background: #4f46e5;
  color: white;
}

.alert {
  @apply btn-primary rounded; /* ERROR: btn-primary is not a utility */
}

The fix is to define your reusable class with @utility instead, which registers it as a real utility:

@utility btn-primary {
  background: #4f46e5;
  color: white;
}

.alert {
  @apply btn-primary rounded; /* works */
}

/* bonus: it now works with variants too */
<button class="hover:btn-primary">Save</button>

Fix 3: @utility vs @layer utilities (Variant Support)

This one is sneaky because there is no error at all. You define a custom "utility" inside a plain @layer utilities block, it works bare, but hover:, dark:, and responsive variants silently ignore it:

/* looks like a utility, but variants skip it */
@layer utilities {
  .text-balance-custom {
    text-wrap: balance;
  }
}
/* hover:text-balance-custom does nothing */

/* a real utility: variants work */
@utility text-balance-custom {
  text-wrap: balance;
}
/* hover:text-balance-custom works */

Rule of thumb: @layer utilities is just an organizational bucket for ordinary CSS. @utility is how you teach Tailwind a new utility, with variant support, proper sorting, and @apply compatibility included.

Confirm it worked: after converting to @utility, paste your stylesheet into our free Tailwind Config Visualizer and check the generated CSS contains both the utility and its hover: variant. If the variant selector is missing from the output, the definition is still in a plain layer.

Fix 4: The Utility Was Renamed or Removed in v4

Sometimes "unknown utility class" is telling the literal truth: the class does not exist anymore. v4 renamed a few utilities, most famously the gradient direction:

/* v3 name: gone in v4 */
.card {
  @apply bg-gradient-to-r from-blue-500 to-purple-500;
}

/* v4 name */
.card {
  @apply bg-linear-to-r from-blue-500 to-purple-500;
}

Check the exact class name in the error against the v4 docs. Our Tailwind v4 common errors guide lists the renames that bite migrators most often.

Fix 5: The File Is Never Processed by Tailwind

@apply is Tailwind syntax, not CSS. If the file containing it never passes through Tailwind, nothing can resolve it. Typical cases: @apply inside a plain <style> tag in HTML, a stylesheet loaded directly without the Vite plugin or PostCSS, or a CSS file imported outside the pipeline. The symptom is either the same build error or a literal @apply sitting in your shipped CSS doing nothing. The fix is structural: make sure every file using Tailwind directives flows through @tailwindcss/vite or @tailwindcss/postcss.

Quick Recap

  1. Isolated stylesheets (modules, scoped styles) need @reference at the top.
  2. @apply only accepts utilities; register custom classes with @utility.
  3. Use @utility, not @layer utilities, when you need variant support.
  4. Verify the class name still exists in v4 (renames like bg-linear-to-*).
  5. Make sure the file is actually processed by Tailwind's Vite/PostCSS plugin.

# Expansion draft: tailwind-v4-apply-errors-fix-guide

Debugging Walkthrough: Reading the Error Message Like a Map

The main guide lists five fixes. In practice the error message itself tells you which one you need, if you read it carefully. Here is the walkthrough I use.

The message names the exact class it choked on: Cannot apply unknown utility class 'border-border'. Start there. Ask: is this a Tailwind utility at all? In this real-world example, border-border comes from shadcn-style setups where --color-border is a theme token, so border-border is a legitimate utility in v4. If the class is yours or from a component library convention, jump to Fix 2 and Fix 3: you are applying something that was never registered as a utility.

If the class is a stock Tailwind utility like rounded-xl, the problem is visibility, not existence. Next question: where does the @apply live? Open the file. If it is a .module.css file, a Vue <style scoped> block, or anything other than your main Tailwind entry file, you are in Fix 1 territory: add @reference. If it is already in the entry file and still fails, check for a v3 name (bg-gradient-to-r, shadow-sm) and go to Fix 4.

The last branch is the silent one. No error, but the style does nothing or a variant is ignored. That means @apply resolved, but the thing it resolved to is not a real utility: a plain class in @layer utilities, or a stylesheet Tailwind never processes. Fix 3 and Fix 5 cover those.

I keep this order because it follows the evidence: class name first, then file location, then silence versus error. It resolves most cases in under five minutes without touching config.

@reference or Consolidate: An Architectural Call

Fix 1 says every isolated stylesheet using @apply needs its own @reference line. That is correct, and it scales badly. I have seen projects with forty CSS modules, each starting with an identical @reference "../app/globals.css" line, each with a relative path waiting to break during a refactor.

There is a real architectural choice here, and it is worth making deliberately:

**Option A: @reference everywhere.** Keep @apply in the modules. The cost is one line per file and a path that must stay correct. The benefit is that component styles stay next to their components. This fits teams that already organize by component and treat CSS modules as the unit of ownership.

**Option B: consolidate.** Move all @apply-based styles into the global stylesheet (or one components.css that the entry imports). Modules keep only plain CSS or nothing at all. The cost is that styles live far from their components. The benefit is a single file where every @apply can see every utility, zero @reference lines, and one obvious place to audit.

In practice I prefer Option B for most projects. @apply exists to compose utilities into reusable classes, and reusable classes are global by nature. Keeping them in modules buys little and costs a @reference line plus a fragile relative path in every file. The exception is a genuine design-system package consumed by multiple apps, where the component and its styles must travel together. There, @reference is the right tool and the paths are stable because the package structure is.

Either way, pick one and enforce it. A codebase with @reference in half its modules and consolidated styles in the other half is where the next person wastes an afternoon.

Prevention Checklist: @apply Hygiene for Teams

Three rules that prevent the whole category:

1. **Lint for @apply outside approved files.** If your team chose consolidation, a simple CI grep fails the build when @apply appears in a .module.css file. The error message should point at the global stylesheet. Cheap to add, and it stops the slow drift back to forty @reference lines.

2. **Never @apply a class you defined in the same file as plain CSS.** This is Fix 2 recurring. If you need the class in @apply, define it with @utility from the start. Make it a review rule: every new custom class gets the question "utility or plain CSS?" before it merges.

3. **Pin the v4 renames in your migration notes.** @apply bg-gradient-to-r fails after migration with the same "unknown utility" error, and it looks identical to the @reference problem. Keep a short list of the renames your codebase actually used (bg-linear-to-*, shadow-xs, outline-hidden) where the team can find it, so the next person does not re-diagnose a solved problem.

Frequently Asked Questions

What does @reference actually do?

It imports another stylesheet's Tailwind context (theme, utilities, keyframes) purely for reference. Nothing is emitted into your CSS, so there is no duplication; it only makes names visible to @apply inside an otherwise isolated file.

Why did @apply work in v3 without all this?

v3 resolved @apply through the JavaScript config pipeline, which saw utilities globally. v4 moved everything into CSS, where stylesheets are isolated from each other by design. @reference is the explicit bridge v4 requires.

Do I need @reference in every CSS module?

In every isolated file that uses @apply, yes. Files that only use plain CSS need nothing. If only one or two modules use @apply, consider moving those styles into the global stylesheet instead.

Can @apply use variants, like hover:font-bold?

Yes, @apply hover:font-bold works in v4. What does not work is applying a variant of something that is not a utility (see Fix 2 and Fix 3).

Is @utility the same as @layer utilities?

No, and the difference is the whole point of Fix 3. @layer utilities is an ordinary cascade layer holding plain CSS. @utility registers a first-class utility: variants, @apply support, and correct sorting come with it.

Verify the fix: paste your updated stylesheet into the free Tailwind Config Visualizer and confirm your @utility definitions and their variants appear in the generated CSS. If they do, the next build will succeed.

Share this guide