CSS Academy · Lesson

color-mix() and relative color syntax

Blend colors together and create color variations using modern CSS color functions.

Lesson 4 of 412 steps

color-mix() and relative color syntax is a free CSS Academy lesson on CoddyKit. This is lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.

color-mix() Function

color-mix() blends two colors together in a specified color space. It enables design token–driven color variations without Sass or JavaScript.

  <button class="button-hover">Hover-mixed button</button>

color-mix() Syntax

Full syntax: color-mix(in <color-space>, <color-1> [percentage], <color-2> [percentage]). Percentages must sum to 100%.

  <div class="mix-equal">Equal mix</div>
  <div class="mix-weighted">Weighted mix</div>

Color Spaces in color-mix()

The color space affects the blending result. Modern perceptual spaces like oklch produce more visually uniform results than srgb:

  <div class="oklch-mix">OKLCH mix</div>
  <div class="srgb-mix">sRGB mix</div>

Generating Color Scales with color-mix()

Create a consistent color palette from a single brand color:

  <span class="swatch swatch-100"></span>
  <span class="swatch swatch-300"></span>
  <span class="swatch swatch-700"></span>
  <span class="swatch swatch-900"></span>

Relative Color Syntax

Relative colors let you derive a new color from an existing color by modifying specific channels. Use from keyword:

  <p class="darker">20% darker text</p>
  <p class="desaturated">Half saturation text</p>

Transparent Variant with Relative Color

Create a transparent version of a brand color without knowing its RGB values:

  <div class="overlay">Overlay</div>

Lightening and Darkening

Add or subtract lightness in oklch to create tints and shades:

  <div class="card demo-active">Card</div>

oklch Color Space Overview

OKLCH is a perceptually uniform color space:

  • l — lightness (0 to 1)
  • c — chroma/saturation (0 to 0.4+)
  • h — hue angle (0 to 360)

Adjusting l gives predictably uniform tints/shades.

Browser Support

color-mix() is supported in Chrome 111+, Firefox 113+, Safari 16.2+. Relative color syntax (from keyword) is in Chrome 119+, Safari 16.4+, Firefox 128+. Check caniuse.com for current support.

color-contrast() Future

color-contrast() is a proposed function that automatically picks the most readable color (from a list) against a given background. Not yet in browsers but designed for accessibility-driven theming.

Quick Check

Which color-mix() color space produces the most perceptually uniform blending results?

Recap

color-mix(in oklch, color1 %, color2 %) blends colors in a specified space — ideal for tints, shades, and transparent variants from a single brand color. Relative color syntax (oklch(from var(--brand) calc(l+0.2) c h)) derives new colors by modifying individual channels. OKLCH is the best color space for perceptually uniform results.

Free to start

Learn CSS with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
40
Lessons
159

Frequently Asked Questions

Is the “color-mix() and relative color syntax” lesson free?

Yes — the full text of “color-mix() and relative color syntax” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.

What will I learn in “color-mix() and relative color syntax”?

Blend colors together and create color variations using modern CSS color functions. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CSS Academy?

No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “color-mix() and relative color syntax” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CSS Academy lesson?

Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. calc() for Dynamic Calculations
  2. min() max() and clamp() for Fluid Values
  3. repeat() and minmax() in Grid
  4. color-mix() and relative color syntax
← Back to CSS Academy