Dark mode and theming
Use the dark variant, CSS variables and a persisted preference.
What you will be able to do
- Use dark: variants for simple cases.
- Store the preference and apply a class on html.
- Define semantic tokens such as surface and ink.
- Check contrast in both themes.
In plain English
Tailwind’s dark variant can follow the operating system or a class you control. For a product theme, store a small token layer in CSS variables and switch the values, then reference them from utilities or components.
:root {
--surface: #ffffff;
--ink: #0f172a;
}
.dark {
--surface: #0f172a;
--ink: #e2e8f0;
}
body {
background: var(--surface);
color: var(--ink);
}Your turn
EasyAdd a dark variant
Make a card white in light mode and slate-900 in dark mode using dark: utilities.
HTML · starter
<div class="">Check your understanding before moving on.
Knowledge checkQuestion 1
Why avoid filter: invert(1) for dark mode?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.