Dark mode usually breaks in the boring places. The light theme looks clean, then someone adds a dark theme by editing component styles one at a time, and six months later half the interface follows the dark palette while the rest quietly keeps the light one. The failure is rarely about color taste. It is about names.
The structural fix is one set of variable names carrying two sets of values. The CSS Variable Palette Builder on Ovatly turns a pasted list of colors into a :root block of CSS custom properties, plus a Tailwind snippet referencing the same names. It does not contain a dark-mode switch, and this guide will not pretend otherwise. What it gives you is a reliable way to produce two consistently named variable sets, and consistent names are the entire mechanism dark mode runs on.
Contents
- Quick answer
- What the builder generates
- Why matching names do all the work
- How to build both palettes, step by step
- Worked example: primary and paper, light and dark
- Using the variables with Tailwind
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
Quick answer
Build your light palette and your dark palette as two separate inputs to the CSS Variable Palette Builder, using exactly the same color names in both. The builder normalizes every name to lowercase kebab-case and applies the same prefix, color by default, so both runs produce variables with identical names. Paste the light block as your :root block, then redefine the same names under a dark-mode selector in your own CSS. Every rule that references the variables follows automatically, because it reads the value by name, not by hex.
What the builder generates
You paste one color per line. The accepted forms are name: #HEX, name #HEX, --name: #HEX with an optional semicolon, or a bare #HEX with no name. Three-digit hex values are normalized to six digits, and names are normalized to lowercase kebab-case, so Primary Color and primary-color come out as the same name. If two lines end up with the same name, the duplicate receives a numeric suffix instead of overwriting the first. Lines without a valid hex are reported with their line number and excluded from the output.
The output is a :root block of CSS custom properties, plus a Tailwind snippet in two forms, a v4 @theme form and a v3 config form, referencing the same names. Nothing in that output knows or cares whether a palette is light or dark. That neutrality is the point: the same generator, fed twice with matching names, produces both halves of a theme.
Why matching names do all the work
A CSS custom property is resolved where it is used. When a rule says background: var(--color-paper), the browser looks up the current value of --color-paper for that element. If a dark-mode selector redefines --color-paper, every rule referencing it picks up the dark value at once, with no edits to the rules themselves.
That mechanism has one strict condition: the name being redefined must be the name being referenced, character for character. If the dark set calls a color primarycolor while the light set and the rules use primary-color, the redefinition lands on a variable nothing reads, and that part of the interface stays light. This is why the builder's normalization matters more than it first appears. Lowercase kebab-case output plus one fixed prefix removes case and separator drift between the two runs, as long as you type the same names and keep the same prefix both times.
How to build both palettes, step by step
- Write your light palette, one named color per line, for example
primary: #2563EB. - Paste it into the builder, keep the prefix at the default
color, and copy the:rootblock into your stylesheet. - Write your dark palette using the same names in the same order, with the dark values you have chosen. The builder does not choose these values; you do.
- Run the builder again with the same prefix, and read the invalid-line report before copying anything, so no color silently goes missing from the second set.
- In your stylesheet, keep the light block under
:root, then write a dark selector block that redefines the same names. This step is plain CSS that you write yourself, not something the builder emits. - Reference the variables in every component rule. A rule that pastes a raw hex value can never follow the theme.
Worked example: primary and paper, light and dark
Start with the light palette, using the builder's own worked example input:
primary: #2563EB
paper: #FAFAF7
The builder produces this block:
:root {
--color-primary: #2563EB;
--color-paper: #FAFAF7;
}
Now the dark palette. The two values below are ones typed for this example: the builder does not compute, suggest or check them, it only formats what you paste.
primary: #7CA1F3
paper: #16181D
Run through the builder with the same prefix, this input produces the same two names, --color-primary and --color-paper, carrying the dark values. The last step is the plain CSS pattern, written by you in your stylesheet, that puts the dark values in force:
[data-theme="dark"] {
--color-primary: #7CA1F3;
--color-paper: #16181D;
}
Because the names match the light block exactly, a rule such as color: var(--color-primary) needs no dark variant of its own. Flip the attribute, and the lookup returns the dark value.
Using the variables with Tailwind
If your project uses Tailwind, you do not need to retype the palette. Next to the :root block, the builder emits a Tailwind snippet, in a v4 @theme form and a v3 config form, and both reference the same variable names rather than copying the hex values. As the tool's entry puts it, referencing the variables in Tailwind keeps one source of truth, dark-mode overrides included: change a value in the variable block, and the utilities built on it follow.
Limitations and honest tradeoffs
The builder formats colors; it does not design a dark theme. It will not suggest dark values, check contrast between your pairs, or warn you that a dark choice is unreadable. Those judgments stay with you.
It also contains no toggle. Switching themes still needs your own mechanism, whether that is an attribute on the root element, a class, or a media query, and the builder has no opinion about which one you use.
Finally, the safeguards cut both ways. A duplicate name inside one palette receives a numeric suffix, which is helpful for a single palette but breaks name matching if one set has the duplicate and the other does not. And an excluded invalid line means a variable your dark block expects may simply not exist. Read the report on both runs.
Common mistakes
- Typing different names in the dark set. Normalization fixes case and separators, not different words. One renamed color stays light forever.
- Changing the prefix on the second run. The prefix is part of every generated name, so a different prefix creates a parallel variable set that your rules never reference.
- Pasting raw hex values into component rules. Only declarations that reference the variables can follow a redefinition.
- Skipping the invalid-line report. An excluded line in either run means the two sets no longer cover the same colors.
- Expecting the builder to pick dark colors. It formats the values you supply. Choosing them is design work it does not do.
FAQs
Does the builder have a dark mode setting? No. The builder generates variable blocks from the colors you paste; it has no dark-mode switch. You run it twice, once for the light palette and once for the dark palette, and redefine the same variable names under a dark selector in your own CSS.
Why must the names in both palettes match exactly?
Redefinition works by name. A rule that references --color-primary picks up whichever value is currently in force, so the dark block only changes the interface if it redefines the exact names the rules use. A different spelling is a different variable, and the rule never sees the dark value.
Which input formats does the builder accept?
One color per line, as name: #HEX, name #HEX or --name: #HEX with an optional semicolon, or as a bare #HEX. Three-digit hex values are normalized to six digits, and names are normalized to lowercase kebab-case.
What happens if one of my lines is wrong? Lines without a valid hex are reported with their line number and excluded from the output. Read the report before copying the block: an excluded line means a variable your stylesheet expects will not exist.
Can I use the generated variables with Tailwind?
Yes. Next to the :root block, the builder emits a Tailwind snippet, in a v4 @theme form and a v3 config form, referencing the same variable names. Referencing the variables in Tailwind keeps one source of truth, dark-mode overrides included.
Conclusion
Dark mode with CSS variables is a naming discipline, not a feature you switch on. Run the CSS Variable Palette Builder twice with identical names and one prefix, redefine those names under a dark selector, and every referencing rule follows. If your variable layer is already built and a redesign is looming, read our companion guide on CSS variable mistakes that make redesigns painful before you touch it. For more guides in this series, see our Color and Design Tools guides.