Tailwind CSS interview question · Most asked
How do you implement dark mode with Tailwind?
Summary
Use the dark: variant. By default it follows prefers-color-scheme. For a user toggle, define class-based dark mode with @custom-variant dark (&:where(.dark, .dark *)); and toggle the dark class on <html>, setting it in an inline head script (or server-side) to avoid a flash of light theme.
Longer Answer
With semantic colour tokens that switch value under .dark, many components need no dark: classes at all.
Key Points
- dark: variant.
- Media query by default.
- @custom-variant for a toggle.
- Set the class before first paint.
Deep dive: Tailwind CSS in Production: The White Flash in Dark Mode
Explanation
What interviewers look for
Mentions the flash and how to avoid it.
More most-asked Tailwind CSS questions
- How do you customize Tailwind's design tokens in v4?
- Why doesn't className={`bg-${color}-500`} work, and what should you do instead?
- Explain Tailwind's responsive design approach.
- How does Tailwind decide which CSS to generate?
- What is Tailwind CSS and what does 'utility-first' mean?
- What changed in Tailwind CSS v4 compared with v3?
- How do you make Tailwind interfaces accessible?
- What's the difference between flex and grid in Tailwind, and when do you use each?