46.1 @variant
@variant is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
Step by step
- Identify the CSS behavior behind @variant.
- Build a very small HTML example before placing it inside a large component.
- Apply the Tailwind utilities and inspect the result at multiple viewport widths.
- Add interaction, dark mode, RTL, or accessibility states when the component needs them.
- Refactor repeated markup into a reusable component only after the visual rule is understood.
10 practical examples
- Apply @variant to a course website and explain the decision you made.
- Apply @variant to a online store and explain the decision you made.
- Apply @variant to a banking app and explain the decision you made.
- Apply @variant to a school portal and explain the decision you made.
- Apply @variant to a clinic booking system and explain the decision you made.
- Apply @variant to a dashboard and explain the decision you made.
- Apply @variant to a restaurant site and explain the decision you made.
- Apply @variant to a mobile app and explain the decision you made.
- Apply @variant to a creator site and explain the decision you made.
- Apply @variant to a business landing page and explain the decision you made.
Hands-on example
<div class="flex flex-wrap items-center gap-4 rounded-xl border bg-white p-6 shadow-sm">
<span class="font-semibold text-slate-900">@variant</span>
</div>Expected output
A working responsive example demonstrating @variant, with no page-wide overflow and clear behavior across breakpoints.
Practice exercise
Create a fresh example for @variant using a different product, screen, component, or content set. Explain what changed and why.
46.2 @custom-variant
@custom-variant is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
Step by step
- Identify the CSS behavior behind @custom-variant.
- Build a very small HTML example before placing it inside a large component.
- Apply the Tailwind utilities and inspect the result at multiple viewport widths.
- Add interaction, dark mode, RTL, or accessibility states when the component needs them.
- Refactor repeated markup into a reusable component only after the visual rule is understood.
10 practical examples
- Apply @custom-variant to a course website and explain the decision you made.
- Apply @custom-variant to a online store and explain the decision you made.
- Apply @custom-variant to a banking app and explain the decision you made.
- Apply @custom-variant to a school portal and explain the decision you made.
- Apply @custom-variant to a clinic booking system and explain the decision you made.
- Apply @custom-variant to a dashboard and explain the decision you made.
- Apply @custom-variant to a restaurant site and explain the decision you made.
- Apply @custom-variant to a mobile app and explain the decision you made.
- Apply @custom-variant to a creator site and explain the decision you made.
- Apply @custom-variant to a business landing page and explain the decision you made.
Hands-on example
@custom-variant theme-midnight (&:where([data-theme="midnight"] *));Expected output
A working responsive example demonstrating @custom-variant, with no page-wide overflow and clear behavior across breakpoints.
Practice exercise
Create a fresh example for @custom-variant using a different product, screen, component, or content set. Explain what changed and why.
46.3 Media Variants
Media Variants is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
Step by step
- Identify the CSS behavior behind Media Variants.
- Build a very small HTML example before placing it inside a large component.
- Apply the Tailwind utilities and inspect the result at multiple viewport widths.
- Add interaction, dark mode, RTL, or accessibility states when the component needs them.
- Refactor repeated markup into a reusable component only after the visual rule is understood.
10 practical examples
- Apply Media Variants to a course website and explain the decision you made.
- Apply Media Variants to a online store and explain the decision you made.
- Apply Media Variants to a banking app and explain the decision you made.
- Apply Media Variants to a school portal and explain the decision you made.
- Apply Media Variants to a clinic booking system and explain the decision you made.
- Apply Media Variants to a dashboard and explain the decision you made.
- Apply Media Variants to a restaurant site and explain the decision you made.
- Apply Media Variants to a mobile app and explain the decision you made.
- Apply Media Variants to a creator site and explain the decision you made.
- Apply Media Variants to a business landing page and explain the decision you made.
Hands-on example
<div class="flex flex-wrap items-center gap-4 rounded-xl border bg-white p-6 shadow-sm">
<span class="font-semibold text-slate-900">Media Variants</span>
</div>Expected output
A working responsive example demonstrating Media Variants, with no page-wide overflow and clear behavior across breakpoints.
Practice exercise
Create a fresh example for Media Variants using a different product, screen, component, or content set. Explain what changed and why.
46.4 Selector Variants
Selector Variants is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
Step by step
- Identify the CSS behavior behind Selector Variants.
- Build a very small HTML example before placing it inside a large component.
- Apply the Tailwind utilities and inspect the result at multiple viewport widths.
- Add interaction, dark mode, RTL, or accessibility states when the component needs them.
- Refactor repeated markup into a reusable component only after the visual rule is understood.
10 practical examples
- Apply Selector Variants to a course website and explain the decision you made.
- Apply Selector Variants to a online store and explain the decision you made.
- Apply Selector Variants to a banking app and explain the decision you made.
- Apply Selector Variants to a school portal and explain the decision you made.
- Apply Selector Variants to a clinic booking system and explain the decision you made.
- Apply Selector Variants to a dashboard and explain the decision you made.
- Apply Selector Variants to a restaurant site and explain the decision you made.
- Apply Selector Variants to a mobile app and explain the decision you made.
- Apply Selector Variants to a creator site and explain the decision you made.
- Apply Selector Variants to a business landing page and explain the decision you made.
Hands-on example
<div class="flex flex-wrap items-center gap-4 rounded-xl border bg-white p-6 shadow-sm">
<span class="font-semibold text-slate-900">Selector Variants</span>
</div>Expected output
A working responsive example demonstrating Selector Variants, with no page-wide overflow and clear behavior across breakpoints.
Practice exercise
Create a fresh example for Selector Variants using a different product, screen, component, or content set. Explain what changed and why.
46.5 Variant Composition
Variant Composition is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
Step by step
- Identify the CSS behavior behind Variant Composition.
- Build a very small HTML example before placing it inside a large component.
- Apply the Tailwind utilities and inspect the result at multiple viewport widths.
- Add interaction, dark mode, RTL, or accessibility states when the component needs them.
- Refactor repeated markup into a reusable component only after the visual rule is understood.
10 practical examples
- Apply Variant Composition to a course website and explain the decision you made.
- Apply Variant Composition to a online store and explain the decision you made.
- Apply Variant Composition to a banking app and explain the decision you made.
- Apply Variant Composition to a school portal and explain the decision you made.
- Apply Variant Composition to a clinic booking system and explain the decision you made.
- Apply Variant Composition to a dashboard and explain the decision you made.
- Apply Variant Composition to a restaurant site and explain the decision you made.
- Apply Variant Composition to a mobile app and explain the decision you made.
- Apply Variant Composition to a creator site and explain the decision you made.
- Apply Variant Composition to a business landing page and explain the decision you made.
Hands-on example
<div class="flex flex-wrap items-center gap-4 rounded-xl border bg-white p-6 shadow-sm">
<span class="font-semibold text-slate-900">Variant Composition</span>
</div>Expected output
A working responsive example demonstrating Variant Composition, with no page-wide overflow and clear behavior across breakpoints.
Practice exercise
Create a fresh example for Variant Composition using a different product, screen, component, or content set. Explain what changed and why.
Chapter 46 review — 10 questions and answers
1. What is the main purpose of @variant?
Answer: @variant is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
2. What is a common mistake with @variant?
Answer: Using @variant as memorized class names without understanding the CSS behavior, responsive context, accessibility, or component structure.
3. What is the main purpose of @custom-variant?
Answer: @custom-variant is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
4. What is a common mistake with @custom-variant?
Answer: Using @custom-variant as memorized class names without understanding the CSS behavior, responsive context, accessibility, or component structure.
5. What is the main purpose of Media Variants?
Answer: Media Variants is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
6. What is a common mistake with Media Variants?
Answer: Using Media Variants as memorized class names without understanding the CSS behavior, responsive context, accessibility, or component structure.
7. What is the main purpose of Selector Variants?
Answer: Selector Variants is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
8. What is a common mistake with Selector Variants?
Answer: Using Selector Variants as memorized class names without understanding the CSS behavior, responsive context, accessibility, or component structure.
9. What is the main purpose of Variant Composition?
Answer: Variant Composition is part of the Tailwind CSS 4.3 workflow. Learn what the underlying CSS property or layout rule does first, then use the utility class to apply that rule consistently in markup.
10. What is a common mistake with Variant Composition?
Answer: Using Variant Composition as memorized class names without understanding the CSS behavior, responsive context, accessibility, or component structure.