Favorites

CSS <color> Data Type

<color>
CSS Data TypeThis data type is supported by all modern browsers.
Updated 21st November 2026

The <color> data type is a color value, written as a named color, a hex code, or a function such as rgb(), hsl(), oklch() or color-mix().

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 data type represents a color value that can be applied to various visual aspects of elements, such as text, borders, backgrounds, and shadows. It is one of the most commonly used data types in CSS because it defines how elements appear visually and how they interact with other content on a page. Colors can be expressed in multiple ways, including named colors like red or blue, hexadecimal values such as #ff0000, functional notations like rgb(), rgba(), hsl(), and hsla(), and even modern formats like lab() or lch(). Using the <color> data type effectively allows designers and developers to convey visual hierarchy, emphasis, and thematic consistency throughout a web page.

One key aspect of the <color> data type is its flexibility in combining with opacity and transparency. For instance, the rgba() and hsla() notations allow you to set an alpha channel to make a color partially transparent, which can be useful when layering elements or creating overlays. Many CSS properties accept <color> values, including color, background-color, border-color, and box-shadow. This makes it a versatile type for both text styling and box model effects.

The <color> data type also interacts with other CSS data types, such as <length> in gradients and shadows. Gradients, for example, can transition smoothly between multiple <color> values, enabling visually appealing backgrounds without using images. Additionally, the <color> type is integral in dynamic styling, including CSS variables and animations, allowing developers to create responsive designs that adapt to user interaction or theme changes.

Examples:

/* Named color */
p {
  color: red;
}

/* Hexadecimal color */
h1 {
  color: #1e90ff;
}

/* RGB with transparency */
div {
  background-color: rgba(255, 0, 0, 0.5);
}

/* HSL color */
span {
  color: hsl(120, 100%, 50%);
}

/* Gradient using multiple colors */
header {
  background: linear-gradient(to right, red, blue, yellow);
}

This data type forms the backbone of CSS styling for visual elements, providing precise control over how elements appear and interact with other parts of a web page.

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: tomato;
}

Syntax

<color> = <color-base> | currentcolor | <system-color> | <light-dark()>
where
<color-base> = <hex-color> | <named-color> | transparent
             | <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()>
             | <lab()> | <lch()> | <oklab()> | <oklch()>
             | <color()> | <color-mix()> | <device-cmyk()>

Values

  • <hex-color>A hexadecimal color with 3, 4, 6 or 8 digits: #RGB, #RGBA, #RRGGBB or #RRGGBBAA, where A is the alpha (opacity) channel.
  • <named-color>One of the predefined color keywords such as red, rebeccapurple or cornflowerblue. Click CSS Color Names to view the range of named colors.
  • currentcolorThe value of the color property for the current element. This lets other properties, such as border-color or fill, reuse the text color.
  • transparentA fully transparent color, the same as rgb(0 0 0 / 0).
  • <rgb()> | <rgba()>Red, green and blue channels as numbers from 0 to 255 or percentages, with an optional alpha value. rgba() is an alias of rgb().
  • <hsl()> | <hsla()>Hue, saturation and lightness, with an optional alpha value. hsla() is an alias of hsl().
  • <hwb()>Hue, whiteness and blackness, with an optional alpha value.
  • <lab()> | <lch()>Colors in the CIE Lab color space, given as lightness with a and b axes (lab) or lightness, chroma and hue (lch). They can describe colors beyond sRGB.
  • <oklab()> | <oklch()>Colors in the perceptually uniform Oklab color space, which gives more even lightness and hue than Lab. Well suited to building palettes.
  • <color()>A color in a named color space, such as srgb, display-p3, rec2020 or xyz, for example color(display-p3 1 0 0).
  • <color-mix()>Mixes two colors in a chosen color space, for example color-mix(in oklab, blue 70%, white).
  • <light-dark()>Returns the first color in a light color scheme and the second in a dark color scheme.
  • <system-color>A keyword for a color chosen by the operating system or browser, such as Canvas, CanvasText or ButtonFace. Important for forced colors (high contrast) modes.
  • <device-cmyk()>A print color given as cyan, magenta, yellow and black ink amounts. Not supported by browsers.

Example

<div class='palette'>
<h1>CSS &lt;color&gt; data type - examples</h1>
<div class='swatches'>
<div class='swatch named'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>Named color</div>
<div class='value'>red</div>
</div>
</div>

<div class='swatch hex6'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>Hex (6-digit)</div>
<div class='value'>#ff0000</div>
</div>
</div>

<div class='swatch hex3'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>Hex (3-digit)</div>
<div class='value'>#f00</div>
</div>
</div>

<div class='swatch rgb'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>rgb()</div>
<div class='value'>rgb(255, 0, 0)</div>
</div>
</div>

<div class='swatch rgb-space-alpha'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>rgb() with space-separated and alpha</div>
<div class='value'>rgb(255 0 0 / 0.5)</div>
</div>
</div>

<div class='swatch rgba'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>rgba()</div>
<div class='value'>rgba(255, 0, 0, 0.75)</div>
</div>
</div>

<div class='swatch hsl'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>hsl()</div>
<div class='value'>hsl(0 100% 50%)</div>
</div>
</div>

<div class='swatch hsla'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>hsl() with alpha</div>
<div class='value'>hsl(0 100% 50% / 0.6)</div>
</div>
</div>

<div class='swatch hwb'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>hwb()</div>
<div class='value'>hwb(0deg 0% 0%)</div>
</div>
</div>

<div class='swatch srgb'>
<div class='chip' aria-hidden='true'></div>
<div class='meta'>
<div class='label'>color() with sRGB</div>
<div class='value'>color(srgb 1 0 0 / 0.8)</div>
</div>
</div>
</div>
</div>
/* Styles for color examples */
:root {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  color-scheme: light;
}

.palette {
  max-width: 900px;
  margin: 32px auto;
  padding: 16px;
}

.palette h1 {
  font-size: 18px;
  margin: 0 0 16px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.swatch {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  background: #fff;
}

.chip {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06) inset, 0 1px 4px rgba(0,0,0,0.06);
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.label {
  font-size: 13px;
  color: #333;
}

.value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, 'Roboto Mono', monospace;
  font-size: 12px;
  color: #555;
}

/* Color examples using different  syntaxes */
.swatch.named .chip { background: red; }
.swatch.hex6 .chip { background: #ff0000; }
.swatch.hex3 .chip { background: #f00; }
.swatch.rgb .chip { background: rgb(255, 0, 0); }
.swatch.rgb-space-alpha .chip { background: rgb(255 0 0 / 0.5); }
.swatch.rgba .chip { background: rgba(255, 0, 0, 0.75); }
.swatch.hsl .chip { background: hsl(0 100% 50%); }
.swatch.hsla .chip { background: hsl(0 100% 50% / 0.6); }
.swatch.hwb .chip { background: hwb(0deg 0% 0%); }
.swatch.srgb .chip { background: color(srgb 1 0 0 / 0.8); }

/* Optional: make text rendering blend nicely */
.swatch .value,
.swatch .label {
  mix-blend-mode: multiply;
}
Open in editor

Browser Support

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

This data type 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.