CSS <color> Data Type
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().
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
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
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.
Desktop





Tablets & Mobile





