Built-in Variants
Tailwind includes many variants out of the box:Pseudo-class Variants
Pseudo-element Variants
Media Query Variants
Variant Categories
State Variants
pseudo-class
Applied on hover (with
@media (hover: hover) wrapper)pseudo-class
Applied when element has focus
pseudo-class
Applied when element is being activated
pseudo-class
Applied to visited links
pseudo-class
Applied when element is disabled
Form Variants
Positional Variants
Group & Peer Variants
Apply styles based on parent or sibling state:Responsive Variants
The default breakpoints:Custom Variants with Plugins
Create custom variants using the plugin API:Static Variant
Add a simple static variant:tailwind.config.ts
Functional Variant
Create variants that accept values:Compound Variants
Create variants that modify other variants:Functional Variants
Some variants accept arbitrary values:Stacking Variants
Combine multiple variants:Variant Order
Variants are applied in a specific order (roughly):- Responsive variants (
sm:,md:, etc.) - State variants (
hover:,focus:, etc.) - Compound variants (
group-*:,peer-*:) - Pseudo-elements (
before:,after:, etc.)
The order of variants in your class name doesn’t matter - Tailwind handles ordering automatically based on CSS specificity rules.
Advanced Variant Examples
Custom Dark Mode
Implement a custom dark mode strategy:RTL Support
Container Queries
Use container query variants:Not Variant
Negate other variants:Variant Modifiers
Some variants support modifiers:Best Practices
- Use semantic variants -
hover:,focus:, etc. are more maintainable than arbitrary selectors - Leverage responsive variants - Build mobile-first with progressive enhancement
- Group related states - Use
groupandpeerfor parent/sibling relationships - Be mindful of specificity - More variants = higher specificity