Color scheme

Relative Color Syntax

You already know how to derive tints and shades from a seed color using color-mix(). That approach works well, but it always blends two colors together. What if you want to take one color and surgically adjust a single channel, like bumping the lightness up by 20% or shifting the hue 30 degrees without touching anything else? That is exactly what relative color syntax does. It lets you decompose any color into its individual channels, modify whichever ones you want with calc(), and produce a new color in a single declaration. The result is a palette system that is more expressive and more readable than stacking color-mix() calls.

The from Keyword

Relative color syntax works by adding the from keyword inside any CSS color function. After from, you provide an origin color. The browser converts that color into the target color space and exposes its individual channels as variables you can use or modify. Here is the general pattern in oklch():


        oklch(from var(--seed) l c h)
    

This produces the exact same color as var(--seed), just expressed in oklch(). On its own that is not useful, but it becomes powerful once you start replacing or calculating new values for l, c, or h. The browser resolves the origin color into three channel variables:

  • l — Lightness, a number between 0 and 1 (where 0 is black and 1 is white)
  • c — Chroma, a number typically between 0 and 0.4 (where 0 is fully gray and higher values are more vivid)
  • h — Hue, an angle between 0 and 360 on the color wheel

You can also access the alpha channel with alpha if you need to adjust transparency. Any channel you do not modify is carried through unchanged from the origin color.

Any Color Space Works

The from keyword works inside rgb(), hsl(), lab(), lch(), oklab(), and oklch(). The origin color can be in any format and the browser will convert it automatically. Throughout this page we use oklch() because its lightness channel is perceptually uniform, which means equal numeric adjustments produce equal visual changes across different hues.

Adjusting Channels

The real power comes from wrapping channel variables in calc(). You can lighten, darken, desaturate, shift hue, or adjust opacity, all relative to the original value. The key distinction is between adjusting by a relative amount versus setting to an absolute value.

Lighten and Darken

To lighten a color by a percentage of its current lightness, multiply l. To darken, use a multiplier below 1. You can also add or subtract a fixed amount:


        /* Lighten by 25% of the current lightness */
        --lighter: oklch(from var(--seed) calc(l * 1.25) c h);

        /* Darken by 15% of the current lightness */
        --darker: oklch(from var(--seed) calc(l * 0.85) c h);

        /* Add a fixed amount to lightness */
        --bumped: oklch(from var(--seed) calc(l + 0.1) c h);

        /* Set lightness to an absolute value (ignores original) */
        --forced-light: oklch(from var(--seed) 0.9 c h);
    

Multiplication is generally the better choice for palette work because it scales proportionally. A 25% bump on a dark seed produces a smaller absolute shift than the same bump on a mid-tone seed, keeping the palette visually balanced.

Desaturate and Boost

Chroma controls how vivid a color looks. Reducing it moves the color toward gray, and increasing it makes the color more saturated. Setting chroma to 0 produces a perfect grayscale version of the original:


        /* Desaturate by half */
        --muted: oklch(from var(--seed) l calc(c * 0.5) h);

        /* Fully desaturate (grayscale) */
        --gray: oklch(from var(--seed) l 0 h);

        /* Boost chroma by 50% */
        --vivid: oklch(from var(--seed) l calc(c * 1.5) h);
    

Shift Hue

Rotating the hue creates complementary, analogous, or triadic color relationships from a single base. Because hue is an angle, adding 180 gives you the complementary color, and adding or subtracting 30 to 60 gives you analogous neighbors:


        /* Complementary (opposite side of the wheel) */
        --complement: oklch(from var(--seed) l c calc(h + 180));

        /* Analogous neighbor */
        --neighbor: oklch(from var(--seed) l c calc(h - 30));

        /* Triadic (three colors evenly spaced) */
        --triad-a: oklch(from var(--seed) l c calc(h + 120));
        --triad-b: oklch(from var(--seed) l c calc(h - 120));
    

Adjust Opacity

The alpha channel is available as alpha. This is useful for creating semi-transparent overlays, borders, or shadows from an existing color without needing to know or repeat the color value:


        /* 20% opacity version for a subtle border */
        --border-tint: oklch(from var(--seed) l c h / 0.2);

        /* 40% opacity for a shadow */
        --shadow: oklch(from var(--seed) l c h / 0.4);
    

Building a Palette from One Seed

On the Modern Color Functions page you built a palette ramp by mixing your seed with white and black at different percentages using color-mix(). Relative color syntax lets you achieve the same result by adjusting lightness directly. Compare the two approaches side by side:


        /* color-mix() approach */
        --accent-200: color-mix(in oklch, var(--seed) 30%, white);
        --accent-500: var(--seed);
        --accent-800: color-mix(in oklch, var(--seed) 40%, black);

        /* Relative color syntax approach */
        --accent-200: oklch(from var(--seed) calc(l + 0.3) c h);
        --accent-500: var(--seed);
        --accent-800: oklch(from var(--seed) calc(l - 0.25) c h);
    

The color-mix() version blends two complete colors together, which shifts chroma and can subtly alter the hue. The relative color version adjusts only lightness, leaving chroma and hue perfectly intact. Neither approach is universally better. color-mix() is simpler and more predictable when you want a straightforward tint or shade. Relative color syntax gives you finer control when you need to keep the character of the original hue across the entire ramp.

Here is a full seven-step ramp using relative color syntax. Each step adjusts lightness by a fixed increment from the seed:


        :root {
            --seed: oklch(0.55 0.2 260);

            --accent-100: oklch(from var(--seed) calc(l + 0.35) calc(c * 0.3) h);
            --accent-200: oklch(from var(--seed) calc(l + 0.25) calc(c * 0.5) h);
            --accent-300: oklch(from var(--seed) calc(l + 0.15) calc(c * 0.8) h);
            --accent-400: oklch(from var(--seed) calc(l + 0.05) c h);
            --accent-500: var(--seed);
            --accent-600: oklch(from var(--seed) calc(l - 0.08) c h);
            --accent-700: oklch(from var(--seed) calc(l - 0.18) c h);
            --accent-800: oklch(from var(--seed) calc(l - 0.28) calc(c * 0.8) h);
            --accent-900: oklch(from var(--seed) calc(l - 0.35) calc(c * 0.5) h);
        }
    

Notice how the lightest steps also reduce chroma. This prevents pastel tints from looking artificially neon, which can happen when you push lightness high while keeping full chroma. The darkest steps do the same in reverse, tapering chroma so the deepest shades settle into a rich near-black instead of a muddy dark color.

Practical Patterns

Beyond palette ramps, relative color syntax is especially useful for component-level color adjustments. These patterns come up constantly in real UI work.

Hover and Active States

Instead of maintaining separate hex values for every interactive state, derive them from the base:


        .button {
            --btn-bg: var(--accent-500);
            background-color: var(--btn-bg);
        }

        .button:hover {
            background-color: oklch(from var(--btn-bg) calc(l - 0.07) c h);
        }

        .button:active {
            background-color: oklch(from var(--btn-bg) calc(l - 0.12) c h);
        }
    

Change --accent-500 to any color and the hover and active states update automatically. The relationship is preserved regardless of the base value.

Disabled States

A common pattern for disabled controls is to strip chroma and lighten. Relative color syntax makes this a single declaration:


        .button[disabled] {
            background-color: oklch(from var(--btn-bg) calc(l + 0.2) 0 h);
            cursor: not-allowed;
        }
    

Setting chroma to 0 produces a grayscale version while keeping the lightness relationship intact. The button looks clearly disabled without needing a separate --gray-300 token.

Transparent Borders and Shadows

Rather than hardcoding shadow and border colors, derive them from whatever accent or surface color is already in use:


        .card {
            border: 1px solid oklch(from var(--accent-500) l c h / 0.15);
            box-shadow: 0 4px 12px oklch(from var(--accent-500) calc(l - 0.2) c h / 0.2);
        }
    

Live Demo

This demo generates a palette ramp from a single seed color using relative color syntax. Adjust the hue slider to see how every swatch updates from one declaration. Use the theme toggle to see how the demo responds in both light and dark mode:

260°
Color scheme
100
200
300
400
500
600
700
800
900

Relative Color Syntax vs. color-mix()

Both tools derive new colors from existing ones, but they solve different problems. color-mix() blends two colors in a given color space. It is ideal when you want to tint toward white, shade toward black, or blend two brand colors together. Relative color syntax decomposes one color and recalculates individual channels. It is ideal when you want to adjust a specific property (lightness, chroma, hue, or opacity) without side effects on the others.

In practice, many teams use both. color-mix() handles the broad strokes (tints, shades, overlay blending), while relative color syntax handles the precise adjustments (hover state shifts, disabled desaturation, complementary hue calculations). Understanding when to reach for each tool is an important part of building a flexible color system.

Resources

Teaching Video Checklist

When you record your teaching video, make sure your teammates come away understanding these concepts:

  • What the from keyword does inside a color function and how it decomposes an origin color into channel variables
  • How to use calc() on individual channels to lighten, darken, desaturate, and shift hue
  • The difference between adjusting a channel by a relative amount (multiplication) versus setting it to an absolute value
  • How to build a multi-step palette ramp from a single seed using relative color syntax in oklch()
  • When you would choose relative color syntax over color-mix() and when color-mix() is the better tool

Show a live demo in your video. Start with a single custom property as your seed, derive at least five palette steps using the from keyword, and then change the seed value so your teammates can see the entire palette update in real time.