Menu

CSS light-dark() & Relative Color Generator

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.


        

Live preview

Acme

Project settings

Muted description text sits on the raised surface. Hover the buttons to see the hover and active tokens.

Subtle brand background with a matching border.

Tokens

Contrast checks (WCAG 2, 4.5:1)

✓ Copied!
MODERN CSS COLOR WORKFLOW

CSS light-dark() & Relative Color Syntax Generator

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.

light-dark() from OKLCH RGB HSL CSS Color 5
CSS COLOR LAB 01
.theme {
color:
light-dark(
var(--light),
var(--dark)
);
}
CSS
QUICK ANSWER

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.

01
MODERN CSS

What Is a CSS light-dark() & Relative Color Syntax Generator?

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.

02
COLOR SCHEME

What Does CSS light-dark() Do?

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.

LIGHT MODE #111827 Text / foreground
→
DARK MODE #F8FAFC Text / foreground
CSS
: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.

03
COLOR DERIVATION

What Is Relative Color Syntax?

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.

ORIGIN oklch(65% 0.18 250)
→
DERIVED oklch(from var(--brand) calc(l + 10%) c h)

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.

CSS COLOR GENERATOR

Generate Modern CSS Color Syntax

READY
01
Base Color Source color
02
light-dark() Theme-aware color
light-dark(#111827, #F8FAFC)
03
Relative Color Modify channels
Adjustment +10%
Chroma 0
oklch(from #635BFF calc(l + 10%) c h)
GENERATED CSS Ready to copy
:root {
  color-scheme: light dark;
}

.element {
  color: light-dark(#111827, #F8FAFC);
  background:
    oklch(from #635BFF calc(l + 10%) c h);
}
04
WHY USE IT

Why Use Relative Color Syntax?

01

Less Hard-Coded Color Data

Derive related colors from a source color instead of manually storing every variation.

02

Theme-Friendly

Build color relationships that can work naturally with modern light and dark interfaces.

03

Design-System Ready

Create systematic hover, active, muted and emphasis variations from shared color tokens.

04

Modern Color Spaces

Work with perceptual color models such as OKLab and OKLCH instead of relying only on legacy color formats.

05
THEMING

light-dark() vs prefers-color-scheme

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.

TRADITIONAL THEME RULE
.button {
  color: #111827;
}

@media (prefers-color-scheme: dark) {
  .button {
    color: #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.

06
COLOR CHANNELS

Understanding Relative Color Channels

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.

L Lightness

Controls the lightness dimension in OKLab and OKLCH workflows.

C Chroma

Controls colorfulness in OKLCH and related cylindrical spaces.

H Hue

Represents the hue angle in cylindrical color spaces.

R RGB Channel

RGB-relative syntax can derive colors by modifying red, green or blue channels.

07
PERCEPTUAL COLOR

Using Relative Colors with OKLCH

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.

SOURCE TOKEN --brand: #635BFF;
.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 .

08
REAL-WORLD APPLICATIONS

Where This CSS Generator Is Useful

01

Dark Mode

Define light and dark alternatives for text, borders, backgrounds and UI controls.

02

Design Systems

Generate related component colors from a smaller collection of source tokens.

03

Hover States

Derive hover colors by changing lightness or other color dimensions from the base color.

04

Theme Tokens

Combine CSS custom properties with relative color syntax to create flexible theme architectures.

05

Component Libraries

Create systematic variations for buttons, cards, navigation and interactive components.

06

Frontend Development

Generate modern CSS values without manually calculating every derived color.

09
WORKFLOW

How to Use the CSS Color Syntax Generator

01

Enter a source color

Enter a HEX, RGB, HSL, OKLCH or another supported CSS color as your starting value.

02

Create a light-dark() value

Enter the light and dark alternatives that should be selected according to the active color scheme.

03

Select a relative color space

Choose a destination color space such as OKLCH, OKLab, HSL or RGB for your relative color declaration.

04

Modify color channels

Adjust lightness, chroma or other relevant channels to create a derived color relationship.

05

Copy the CSS

Copy the generated CSS declaration and add it to your stylesheet or design-system token workflow.

10
DEVELOPER GUIDANCE

Best Practices for Modern CSS Colors

Use semantic tokens

Store important brand and interface colors in custom properties instead of scattering raw values throughout the stylesheet.

Prefer relationships where useful

Relative colors can make related states easier to maintain when the source color changes.

Test browser support

Check the browsers and environments supported by your project before depending on newer CSS color functionality.

Check accessibility

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.

11
TECHNICAL REFERENCES

CSS Color Documentation

13
COMMON QUESTIONS

CSS light-dark() & Relative Color Syntax FAQ

What is the CSS light-dark() function?

CSS light-dark() is a color function that provides two color alternatives and selects the appropriate one according to the active color scheme.

What is relative color syntax in CSS?

Relative color syntax allows a new color to be derived from an existing origin color using the from keyword and color channels.

How does light-dark() work?

light-dark() receives a light color and a dark color. The browser chooses the appropriate color according to the element's effective color scheme.

Do I need color-scheme to use light-dark()?

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.

What does the from keyword mean in relative colors?

The from keyword identifies the origin color from which the new relative color is derived.

Can relative color syntax use OKLCH?

Yes. Relative color syntax can be used with OKLCH, allowing developers to reference and modify lightness, chroma and hue channels.

Can relative colors be used with CSS variables?

Yes. CSS custom properties can provide the origin color for a relative color declaration, making the technique useful for reusable design tokens.

Is light-dark() better than prefers-color-scheme?

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.

Can relative color syntax create hover colors?

Yes. A relative color can derive a hover color from a base color by modifying channels such as lightness or chroma.

Can I use relative colors in a design system?

Yes. Relative colors can work with custom properties and semantic tokens to create systematic variations for components and themes.

Are light-dark() and relative color syntax supported in all browsers?

Support depends on the browser version and the specific CSS color feature being used. Always check current browser compatibility requirements for production projects.

Is this CSS color syntax generator free?

Yes. The BestColorPicker CSS light-dark() and Relative Color Syntax Generator is designed as a free online developer tool.

MODERN CSS COLOR WORKFLOW

Build Smarter Theme-Aware Colors with Modern CSS

Generate light-dark() values, relative color expressions and modern CSS color relationships for your next frontend project.

Generate CSS