Tailwind CSS Knowledge Patch
Use this patch when configuring, migrating, integrating, or extending a Tailwind CSS project. Check migration-sensitive behavior first, then open only the topic reference relevant to the task.
Reference Index
| Reference |
Topics |
| Configuration and Theming |
@theme, token namespaces, source detection, legacy configuration, build-time functions, custom utilities |
| Integrations and Ecosystem |
@reference, Vite, webpack, CLI watch polling, CSS nesting, Tailwind Plus, Prettier |
| Migration and Compatibility |
Removed configuration, renamed utilities, browser fallbacks, logical positioning, platform font behavior |
| Utilities |
Values, gradients, masks, shadows, wrapping, alignment, logical properties, scrollbars, containers, typography |
| Variants and States |
Data and ancestor states, negation, pointers, validation, details, popovers, authored CSS composition |
Migration Hazards First
Use the CSS-first entry point
@import "tailwindcss";
@theme {
--color-brand: oklch(0.68 0.14 250);
--breakpoint-3xl: 120rem;
}
- Put framework tokens in a top-level
@theme; a :root custom property alone does not create a utility or variant.
- Use
@config and @plugin only as bridges for legacy JavaScript configuration and plugins.
- Do not carry forward
corePlugins, safelist, or separator; they are unsupported. Replace safelisting with @source inline().
Update renamed and deprecated classes
| Old form |
Current form |
Note |
bg-gradient-to-r |
bg-linear-to-r |
Linear gradients use the bg-linear-* family. |
start-* |
inset-s-* |
Logical inline-start positioning. |
end-* |
inset-e-* |
Logical inline-end positioning. |
Unmodified gradients interpolate in OKLAB. Append an explicit modifier such as /srgb or /oklch only when a particular color space is required.
Preserve compatibility deliberately
- Older-browser fallbacks cover
oklab, opacity-modified colors, and registered-custom-property implementations used by shadows, transforms, and gradients.
- Explicit gradient interpolation falls back to the browser default when unsupported; test visual fidelity when older browsers matter.
- CSS nesting is processed even when Lightning CSS does not run, including in
@tailwindcss/browser and Tailwind Play.
- The default sans stack uses explicit platform fonts so Windows CJK selection can follow the document's
lang attribute.
Theme and Configuration Quick Reference
Theme block modes
| Form |
Behavior |
@theme { ... } |
Defines tokens and emits used variables. |
@theme inline { ... } |
Inlines referenced values into generated utilities. |
@theme static { ... } |
Emits every variable in the block, even when unused. |
--color-*: initial |
Removes one default namespace and its generated utilities. |
--*: initial |
Removes the entire default theme before replacement. |
Theme namespaces create APIs for colors, fonts, text sizes, font weights, tracking, leading, spacing, radii, shadows, inset shadows, drop shadows, blur, perspective, aspect ratios, easing, and animation. Breakpoint tokens create responsive variants; container tokens create container variants and size utilities.
Animation ownership
Nest a keyframe in @theme beside its --animate-* token when it should be emitted only if that animation is used. Put @keyframes outside @theme when it must always exist.
@theme {
--animate-fade-in: fade-in 300ms ease-out;
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
}
Source detection controls
@source not "./src/components/legacy";
@source inline("{hover:,}bg-red-{50,{100..900..100},950}");
@source not inline("container");
@source not excludes paths from candidate scanning.
@source inline() generates literal candidates and supports brace-expanded lists, ranges, and variants.
@source not inline() suppresses a candidate even if project scanning finds it.
Build-time functions and functional utilities
.card {
color: --alpha(var(--color-lime-300) / 50%);
margin: --spacing(4);
}
@utility tab-* {
tab-size: --value(integer, --default(4));
}
--alpha() compiles opacity changes to color-mix(). --spacing() multiplies the base spacing token and preserves a length for zero by compiling --spacing(0) to 0px. Within a functional @utility, nest --default(...) in --value(...) or --modifier(...) to support both a bare utility and explicitly valued forms.
Common Utility Changes
Values and gradients
Grid counts and spacing-based utilities accept bare values outside a configured scale:
<div class="grid grid-cols-15 w-17 pr-29"></div>
Linear, radial, and conic gradients share from-*, via-*, and to-* stops:
<div class="bg-linear-45/oklch from-indigo-500 to-pink-500"></div>
<div class="bg-conic/[in_hsl_longer_hue] from-red-600 to-red-600"></div>
<div class="bg-radial-[at_25%_25%] from-white to-zinc-900 to-75%"></div>
Shadows and masks
<h1 class="text-shadow-lg text-shadow-sky-300">Title</h1>
<h2 class="text-shadow-sm/12.5">Subtitle</h2>
<svg class="drop-shadow-xl drop-shadow-cyan-500/50">...</svg>
<img class="mask-b-from-50% mask-radial-[50%_90%] mask-radial-from-80%" src="photo.jpg" />
- Text shadows range from
text-shadow-2xs through text-shadow-lg; size and color compose.
- Box, text, drop, and inset shadow sizes accept fractional opacity modifiers.
- Drop-shadow size and color are separate; color accepts an opacity modifier.
- Linear, radial, and conic mask utilities compose on one element.
Wrapping and alignment
| Utility |
Use |
wrap-break-word |
Break long words and URLs when necessary. |
wrap-anywhere |
Include mid-word breaks in intrinsic sizing; useful in flex layouts without min-w-0. |
items-baseline-last |
Align flex or grid children by their last text baseline. |
self-baseline-last |
Apply last-baseline alignment to one item. |
justify-center-safe |
Fall back to start alignment when centering would overflow. |
Safe alignment works across flex and grid alignment properties by appending -safe to the alignment value.
Logical properties, scrollbars, and size containers
- Spacing and borders:
pbs-*, pbe-*, mbs-*, mbe-*, scroll-pbs-*, scroll-pbe-*, scroll-mbs-*, scroll-mbe-*, border-bs-*, and border-be-*.
- Sizing:
inline-*, block-*, min-inline-*, max-inline-*, min-block-*, and max-block-*.
- Positioning:
inset-s-*, inset-e-*, inset-bs-*, and inset-be-*.
<div class="scrollbar-thin scrollbar-thumb-sky-700/60 scrollbar-track-sky-100 scrollbar-gutter-stable overflow-auto"></div>
<div class="@container-size/sidebar"><div class="h-[50cqb]"></div></div>
@container-size creates a size container with block-axis units such as cqb and cqh; use @container-size/{name} for a named one.
Variant Quick Reference
| Variant |
Meaning |
data-current: |
Match a present boolean data attribute without bracket syntax. |
not-hover: |
Negate a state; not-* also works with media and support conditions. |
in-focus: |
React to a matching ancestor without requiring a group class. |
open: |
Match open disclosures and the :popover-open state. |
pointer-fine: / pointer-coarse: |
Test the primary pointing device. |
any-pointer-fine: / any-pointer-coarse: |
Test all available pointing devices. |
details-content: |
Target the content container generated by <details>. |
inverted-colors: |
Match an operating-system inverted-color mode. |
noscript: |
Apply CSS while JavaScript is disabled. |
user-valid: / user-invalid: |
Validate after user interaction instead of on initial render. |
<button class="p-2 pointer-coarse:p-4">Select</button>
<input required class="border user-valid:border-green-500 user-invalid:border-red-500" />
<div class="hidden noscript:block">Please enable JavaScript.</div>
In authored CSS, a colon stacks conditions while a comma applies one declaration block to alternatives:
.button {
@variant hover:focus { background: var(--color-sky-600); }
@variant active, disabled { opacity: 50%; }
}
Integration Choices
- Use
@reference in component styles or CSS modules to expose theme values, custom utilities, and variants without duplicating the referenced stylesheet.
- Use
@tailwindcss/vite with Vite projects, including Vite 8.
- Use
@tailwindcss/webpack to run Tailwind directly as a webpack loader instead of routing through PostCSS.
- Add
--poll or --poll=<milliseconds> to CLI watch mode when filesystem events are unavailable or unreliable.
prettier-plugin-tailwindcss can sort classes while removing duplicate classes and unnecessary whitespace.
- Tailwind Plus plain-HTML UI blocks include accessible interactive behavior without a framework requirement.
Before You Finish
- Confirm tokens that should create utilities live in
@theme, not only in :root.
- Check migrated gradients and logical positioning for renamed classes.
- Keep
@source inline() inputs explicit and use exclusions narrowly.
- Choose primary-pointer or any-pointer variants based on the actual interaction requirement.
- Prefer higher-level typography utilities such as
tabular-nums before font-features-*.
- Open the topic references before changing configuration or writing compatibility-sensitive utilities.
1---2name: tailwind-knowledge-patch-23description: Tailwind CSS4license: MIT5---678# Tailwind CSS Knowledge Patch910Use this patch when configuring, migrating, integrating, or extending a Tailwind CSS project. Check migration-sensitive behavior first, then open only the topic reference relevant to the task.1112## Reference Index1314| Reference | Topics |15|---|---|16| [Configuration and Theming](references/configuration.md) | `@theme`, token namespaces, source detection, legacy configuration, build-time functions, custom utilities |17| [Integrations and Ecosystem](references/integrations.md) | `@reference`, Vite, webpack, CLI watch polling, CSS nesting, Tailwind Plus, Prettier |18| [Migration and Compatibility](references/migration.md) | Removed configuration, renamed utilities, browser fallbacks, logical positioning, platform font behavior |19| [Utilities](references/utilities.md) | Values, gradients, masks, shadows, wrapping, alignment, logical properties, scrollbars, containers, typography |20| [Variants and States](references/variants.md) | Data and ancestor states, negation, pointers, validation, details, popovers, authored CSS composition |2122## Migration Hazards First2324### Use the CSS-first entry point2526```css27@import "tailwindcss";2829@theme {30 --color-brand: oklch(0.68 0.14 250);31 --breakpoint-3xl: 120rem;32}33```3435- Put framework tokens in a top-level `@theme`; a `:root` custom property alone does not create a utility or variant.36- Use `@config` and `@plugin` only as bridges for legacy JavaScript configuration and plugins.37- Do not carry forward `corePlugins`, `safelist`, or `separator`; they are unsupported. Replace safelisting with `@source inline()`.3839### Update renamed and deprecated classes4041| Old form | Current form | Note |42|---|---|---|43| `bg-gradient-to-r` | `bg-linear-to-r` | Linear gradients use the `bg-linear-*` family. |44| `start-*` | `inset-s-*` | Logical inline-start positioning. |45| `end-*` | `inset-e-*` | Logical inline-end positioning. |4647Unmodified gradients interpolate in OKLAB. Append an explicit modifier such as `/srgb` or `/oklch` only when a particular color space is required.4849### Preserve compatibility deliberately5051- Older-browser fallbacks cover `oklab`, opacity-modified colors, and registered-custom-property implementations used by shadows, transforms, and gradients.52- Explicit gradient interpolation falls back to the browser default when unsupported; test visual fidelity when older browsers matter.53- CSS nesting is processed even when Lightning CSS does not run, including in `@tailwindcss/browser` and Tailwind Play.54- The default sans stack uses explicit platform fonts so Windows CJK selection can follow the document's `lang` attribute.5556## Theme and Configuration Quick Reference5758### Theme block modes5960| Form | Behavior |61|---|---|62| `@theme { ... }` | Defines tokens and emits used variables. |63| `@theme inline { ... }` | Inlines referenced values into generated utilities. |64| `@theme static { ... }` | Emits every variable in the block, even when unused. |65| `--color-*: initial` | Removes one default namespace and its generated utilities. |66| `--*: initial` | Removes the entire default theme before replacement. |6768Theme namespaces create APIs for colors, fonts, text sizes, font weights, tracking, leading, spacing, radii, shadows, inset shadows, drop shadows, blur, perspective, aspect ratios, easing, and animation. Breakpoint tokens create responsive variants; container tokens create container variants and size utilities.6970### Animation ownership7172Nest a keyframe in `@theme` beside its `--animate-*` token when it should be emitted only if that animation is used. Put `@keyframes` outside `@theme` when it must always exist.7374```css75@theme {76 --animate-fade-in: fade-in 300ms ease-out;7778 @keyframes fade-in {79 from { opacity: 0; }80 to { opacity: 1; }81 }82}83```8485### Source detection controls8687```css88@source not "./src/components/legacy";89@source inline("{hover:,}bg-red-{50,{100..900..100},950}");90@source not inline("container");91```9293- `@source not` excludes paths from candidate scanning.94- `@source inline()` generates literal candidates and supports brace-expanded lists, ranges, and variants.95- `@source not inline()` suppresses a candidate even if project scanning finds it.9697### Build-time functions and functional utilities9899```css100.card {101 color: --alpha(var(--color-lime-300) / 50%);102 margin: --spacing(4);103}104105@utility tab-* {106 tab-size: --value(integer, --default(4));107}108```109110`--alpha()` compiles opacity changes to `color-mix()`. `--spacing()` multiplies the base spacing token and preserves a length for zero by compiling `--spacing(0)` to `0px`. Within a functional `@utility`, nest `--default(...)` in `--value(...)` or `--modifier(...)` to support both a bare utility and explicitly valued forms.111112## Common Utility Changes113114### Values and gradients115116Grid counts and spacing-based utilities accept bare values outside a configured scale:117118```html119<div class="grid grid-cols-15 w-17 pr-29"></div>120```121122Linear, radial, and conic gradients share `from-*`, `via-*`, and `to-*` stops:123124```html125<div class="bg-linear-45/oklch from-indigo-500 to-pink-500"></div>126<div class="bg-conic/[in_hsl_longer_hue] from-red-600 to-red-600"></div>127<div class="bg-radial-[at_25%_25%] from-white to-zinc-900 to-75%"></div>128```129130### Shadows and masks131132```html133<h1 class="text-shadow-lg text-shadow-sky-300">Title</h1>134<h2 class="text-shadow-sm/12.5">Subtitle</h2>135<svg class="drop-shadow-xl drop-shadow-cyan-500/50">...</svg>136<img class="mask-b-from-50% mask-radial-[50%_90%] mask-radial-from-80%" src="photo.jpg" />137```138139- Text shadows range from `text-shadow-2xs` through `text-shadow-lg`; size and color compose.140- Box, text, drop, and inset shadow sizes accept fractional opacity modifiers.141- Drop-shadow size and color are separate; color accepts an opacity modifier.142- Linear, radial, and conic mask utilities compose on one element.143144### Wrapping and alignment145146| Utility | Use |147|---|---|148| `wrap-break-word` | Break long words and URLs when necessary. |149| `wrap-anywhere` | Include mid-word breaks in intrinsic sizing; useful in flex layouts without `min-w-0`. |150| `items-baseline-last` | Align flex or grid children by their last text baseline. |151| `self-baseline-last` | Apply last-baseline alignment to one item. |152| `justify-center-safe` | Fall back to start alignment when centering would overflow. |153154Safe alignment works across flex and grid alignment properties by appending `-safe` to the alignment value.155156### Logical properties, scrollbars, and size containers157158- Spacing and borders: `pbs-*`, `pbe-*`, `mbs-*`, `mbe-*`, `scroll-pbs-*`, `scroll-pbe-*`, `scroll-mbs-*`, `scroll-mbe-*`, `border-bs-*`, and `border-be-*`.159- Sizing: `inline-*`, `block-*`, `min-inline-*`, `max-inline-*`, `min-block-*`, and `max-block-*`.160- Positioning: `inset-s-*`, `inset-e-*`, `inset-bs-*`, and `inset-be-*`.161162```html163<div class="scrollbar-thin scrollbar-thumb-sky-700/60 scrollbar-track-sky-100 scrollbar-gutter-stable overflow-auto"></div>164<div class="@container-size/sidebar"><div class="h-[50cqb]"></div></div>165```166167`@container-size` creates a size container with block-axis units such as `cqb` and `cqh`; use `@container-size/{name}` for a named one.168169## Variant Quick Reference170171| Variant | Meaning |172|---|---|173| `data-current:` | Match a present boolean data attribute without bracket syntax. |174| `not-hover:` | Negate a state; `not-*` also works with media and support conditions. |175| `in-focus:` | React to a matching ancestor without requiring a `group` class. |176| `open:` | Match open disclosures and the `:popover-open` state. |177| `pointer-fine:` / `pointer-coarse:` | Test the primary pointing device. |178| `any-pointer-fine:` / `any-pointer-coarse:` | Test all available pointing devices. |179| `details-content:` | Target the content container generated by `<details>`. |180| `inverted-colors:` | Match an operating-system inverted-color mode. |181| `noscript:` | Apply CSS while JavaScript is disabled. |182| `user-valid:` / `user-invalid:` | Validate after user interaction instead of on initial render. |183184```html185<button class="p-2 pointer-coarse:p-4">Select</button>186<input required class="border user-valid:border-green-500 user-invalid:border-red-500" />187<div class="hidden noscript:block">Please enable JavaScript.</div>188```189190In authored CSS, a colon stacks conditions while a comma applies one declaration block to alternatives:191192```css193.button {194 @variant hover:focus { background: var(--color-sky-600); }195 @variant active, disabled { opacity: 50%; }196}197```198199## Integration Choices200201- Use `@reference` in component styles or CSS modules to expose theme values, custom utilities, and variants without duplicating the referenced stylesheet.202- Use `@tailwindcss/vite` with Vite projects, including Vite 8.203- Use `@tailwindcss/webpack` to run Tailwind directly as a webpack loader instead of routing through PostCSS.204- Add `--poll` or `--poll=<milliseconds>` to CLI watch mode when filesystem events are unavailable or unreliable.205- `prettier-plugin-tailwindcss` can sort classes while removing duplicate classes and unnecessary whitespace.206- Tailwind Plus plain-HTML UI blocks include accessible interactive behavior without a framework requirement.207208## Before You Finish209210- Confirm tokens that should create utilities live in `@theme`, not only in `:root`.211- Check migrated gradients and logical positioning for renamed classes.212- Keep `@source inline()` inputs explicit and use exclusions narrowly.213- Choose primary-pointer or any-pointer variants based on the actual interaction requirement.214- Prefer higher-level typography utilities such as `tabular-nums` before `font-features-*`.215- Open the topic references before changing configuration or writing compatibility-sensitive utilities.