Less Hard-Coded Color Data
Derive related colors from a source color instead of manually storing every variation.
Give it one brand color and get a complete light and dark theme as CSS variables, built with light-dark() and relative color syntax, plus fallbacks for older browsers.
Support badges show what your browser can run. The preview below always uses computed values, so it works everywhere.
Muted description text sits on the raised surface. Hover the buttons to see the hover and active tokens.
Tokens
Contrast checks (WCAG 2, 4.5:1)
Generate modern CSS color declarations using
light-dark() and relative color syntax. Create
adaptive light and dark theme colors, derive new colors from
existing values, adjust channels, and build flexible CSS color
systems without manually calculating every shade.
The CSS light-dark() & Relative Color Syntax Generator
helps create modern CSS color values that can adapt to light and dark
color schemes and derive new colors from an existing color. The
light-dark() function selects between two colors based
on the active color scheme, while relative color syntax uses
from to modify or inspect channels of an existing color.
CSS has evolved beyond fixed HEX values and traditional RGB or HSL declarations. Modern CSS color features allow developers to describe relationships between colors and create styles that respond to the user's color scheme.
The light-dark() function is designed for situations where
a stylesheet needs one color in a light scheme and another color in a
dark scheme. Instead of writing the same property in separate media
queries, you can express both alternatives directly in the color value.
Relative color syntax provides another powerful approach. It lets you
start with an existing color using the from keyword and
derive another color by modifying its channels. This is particularly
useful for design systems, themes, component states and generated
color variations.
This generator brings both concepts together so developers can explore modern CSS color relationships and generate ready-to-use declarations.
The CSS light-dark() function accepts two color values:
one intended for light color schemes and another intended for dark
color schemes. The browser selects the appropriate value according to
the element's effective color scheme.
:root {
color-scheme: light dark;
}
body {
color: light-dark(#111827, #F8FAFC);
}
This approach can make theme-aware CSS more compact because the two
color alternatives can live inside the same declaration. The
color-scheme property or inherited color-scheme context
determines which side is selected.
Relative color syntax allows a CSS color to be derived from another
color. The syntax starts with the word from, followed by
the origin color and then channel values that can be preserved,
modified or calculated.
The exact syntax depends on the destination color space. Relative colors can be expressed using formats such as RGB, HSL, HWB, Lab, LCH, OKLab and OKLCH. This makes it possible to create systematic variations without hard-coding every resulting color.
:root {
color-scheme: light dark;
}
.element {
color: light-dark(#111827, #F8FAFC);
background:
oklch(from #635BFF calc(l + 10%) c h);
}
Derive related colors from a source color instead of manually storing every variation.
Build color relationships that can work naturally with modern light and dark interfaces.
Create systematic hover, active, muted and emphasis variations from shared color tokens.
Work with perceptual color models such as OKLab and OKLCH instead of relying only on legacy color formats.
Both approaches can be used to build light and dark themes, but they
operate at different levels. prefers-color-scheme is a
media feature that allows CSS rules to respond to the user's preferred
color scheme. light-dark() provides two color values
inside a color declaration.
.button {
color: #111827;
}
@media (prefers-color-scheme: dark) {
.button {
color: #F8FAFC;
}
}
:root {
color-scheme: light dark;
}
.button {
color:
light-dark(
#111827,
#F8FAFC
);
}
The best approach depends on the design system. Complex theme changes
may still benefit from media queries or custom properties, while
light-dark() can be especially convenient for individual
color declarations.
Relative color syntax exposes the channels of the origin color in the destination color space. Depending on the syntax, developers can reuse a channel, modify it with calculations or replace it with another value.
Controls the lightness dimension in OKLab and OKLCH workflows.
Controls colorfulness in OKLCH and related cylindrical spaces.
Represents the hue angle in cylindrical color spaces.
RGB-relative syntax can derive colors by modifying red, green or blue channels.
OKLCH is especially useful for systematic color manipulation because it represents color using lightness, chroma and hue. This makes it convenient to express relationships such as "make this color lighter" or "reduce its chroma" in a readable way.
.button:hover {
background:
oklch(
from var(--brand)
calc(l + 8%)
c
h
);
}
Relative OKLCH syntax can be useful for hover states, focus states, subtle backgrounds and component variations. The actual resulting color depends on the origin color and the selected channel calculations.
If you work extensively with OKLCH, you can also use the OKLCH Color Picker, HEX to OKLCH Converter and OKLCH Gradient Generator .
Define light and dark alternatives for text, borders, backgrounds and UI controls.
Generate related component colors from a smaller collection of source tokens.
Derive hover colors by changing lightness or other color dimensions from the base color.
Combine CSS custom properties with relative color syntax to create flexible theme architectures.
Create systematic variations for buttons, cards, navigation and interactive components.
Generate modern CSS values without manually calculating every derived color.
Enter a HEX, RGB, HSL, OKLCH or another supported CSS color as your starting value.
Enter the light and dark alternatives that should be selected according to the active color scheme.
Choose a destination color space such as OKLCH, OKLab, HSL or RGB for your relative color declaration.
Adjust lightness, chroma or other relevant channels to create a derived color relationship.
Copy the generated CSS declaration and add it to your stylesheet or design-system token workflow.
Store important brand and interface colors in custom properties instead of scattering raw values throughout the stylesheet.
Relative colors can make related states easier to maintain when the source color changes.
Check the browsers and environments supported by your project before depending on newer CSS color functionality.
A mathematically valid derived color is not automatically an accessible color. Test important foreground and background pairs.
For contrast testing, use the Color Contrast Checker and APCA Contrast Checker.
CSS light-dark() is a color function that provides two color alternatives and selects the appropriate one according to the active color scheme.
Relative color syntax allows a new color to be derived from an existing origin color using the from keyword and color channels.
light-dark() receives a light color and a dark color. The browser chooses the appropriate color according to the element's effective color scheme.
light-dark() relies on the effective color scheme of the element. Setting an appropriate color-scheme context is therefore important when using the function for light and dark alternatives.
The from keyword identifies the origin color from which the new relative color is derived.
Yes. Relative color syntax can be used with OKLCH, allowing developers to reference and modify lightness, chroma and hue channels.
Yes. CSS custom properties can provide the origin color for a relative color declaration, making the technique useful for reusable design tokens.
Neither is universally better. prefers-color-scheme responds to a color-scheme media condition, while light-dark() provides light and dark alternatives directly inside a color value.
Yes. A relative color can derive a hover color from a base color by modifying channels such as lightness or chroma.
Yes. Relative colors can work with custom properties and semantic tokens to create systematic variations for components and themes.
Support depends on the browser version and the specific CSS color feature being used. Always check current browser compatibility requirements for production projects.
Yes. The BestColorPicker CSS light-dark() and Relative Color Syntax Generator is designed as a free online developer tool.
Generate light-dark() values, relative color expressions and modern CSS color relationships for your next frontend project.