Colors in CSS
General.
CSS colors are the same as those of HTML but the syntax for designating a color is more diverse: CSS recognizes hexadecimal codes, the RGB decomposition, the HSL decomposition and especially the named colors.
Color space.
By default, CSS uses the sRGB space, which is the easiest to render, even on older hardware. However, it is possible to choose another space for
colors with the @color-profile directive.
Refer to the following pages to learn more about color spaces:
- A tutorial on color spaces.
- The at-rule
@color-profile.
- The function
color().
Color coding.
Hexadecimal notation.
In the RGB system, colors are defined by three parameters, which are the amount of red, green, and blue. A fourth parameter can be
added if you want to specify a partial opacity of the color.
Each of these values can be translated into a hexadecimal number between 00 and ff, or between 0 and 255 in classical decimal.
- #rrggbb
The hexadecimal code of the color is written here on 6 digits, preceded by a sharp (
#). The first two digits (rr) represent the value of red, the next two represent green (gg) and the last two represent blue (bb).
These three values can change from00toff. This hexadecimal notation is perfectly recognized by all browsers. Unfortunately, the codes are not very easy to read. To make things easier, you can refer to the color chart below, or our color synthesizer tool. - #rgb
The hexadecimal code of the color can be written on 3 digits only, always preceded by a sharp (
#). This notation is a simplified version of the previous one, but it offers fewer color shades since each color is assigned a single digit.
#f00is equivalent to#ff0000.
#0a0is equivalent to#00aa00. - #rrggbbαα
The hexadecimal code of the color is written on 8 digits. The last two digits (
αα) reflect the opacity of the color,00corresponding to a totally transparent (therefore invisible) color andffto a totally opaque color.
#ff0000ffis totally opaque (non-transparent) red.
#0000ff80is semi-transparent blue. - #rgbα
A variant of the previous notation but assigning only one digit to each of the components.
0f0fis a totally opaque green.
00F8is a semi-transparent blue.
Named Colors.
Many colors (about 140) have been given a name, which is now recognized by all browsers. Using these names improves the readability of the codes.
Indeed, lavender is more telling than #e6e6fa.
- currentcolor
currentcolorrefers to the common color, text color, and decorative accessories such as borders, underscores, etc.
This value can be useful for setting the color of something other than text (e.g. a border) when the border has been changed beforehand and that we want to return to the same color as the text. - transparent
The colour is totally transparent, therefore invisible.
transparentis equivalent to#0000, in other words black that is completely transparent. - lightblue
The name of a color. There are 132 W3C standardized color names (see color chart below). The name must not be in quotation marks, nor in apostrophes; It is not case sensitive. These names are now recognized by all browsers.
Color Functions.
CSS recognizes a large number of functions for specifying a color in a given color system.
- rgb(r g b) rgba(r g b / α) hsl(h s l) hsla(h s l / α) hwb(h w b) hwba(h w b / α) lab(l a b / α) lch(l c h / α) oklab(l a b / α) oklch(l c h / α) color() ⚠
All these functions define a color from 3 components, and possibly, from a fourth which is opacity, but each in a different frame of reference. Feel free to click on the links for more details on the syntax of these functions.
rgb()andrgba()use the well-known reference system in computer science: red, green, blue. The three parameters correspond to the dosages of the base colors red, green and blue.
hsl()andhsla()allow you to specify a color in the HSL system: Hue, Brightness, Saturation.
hwb()and
hwba()build a color from a hue, and by adding a dose of white (W) and black (b).lab(),lch(),oklab()andoklch()work inthe L*a*b*andL*C*H*systems.color()Allows you to set a color in a color space other than sRGB. For more details, refer to the tutorial on color spaces.
- ...from... ⚠
Most of the functions mentioned above accept to calculate a color in relation to a reference color. At least, this possibility is provided for in the specification, this is not always the case on current browsers.
For example, the syntax below requires a color that is the same as
mediumBluebut with 10% more saturation.hsl(from mediumBlue h calc(s * 1.1) l)
Color chart: all named colors.
Sort Colors by:
Remarks and anecdotes.
- The color
rebeccaPurplewas named in honor of Eric Meyer's daughter, who died at the age of 6 from a brain tumor. Eric Meyer, little known to the general public, is an American consultant who has done a lot for the implementation of standards on the Internet, and particularly for CSS. Note: several names sometimes exist for the same color:
Fuchsia
Magenta
Gray
And all derivativesGrey
And all derivativesAqua
Cyan
- The
transparentcolor name corresponds to the hexadecimal code00000000, in other words it is a transparent black. Why black? This is of little importance because, in the case of a completely transparent color, the first 6 digits of the code have no effect.
Outdated or poorly recognized names. ✗
System Colors. ✗
These color names were initially available to make it easier to integrate a page into the operating system charter. This feature is now deprecated: avoid using it.
Browser support (compatibility).
rgb() and rgba() functions to set a color in the RGB color space.hsl() function allowing you to define a color with its three parameters: hue, brightness and saturation.hwb() function allowing you to define a color from its Hue and a dose of White and Black.lab() and lch() functions defining a color in the CIE color space, closer to human perception.oklab() and oklch() functions.from clause).Notes:
(1) Does not recognize the word currentColor after the word from.
colors
colors
colors
colors
OkLch
colors
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

QQ Browser

Safari sur IOS

Firefox pour Androïd

Opéra Mobile

Baidu Browser

KaiOS Browser

UC Browser pour Androïd

Samsung Internet

Chrome

Edge

Androïd Brower

Chrome pour Androïd

Opéra

Safari

Firefox

Opéra mini
History of color management in CSS.
-
Cascading Style Sheets specification - Version 1
In this first version of the CSS language, colors can be defined:
- By the rgb() function: values of red, green and blue,
- By a hexadecimal code (example: #804575),
- Or by their name for the 16 named colors:aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,white, andyellow.November 17, 1995Working Draft.November 12, 1996Proposed for recommendation.December 17, 1996Recommendation .September 13, 2018Old specification, declared obsolete. -
Cascading Style Sheets Level 2 - Revision 1 Specification
The color namedorangeis added, bringing the number of named colors to 17.
Thetransparentkeyword is also introduced.
System colors are added (example:ActiveBorder).November 04, 1997Working Draft.March 24, 1998Proposed for recommendation.May 11, 1998Recommendation . -
CSS Color Module Level 3
Ability to add transparency to colors, definition of thergba()function.
Support for HSL notation, definition ofhsl()andhsla()functions.
Definition of the keywordcurrentcolor.
System colors are discontinued.
But introduction of named colors of theX11nomenclature.June 23, 1999Working Draft.May 14, 2003Candidate Recommendation.October 28, 2010Proposed for recommendation.June 07, 2011Recommendation . -
CSS Color Module Level 4
Ability to choose a color space other thansRGBand definition of thecolor()function.
Support for HWB notation (Hue, White, Black), and definition ofhwb()andhwba()functions.
Support forLCIEcolors and definition oflab(),lch(),oklab()andoklch()functions.July 05, 2016Working Draft.July 05, 2022Candidate Recommendation. -
CSS Color Module Level 5
Possibility of defining one color relative to another.March 03, 2020Working Draft.
See also, about color management.
The CSS specifications published by the W3C are organized into modules. Everything about colors is described in the module. This includes the following definitions:




