Configuring v4 in CSS
8. How do you customize the theme in v4 without tailwind.config.js?
With theme variables in an @theme block in your main CSS file. Each variable both defines a design token and creates the utilities for it: --color-brand-500 gives you bg-brand-500, text-brand-500 and every other color utility.
@import "tailwindcss";
@theme {
--color-brand-500: oklch(0.64 0.19 45);
--font-display: "Satoshi", sans-serif;
--breakpoint-3xl: 120rem;
}
That file makes bg-brand-500, font-display and a 3xl: breakpoint at 120rem available; we compiled it and all three appeared in the output. The theme docs list the namespaces (--color-*, --font-*, --breakpoint-*, --spacing and more).
Every token is also a real CSS variable on :root, so JavaScript and inline styles can read it.
9. What is the difference between @theme and @theme inline?
Both create utilities. With @theme, the utility points at the theme variable; with @theme inline, the utility gets the variable's value written in. It matters when a token refers to another variable.
@theme {
--font-body: var(--font-inter);
}
@theme inline {
--font-heading: var(--font-inter);
}
Compiled, font-body becomes font-family: var(--font-body), while font-heading becomes font-family: var(--font-inter).
Without inline, var(--font-inter) is resolved where --font-body is defined, on :root, so a new value of --font-inter set on a lower element never reaches the utility. inline fixes that.
10. How do you add a custom utility in v4?
With @utility. v4 uses native cascade layers and no longer turns classes in @layer utilities into utilities that work with variants, so @utility replaces that pattern.
@utility content-auto {
content-visibility: auto;
}
@utility stack-* {
display: flex;
flex-direction: column;
gap: calc(var(--spacing) * --value(integer, --default(4)));
}
The second one is a functional utility: --value(integer) reads the number from the class name, so stack-2 compiles to gap: calc(var(--spacing) * 2). The --default(4) argument, added in v4.3, makes a bare stack work too; we compiled both.
Custom utilities work with every variant, so md:stack-6 needs nothing extra.
11. How do you add your own variant?
With @custom-variant, giving it a selector or at-rule. This one styles elements inside a data-theme="midnight" container:
@custom-variant midnight (&:where([data-theme="midnight"], [data-theme="midnight"] *));
After that, midnight:text-white works like any built-in variant. Using :where() keeps the added selector at zero specificity, so the variant does not beat an unrelated utility by accident.
12. How do you switch dark mode with a class instead of the OS setting?
Override the dark variant in CSS. By default, dark: follows prefers-color-scheme; the v3 darkMode: 'class' config key does nothing in a v4 CSS setup.
@custom-variant dark (&:where(.dark, .dark *));
dark:bg-gray-900 then compiles to .dark\:bg-gray-900:where(.dark, .dark *), which applies whenever an ancestor has the dark class.
The dark mode docs show the data-attribute version and the few lines of JavaScript that set the class before first paint, which is what prevents a flash of the light theme.
13. Why does @apply fail inside a Vue or Svelte style block, and how do you fix it?
In v4, stylesheets that are bundled separately from your main CSS, such as Vue, Svelte and Astro style blocks and CSS modules, do not see your theme, custom utilities or custom variants. @reference imports them for lookup only, without copying any CSS into the output.
@reference "./app.css";
h1 {
@apply font-display text-2xl text-brand-500;
}
We compiled that block on its own: the output is the single h1 rule, with no Preflight or utilities duplicated.
The upgrade guide also suggests the simpler route of reading theme variables directly, as in color: var(--color-brand-500), which skips @apply altogether.
14. How do you include classes the scanner cannot see, or exclude a folder?
Use @source to add a path, @source not to exclude one, and @source inline() to force classes into the build, which replaces v3's safelist. Brace expansion keeps the list short.
@source "../node_modules/@acme/ui/dist";
@source not "./legacy";
@source inline("{hover:,}bg-red-{50,{100..300..100}}");
The inline rule generated bg-red-50, bg-red-100 to bg-red-300 and their hover: versions. The excluded legacy folder's classes did not appear.
The first line is the common case: a UI library in node_modules, which v4 ignores by default. @source not and @source inline() arrived in v4.1.
15. Can you still use a JavaScript config or a v3 plugin?
Yes, explicitly. JavaScript config files are no longer detected automatically; load one with @config "./tailwind.config.js"; and a plugin with @plugin "@tailwindcss/typography";.
The corePlugins, safelist and separator options are not supported, and resolveConfig was removed. A candidate who proposes keeping the JS config forever has missed that the CSS variables v4 generates are what replaced it.