October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

Modern CSS Color Functions: How to Use Them

A practical guide to modern CSS color functions: choose a perceptual model, name a color space, mix colors, or derive variants from existing values.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Modern CSS color functions let you do more than write a color as a hex code: describe it in a perceptual model, specify a color space such as Display P3, mix colors in a chosen space, or derive a new color from an existing one. Choose the function for the job, check support for the exact syntax in your target browsers, and test the final foreground and background colors for contrast.

Choose a function by what you need to do

Goal Use Why
Express lightness, chroma, and hue in a form convenient for palette adjustments oklch() Its channels map clearly to those three dimensions.
Express a color using rectangular perceptual axes oklab() It uses lightness and two opponent axes rather than hue and chroma.
Name the color space for channel coordinates color() It supports spaces including sRGB and Display P3.
Interpolate between colors color-mix() You specify an interpolation space and the colors’ proportions.
Calculate a variant from a color already in your stylesheet Relative color syntax It lets you reuse, replace, or calculate output channels from an origin color.

These are different tools, not interchangeable spellings for every hex or RGB value. CSS Color Module Level 4 also includes hwb(), lab(), and lch(). Use them when their representation suits the color work at hand. The CSS Color Module Level 4 specification defines the color models and syntax.

As an Amazon Associate I earn from qualifying purchases.

Use perceptual color notation for palette adjustments

Choose between oklch() and oklab()

oklch() describes a color with lightness, chroma, and hue. That makes it convenient when you want to reason about one dimension at a time: adjust lightness, reduce chroma, or shift hue while leaving the other channels recognizable in the notation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
:root {
  --brand: oklch(62% 0.18 250);
}

oklab() instead uses lightness and two opponent axes. It can be a better fit when you want a rectangular coordinate representation rather than cylindrical lightness/chroma/hue.

The CIE-based lab() and lch() functions offer corresponding rectangular and cylindrical representations in the Lab models. Whichever notation you choose, changing a lightness channel does not guarantee accessible text contrast. Check the actual foreground and background pair in the finished interface.

Specify a color space with color()

Use color() when you want to state explicitly which space the channel coordinates belong to, rather than rely on the implicit sRGB interpretation used by many common CSS color notations.

.accent {
  color: color(display-p3 1 0.5 0);
}

The specification includes sRGB, linear-light sRGB, Display P3, linear-light Display P3, A98 RGB, ProPhoto RGB, BT.2020, and CIE XYZ spaces. The selected space and the display’s capabilities affect the rendered result. A wider-gamut value is not a guarantee that every display can show the full color. MDN describes the color-gamut media feature as a way to detect gamut support; consult its reference for color() and test the target devices.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Mix colors with color-mix()

The general form is color-mix(in <space>, <color> <percentage>, <color> <percentage>). It mixes colors using the chosen interpolation space and proportions.

:root {
  --brand: oklch(62% 0.18 250);
  --brand-soft: color-mix(in oklch, var(--brand) 25%, white);
}

This creates a color by mixing 25% of --brand with white in Oklch. The result depends on both the ratio and interpolation space; in polar spaces, the hue interpolation direction also affects the path.

Choose the interpolation space for the effect

  • Oklab, Lab: useful when you want perceptually even spacing between colors.
  • Oklch, LCH: can help avoid a gray-looking midpoint by maintaining chroma.
  • CIE XYZ or srgb-linear: appropriate when simulating physically mixed light intensities.

These are choices about interpolation behavior, not guarantees that one space will look best in every design. MDN documents Oklab as the default when no interpolation method is supplied. For polar spaces such as Oklch, shorter-hue interpolation is the default. If the percentages do not total 100%, CSS normalizes them; if their sum is below 100%, the result also receives an alpha multiplier corresponding to that sum. See MDN’s color-mix() reference for syntax and details.

Derive a color with relative color syntax

Relative color syntax starts with a color function, the keyword from, an origin color, and output channel values. The origin can be any valid color, including a custom property, currentColor, a system color, or another relative color. In the output, you can copy an origin channel, replace it, or use math to change it. If you omit alpha, the result inherits the origin’s alpha.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
:root {
  --brand: oklch(62% 0.18 250);
  --brand-muted: oklch(from var(--brand) l calc(c * 0.65) h);
}

Here, the new color keeps the source lightness and hue while reducing its chroma to 65% of the source value. The supported relative-color function family includes color(), hsl(), hwb(), lab(), lch(), oklab(), oklch(), and rgb(). For the syntax and channel rules, consult MDN’s guide to using relative colors.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check browser support for the exact feature

Support is feature-specific: support for a color function does not automatically establish support for every color space, interpolation option, or relative syntax form. MDN labels color-mix() Baseline Widely available and says it has been available across browsers since May 2023, while noting that some parts may vary. The references here do not provide a complete current browser/version matrix for every Level 4 function and subfeature.

  1. Identify the browsers and versions your project must support.
  2. Check the compatibility data for the exact function and syntax you plan to ship, including the chosen interpolation space or relative-color form.
  3. Test rendered colors in those browsers and on representative displays, especially when using a wide-gamut space.
  4. Provide a fallback where your support requirements call for one, then verify that the fallback and modern declaration produce acceptable results.

For the color type and function family, use MDN’s reference for the <color> type alongside the specific function pages.

Check accessibility on the resulting colors

The CSS Color Module Level 4 specification says: “Authors should consider the Web Content Accessibility Guidelines (WCAG21) when using color in their documents.” A color’s syntax or model does not establish its accessibility. Evaluate the final foreground/background combinations and interface states, and do not rely on color alone to communicate essential information.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common problems

  • A declaration is ignored: Check the exact function and syntax against the target browsers. Confirm that values and separators match the function’s grammar, and use a fallback if required.
  • A mixed color looks different than expected: Check the interpolation space, the percentages, and—if using a polar space—the hue interpolation path. Different spaces can produce different intermediate colors.
  • A Display P3 color looks muted or differs by device: The color space and display gamut affect the result. Verify support and inspect it on the displays relevant to your users.
  • A derived color is not changing as intended: Check the origin after from, the channel names, and the math. In the example above, only chroma changes; lightness and hue are copied.
  • Text still fails a contrast check after adjusting lightness: Test the final text and background together. A lightness adjustment to one color alone does not determine pairwise contrast.

Or skip the browser setup

If you need rendered page screenshots while checking a design, ScreenshotNeo is a website screenshot API and MCP server for developers. A single GET request can return a screenshot or PDF; its clean-shot options accept consent banners like a visitor and remove 60+ known consent platforms, newsletter popups, and chat widgets before capture, with each step configurable. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; response headers report the page verdict and billing status.

Example cURL request, using the documented API parameters:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for setup and options. ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.