The problem: redefining colors per theme
A CTA component with a heading, body copy, and button has some color scheme. Written as plain CSS it means rules for the heading and body text. Rewritten as Tailwind, those same values become utility classes in the markup.

<div class="bg-red-900 text-white">
<h3 class="bg-red-600 text-red-900">Join our mailing list</h3>
<div>
<p>Be the first to hear about our new offerings</p>
<button class="bg-red-600" type="button">Sign up</button>
</div>
</div>
Applying a second scheme gets harder. In ordinary CSS the usual trick is a modifier class such as .cta--blue (BEM convention) appended to the component, with the color values redefined further down the cascade.
.cta--blue {
background-color: #2a4365; // dark blue
}
.cta--blue .cta__heading {
background-color: #3182ce; // medium blue
color: #2a4365;
}
.cta--blue .cta__button {
background-color: #3182ce;
}

A preprocessor like Sass helps with color variables and nested .cta__heading / .cta__body selectors, but only by giving each value a single place to update — the repetition remains. At ten color schemes you are duplicating the block ten times, and if the design system has ten schemes per component, and themes that also change fonts, the CSS volume grows quickly.
Under Tailwind the theme change happens in the HTML instead, swapping several classes at once. That is not trivial even inside React or Vue: to keep unused styles out of production builds, Tailwind (at the time of writing) discourages concatenating class name strings, so theming logic ends up piled into the components.
Custom properties as the theme layer
Declaring custom properties on :root (or body) makes them global, and any selector can then reference them in place of literal color values.
:root {
--primary: #742a2a; // dark red;
--secondary: #e53e3e; // medium red
}
.cta {
background-color: var(--primary);
color: white;
}
.cta__heading {
background-color: var(--secondary);
color: var(--primary);
}
.cta__button {
background-color: var(--secondary);
}
The payoff arrives when each theme simply rewrites those custom property values. Inheritance carries the new values to everything inside the element the theme class is applied to.
.th-blue {
--primary: #2a4365; // dark blue
--secondary: #3182ce; // medium blue
}
No component-specific rule is needed: the .th-blue class can be attached to one component or to the <body> for a page-wide theme that individual components override. Being a utility class, it works anywhere in the codebase, which can save yet more code than a component-scoped selector like .cta--blue.
Filling the Internet Explorer 11 gap
Brand colors and fonts have to appear even on old browsers, so progressive enhancement is a poor fit here, and hand-written @supports fallbacks would cost more work than custom properties save. A polyfill is required, and there are two candidates.
postcss-custom-properties
This PostCSS plugin resolves variables at build time, emitting the computed value alongside the property. Given input CSS, the processed output looks like this:
:root {
--color: red;
}
h1 {
color: var(--color);
}
h1 {
color: red;
color: var(--color);
}
Browsers without custom property support ignore the second rule and use the plain value. An option can strip the custom-property rules entirely for a smaller file — fine for static values, but then no browser receives the variable, which breaks dynamic updates.
The plugin also has two constraints: the file or files where the custom properties live must be listed in its config, and custom properties may only be defined on the :root selector. The first is a minor annoyance; the second makes the plugin useless for theming, since themes depend on redefining variables on a selector.
ie11CustomProperties
This alternative ships a client-side script instead of preprocessing. Loading it conditionally keeps it out of every other browser:
<script>window.MSInputMethodContext && document.documentMode && document.write('<script src="https://cdn.jsdelivr.net/gh/nuxodin/[email protected]/ie11CustomProperties.min.js"><\/script>');</script>
It supports the theming pattern shown above in full, which is why it was the chosen option. One limitation: custom properties set in style attributes are not polyfilled. The theming example was tested against it and works.
Wiring custom properties into Tailwind
Tailwind's utility classes each carry a single purpose — .bg-red-medium for a red background-color, .text-red-medium for color, and equivalents for border, box-shadow, and other places a color is needed. Colors are declared in a config file:
module.exports = {
theme: {
colors: {
red: {
medium: '#e53e3e',
dark: '#742a2a'
},
blue: {
medium: '#3182ce',
dark: '#2a4365'
}
}
}
}
To route those classes through custom properties, declare them in the config as well. A th- prefix on colors and theme class names makes their purpose obvious, though any convention will do.
module.exports = {
theme: {
colors: {
'th-primary': 'var(--primary)',
'th-secondary': 'var(--secondary)'
}
}
}
From then on, .bg-th-primary is available through Tailwind and is equivalent to writing:
.some-element {
background-color: var(--primary);
}
The themes themselves are defined in CSS as before:
:root {
--primary: #742a2a;
--secondary: #742a2a;
}
.th-blue {
--primary: #2a4365;
--secondary: #3182ce;
}
Both CTAs below are identical except for the .th-blue class on the second. The first uses the defaults declared on :root; the second picks up the blue theme. Classes unrelated to color are omitted for clarity.
<!--Component with default (red) theme-->
<div class="bg-th-primary">
<h3 class="bg-th-secondary text-th-primary">Join our mailing list</h3>
<div>
<p>Be the first to hear about our new offerings</p>
<button class="bg-th-secondary" type="button">Sign up</button>
</div>
</div>
<!--Component with blue theme-->
<div class="th-blue bg-th-primary">
<h3 class="bg-th-secondary text-th-primary">Join our mailing list</h3>
<div>
<p>Be the first to hear about our new offerings</p>
<button class="bg-th-secondary" type="button">Sign up</button>
</div>
</div>
Keeping a style guide in the config
Tailwind's recommendation is to define every variable in the config, and it holds up: one source of truth instead of several scattered places where colors and other theme values live. To use config values from custom properties, first declare the full color set in the config (assuming the default palette isn't in use), then access the theme object in CSS.
module.exports = {
theme: {
colors: {
red: {
medium: '#e53e3e',
dark: '#742a2a'
},
blue: {
medium: '#3182ce',
dark: '#2a4365'
},
'th-primary': 'var(--primary)',
'th-secondary': 'var(--secondary)'
}
}
}
:root {
--primary: theme('colors.red.dark');
--secondary: theme('colors.red.medium');
}
.th-blue {
--primary: theme('colors.blue.dark');
--secondary: theme('colors.blue.medium');
}
The approach cuts the code needed for theming sharply and removes most of its maintenance burden, and it does so without browser-support worries once the polyfill is in place.



