addVariant()
Register a static variant that modifies how utilities are applied.string
required
The variant name (must be alphanumeric, lowercase, with dashes or underscores)
string | string[] | CssInJs
required
Selector transformation, media query, or CSS-in-JS object defining the variant behavior
String Selector
Use& as a placeholder for the utility selector:
Array of Selectors
Object Syntax with @slot
Use@slot to mark where the utility styles should be inserted:
Media Queries
Complex Variants with Nesting
At-Rules and Supports
Advanced Example
matchVariant()
Register a dynamic variant that accepts values.string
required
The variant name
(value: string, extra: { modifier: string | null }) => string | string[]
required
Function that returns selector transformation(s) based on the value
object
Basic Example
With Named Values
Data Attributes
ARIA States
Screen Variants
With Modifiers
Group and Peer Variants
group-* and peer-* variants compound automatically, so you don’t need to use :merge() anymore.
Custom Sorting
Variant Compounding
Variants automatically work withgroup-* and peer-* patterns:
Stacking Variants
Variants can be stacked in any order:Validation
Variant names must:
- Start with a lowercase letter or number
- Contain only alphanumeric characters, dashes, or underscores
- Not include
:merge()in v4 (automatically handled)
Migration from v3
In v4, the:merge() pseudo-class is no longer needed. Variants automatically compound:
All built-in Tailwind variants (hover, focus, dark, responsive, etc.) work automatically with custom utilities. You only need to register custom variants for new interaction patterns.