


Colors are fundamental to design and thus fundamental to design systems as well. They play a core part in defining brand identity, so we must work within platform limits to ensure good performance, accessibility, and a consistent user experience while preserving design integrity.
If you've been working with the web for a long time, you might remember the era of web-safe colors: a limited palette of 216 colors that were guaranteed to display consistently across different browsers and operating systems. Those days brought rigidity and creative constraints that often resulted in bland, uniform websites. Thankfully, we can now be much more ambitious and flexible with our designs and create dynamic interfaces adhering to design systems without sacrificing style or introducing unnecessary complexity.
Modern CSS presents us with a rich plethora of features that we can use to bring our design systems to fruition on the web. The intent of this article is to outline some of the powerful color-related CSS features that you should be using with your design systems.
With the W3C’s Design Tokens specification reaching its first stable release in October 2025, we now have a standardized way to represent design values like colors across tools and platforms. This makes the connection between design intent and CSS implementation tighter than ever, and it’s the perfect moment to look at how modern CSS color features support that goal.
A surefire way to cause your design system to fall out of parity is to use hard-coded values throughout. Variables are the answer to this, and we use them all through our design stages, so it makes sense to use them in our code, too.
Once exclusively the domain of preprocessors like Sass, CSS has supported variables for a while now (technically, they're called custom properties, but everyone just calls them variables). We use variables from the initial concept in design tools to the final implementation in code.
We define variables with --variable-name: value and can then reference them with var(--primary-color). For example, we can create a variable (here called primary-color) and then apply it to the color of text in our document's body:
:root {
--primary-color: blue;
}
body {
color: var(--primary-color);
}The key to successful implementation lies in tying these CSS variables directly to your design tokens. Design tokens serve as the single source of truth for design decisions, and CSS variables become their direct translation into code. By maintaining this connection, you ensure that every color used in your interface is intentional and approved, preventing the rogue implementations we discussed earlier.
Defining everything with variables allows pushing out updates based on changes to brand guidelines or the base system in one place without requiring extensive manual effort – no need to laboriously crawl through every CSS file to update every place colors are defined.
Of course, beyond allowing us to build directly with our base design system, it will enable opening opportunities for theming and dynamic interfaces that tailor themselves within our design system to user needs. For example, allowing a high contrast display should a user request it.
You can chain variables with reasonable fallbacks: var(--brand-blue, #4169E1). In this example, if the brand blue color can't be used, it'll revert to the previous hex.
Working with digital colors can be a tad difficult. Take this hex value for a nice blue: #4169E1 – how would you make that blue just a little bit lighter? Tricky, eh? RGB colors like rgba(65, 105, 225) might be a little bit easier to understand and work with, but they remain unintuitive and non-conducive to our perception of color.
Hex and RGB colors use the standard red, green, blue (sRGB) color space, but as displays and technology have gotten more powerful, we've gained new color spaces and new ways to define colors in these spaces. We can display colors that weren't previously possible, with wider gamuts that take advantage of modern display technology.
Of particular note: lch(), lab(), oklch(), and oklab() are much more intuitive for humans to work with and function in a manner much more akin to how we understand and interact with color. This means that brand colors can be displayed more accurately on users’ displays and that more colors are possible.
The beauty of these modern color spaces lies in their intuitive nature. In OKLCH, for example, you can easily adjust only the lightness value to create a lighter or darker version of your brand color – something that would require extra logic in Sass or careful manual adjustment with hex values. Where you might have previously written complex Sass functions to lighten or darken colors, you can now simply modify a single value thanks to their intuitive nature.
I'll illustrate using variables, as that’s where I find the functionality most useful, but the same can be done with the straight color definition.
So when should you use these modern color spaces? They're particularly valuable when you need to create systematic color variations – tints, shades, and tones that maintain perceptual consistency. They're also essential when working with wide-gamut displays or when precise color matching is critical to your brand identity.
Of course, these are fairly new features, and browser support is a consideration as always (check the support for LCH, Lab, OKLCH, and Oklab). If in doubt, you can declare a safe base and then overwrite it within your newer alternative.
color: #4169e1;
color: oklch(0.5598 0.1882 266.4);Then, when the time comes and you phase out the requirement for those older versions, you can remove the hex definitions, leaving your newer setup.
We mix colors all the time, adding in a little bit more red for a warmer hue or the like. Thankfully, CSS now has this capability via color-mix(), which allows supplying two colors and getting an interpolated middle ground. This has obvious potential in defining tints or shades of a color that dynamically update when the root color is changed.
We could hard-code these color variations, but that makes changes in the future difficult, and it would be nearly impossible to do anything dynamic, such as when working with theming or considering altered display modes for accessibility cases.
Think of the applications in dynamic, themeable interfaces! You can combine variables with new color spaces to define dynamic variables based on base colors. For example, you might create a suite of semantic colors that automatically adjust based on your primary brand color:
:root {
--primary: oklch(60% 0.15 250);
--primary-light: color-mix(in oklch, var(--primary) 70%, white 30%);
--primary-dark: color-mix(in oklch, var(--primary) 80%, black 20%);
}This approach ensures that your entire color system remains cohesive even when brand colors change. It also opens up possibilities for user customization while maintaining design system integrity.
It’s increasingly common to offer both light and dark themes, which users don’t just expect, but are also necessary for user accessibility. Thankfully, it has gotten a lot easier to do this with CSS's wonderful light-dark().
With light-dark(), we provide two values – a light value and a dark one – and the best option is selected based on the user's OS/browser preference. We must first write color-scheme: light dark on the parent element – I like to apply this on :root. Then, to have black text in light mode, and white text in dark mode, we'd write this: light-dark(black, white);. It’s entirely intuitive to usual design practices and dynamic enough to be used in modular components across contexts.
There is one drawback to keep in mind: light-dark() only works with colors. You cannot provide it with any other values. While a common pattern might be to change the weight of text between themes for readability, light-dark() will not do anything in that case, and you'll need to use the prefers-color-scheme media query: @media (prefers-color-scheme).
Thankfully, it does accept color variables if we provide them, which allows us to work with the variables we discussed earlier.
On the same topic, it’s worth keeping an eye out for the upcoming contrast-color(),which will always return a color guaranteed to contrast in accordance with the Web Content Accessibility Guidelines (WCAG). Imagine the potential with user-generated content, where manually adjusting every case isn't feasible!
As lovely as all this is, there are cases where we can’t use it. Much of the CSS functionality we've discussed does have wide browser support, but it’s still modern enough that it might not meet your organizational requirements.
The key to implementing fallbacks successfully is to maintain adherence to your base design system and visual identity even when using older CSS features. In some cases this means carefully selecting equivalents that preserve the intent and accessibility of your modern CSS color choices. You might lose some of the dynamic capabilities, but your brand consistency and user experience should remain intact.
A progressive enhancement approach works well here: Start with solid, widely-supported color definitions and layer on the advanced features for browsers that support them. This ensures that your design system works everywhere while taking advantage of modern capabilities where available. Document these fallback strategies in your design system guidelines so that all team members understand when and how to implement them.
We've covered a lot here and barely scratched the surface, but hopefully you've gained a bit of an overview of what CSS can do in the color space (pun intended). If you're itching to learn more, here are some great resources worth a look:
Color Formats in CSS by Josh W Comeau
Color Everything in CSS by Juan Diego Rodríguez
CSS Variables – Why should you care? by Rob Dodson
Remember, we aren't trying to use every new CSS feature available; we're trying to leverage modern CSS to make our work easier. Don't let yourself be spun the other way around.
