Favorites

color() CSS Function

color()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The color() function defines a color in a named color space, such as color(display-p3 1 0 0), for colors beyond the sRGB range.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The color() CSS function lets you specify a color in a particular, named color space, rather than in the default sRGB space used by functions such as rgb() and hsl(). Its main purpose is to give access to wide-gamut color spaces such as display-p3 and rec2020, which can show more vivid colors than sRGB on modern screens. The result is a normal <color> value, so it can be used with any property that accepts a color, including color, background-color and border-color.

The first argument is the name of the color space. For the RGB-based spaces (srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb and rec2020) the next three values are the red, green and blue channels, written as numbers from 0 to 1 or as percentages. For the XYZ spaces (xyz, xyz-d50 and xyz-d65) the three values are the X, Y and Z coordinates. An optional alpha value can be added after a slash. If the screen cannot show the requested color, the browser maps it to the closest color it can display.

color() also supports relative color syntax with the from keyword, which converts an existing color into the chosen space so you can adjust individual channels.

/* A vivid red that sRGB cannot represent */
.badge {
  background-color: #ff0000; /* fallback */
  background-color: color(display-p3 1 0 0);
}

/* Semi-transparent color in sRGB */
.overlay {
  background-color: color(srgb 0 0 0 / 0.5);
}

/* Relative color: reduce the green channel of a brand color */
.accent {
  color: color(from var(--brand) srgb r calc(g * 0.5) b);
}

Because older browsers do not understand color(), it is good practice to declare an sRGB fallback first, or to wrap wide-gamut styles in @supports (color: color(display-p3 1 0 0)).

Interactive Demo

Colour swatch
Demo Code
HTML Code
<div class="demo-checker">
	<div class="demo-element">Colour swatch</div>
</div>
CSS Code
.demo-checker {
	width: 296px;
	padding: 18px;
	box-sizing: border-box;
	background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 20px 20px;
}
.demo-element {
	width: 260px;
	padding: 18px;
	border-radius: 8px;
	font-size: 16px;
	font-weight: bold;
	color: #fff;
	text-shadow: 0 1px 2px rgb(0 0 0 / 40%);
	background-color: color(srgb 0.97 0.15 0.52);
}

Syntax

color() = color( [ from <color> ]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )

<colorspace-params> = <predefined-rgb> [ <number> | <percentage> | none ]{3}
| <xyz-space> [ <number> | <percentage> | none ]{3}
<predefined-rgb> = srgb | srgb-linear | display-p3 | a98-rgb | prophoto-rgb | rec2020
<xyz-space> = xyz | xyz-d50 | xyz-d65

Values

  • colorspaceThe name of the color space: srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb, rec2020, xyz, xyz-d50 or xyz-d65.
  • c1 c2 c3The three channel values. For RGB spaces these are red, green and blue as a <number> from 0 to 1 or a <percentage>. For XYZ spaces they are the X, Y and Z coordinates. The keyword none can be used for a missing channel.
  • alphaOptional. An <alpha-value> after a slash (/) that sets the opacity, from 0 (transparent) to 1 (opaque).
  • from <color>Optional. Starts relative color syntax, converting the given color into the chosen color space so its channels can be referenced as r, g, b (or x, y, z) and alpha.

Example

<div class="wrap">
<h1>CSS color() examples</h1>
<div class="grid">
<div class="card">
<div class="sw srgb-red"></div>
<div class="label">color(srgb 1 0 0)</div>
</div>
<div class="card">
<div class="sw p3-red"></div>
<div class="label">color(display-p3 1 0 0)</div>
</div>
<div class="card">
<div class="sw p3-green"></div>
<div class="label">color(display-p3 0 1 0)</div>
</div>
<div class="card">
<div class="sw rec-blue"></div>
<div class="label">color(rec2020 0 0 1)</div>
</div>
<div class="card">
<div class="sw alpha"></div>
<div class="label">color(srgb 0.15 0.39 0.92 / 0.5)</div>
</div>
</div>
<p class="note">On a wide-gamut (P3) screen, the display-p3 swatches look more vivid than the sRGB red.</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* color() examples */
.sw {
height: 90px;
border-radius: 8px;
border: 1px solid rgba(16, 42, 67, 0.08);
}

.srgb-red { background: color(srgb 1 0 0); }
.p3-red { background: #ff0000; background: color(display-p3 1 0 0); }
.p3-green { background: #00ff00; background: color(display-p3 0 1 0); }
.rec-blue { background: #0000ff; background: color(rec2020 0 0 1); }
.alpha { background: color(srgb 0.15 0.39 0.92 / 0.5); }
Open in editor

Browser Support

The following information will show you the current browser support for the CSS color() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.