The <color>
CSS data type denotes a color in the sRGB color space. A color can be described in any of these ways:
rgb()
and rgba()
functional notations)hsl()
and hsla()
functional notations)Note that the list of accepted color values have been extended as the specification has evolved, culminating with the latest CSS3 colors.
Associated with the color in the sRGB space, a <color>
value also consists of an alpha-channel coordinate, transparency value, indicating how the color should composite with its background color.
Though CSS color values are precisely defined, they may appear differently on different output devices. Most of them are not calibrated, and some browsers do not support output devices' color profile. Without these, color rendering may vary a lot.
Values of the <color>
CSS data type can be interpolated in order to perform animations or for creating <gradient>
values. In that case they are interpolated on each of their red, green, blue components, each handled as a real, floating-point number. Note that interpolation of colors happens in the alpha-premultiplied sRGBA color space to prevent unexpected grey colors to appear. In animations, the speed of the interpolation is determined by the timing function associated with the animation.
There are several ways to describe a <color>
value.
Color keywords are case-insensitive identifiers which represent a specific color, e.g. red, blue, brown, lightseagreen
. The name describes the color, though it is mostly artificial. The list of accepted values varied a lot through the different specification:
orange
keyword.There are a few caveats to consider when using keywords:
darkgray
/ darkgrey
darkslategray
/ darkslategrey
dimgray
/ dimgrey
lightgray
/ lightgrey
lightslategray
/ lightslategrey
gray
/ grey
slategray
/ slategrey
Specification | Color | Keyword | RGB hex values | Live |
---|---|---|---|---|
CSS Level 1 | black | #000000 | ||
silver | #c0c0c0 | |||
gray | #808080 | |||
white | #ffffff | |||
maroon | #800000 | |||
red | #ff0000 | |||
purple | #800080 | |||
fuchsia | #ff00ff | |||
green | #008000 | |||
lime | #00ff00 | |||
olive | #808000 | |||
yellow | #ffff00 | |||
navy | #000080 | |||
blue | #0000ff | |||
teal | #008080 | |||
aqua | #00ffff | |||
CSS Level 2 (Revision 1) | orange | #ffa500 | ||
CSS Color Module Level 3 | aliceblue | #f0f8ff | ||
antiquewhite | #faebd7 | |||
aquamarine | #7fffd4 | |||
azure | #f0ffff | |||
beige | #f5f5dc | |||
bisque | #ffe4c4 | |||
blanchedalmond | #ffebcd | |||
blueviolet | #8a2be2 | |||
brown | #a52a2a | |||
burlywood | #deb887 | |||
cadetblue | #5f9ea0 | |||
chartreuse | #7fff00 | |||
chocolate | #d2691e | |||
coral | #ff7f50 | |||
cornflowerblue | #6495ed | |||
cornsilk | #fff8dc | |||
crimson | #dc143c | |||
darkblue | #00008b | |||
darkcyan | #008b8b | |||
darkgoldenrod | #b8860b | |||
darkgray | #a9a9a9 | |||
darkgreen | #006400 | |||
darkgrey | #a9a9a9 | |||
darkkhaki | #bdb76b | |||
darkmagenta | #8b008b | |||
darkolivegreen | #556b2f | |||
darkorange | #ff8c00 | |||
darkorchid | #9932cc | |||
darkred | #8b0000 | |||
darksalmon | #e9967a | |||
darkseagreen | #8fbc8f | |||
darkslateblue | #483d8b | |||
darkslategray | #2f4f4f | |||
darkslategrey | #2f4f4f | |||
darkturquoise | #00ced1 | |||
darkviolet | #9400d3 | |||
deeppink | #ff1493 | |||
deepskyblue | #00bfff | |||
dimgray | #696969 | |||
dimgrey | #696969 | |||
dodgerblue | #1e90ff | |||
firebrick | #b22222 | |||
floralwhite | #fffaf0 | |||
forestgreen | #228b22 | |||
gainsboro | #dcdcdc | |||
ghostwhite | #f8f8ff | |||
gold | #ffd700 | |||
goldenrod | #daa520 | |||
greenyellow | #adff2f | |||
grey | #808080 | |||
honeydew | #f0fff0 | |||
hotpink | #ff69b4 | |||
indianred | #cd5c5c | |||
indigo | #4b0082 | |||
ivory | #fffff0 | |||
khaki | #f0e68c | |||
lavender | #e6e6fa | |||
lavenderblush | #fff0f5 | |||
lawngreen | #7cfc00 | |||
lemonchiffon | #fffacd | |||
lightblue | #add8e6 | |||
lightcoral | #f08080 | |||
lightcyan | #e0ffff | |||
lightgoldenrodyellow | #fafad2 | |||
lightgray | #d3d3d3 | |||
lightgreen | #90ee90 | |||
lightgrey | #d3d3d3 | |||
lightpink | #ffb6c1 | |||
lightsalmon | #ffa07a | |||
lightseagreen | #20b2aa | |||
lightskyblue | #87cefa | |||
lightslategray | #778899 | |||
lightslategrey | #778899 | |||
lightsteelblue | #b0c4de | |||
lightyellow | #ffffe0 | |||
limegreen | #32cd32 | |||
linen | #faf0e6 | |||
mediumaquamarine | #66cdaa | |||
mediumblue | #0000cd | |||
mediumorchid | #ba55d3 | |||
mediumpurple | #9370db | |||
mediumseagreen | #3cb371 | |||
mediumslateblue | #7b68ee | |||
mediumspringgreen | #00fa9a | |||
mediumturquoise | #48d1cc | |||
mediumvioletred | #c71585 | |||
midnightblue | #191970 | |||
mintcream | #f5fffa | |||
mistyrose | #ffe4e1 | |||
moccasin | #ffe4b5 | |||
navajowhite | #ffdead | |||
oldlace | #fdf5e6 | |||
olivedrab | #6b8e23 | |||
orangered | #ff4500 | |||
orchid | #da70d6 | |||
palegoldenrod | #eee8aa | |||
palegreen | #98fb98 | |||
paleturquoise | #afeeee | |||
palevioletred | #db7093 | |||
papayawhip | #ffefd5 | |||
peachpuff | #ffdab9 | |||
peru | #cd853f | |||
pink | #ffc0cb | |||
plum | #dda0dd | |||
powderblue | #b0e0e6 | |||
rosybrown | #bc8f8f | |||
royalblue | #4169e1 | |||
saddlebrown | #8b4513 | |||
salmon | #fa8072 | |||
sandybrown | #f4a460 | |||
seagreen | #2e8b57 | |||
seashell | #fff5ee | |||
sienna | #a0522d | |||
skyblue | #87ceeb | |||
slateblue | #6a5acd | |||
slategray | #708090 | |||
slategrey | #708090 | |||
snow | #fffafa | |||
springgreen | #00ff7f | |||
steelblue | #4682b4 | |||
tan | #d2b48c | |||
thistle | #d8bfd8 | |||
tomato | #ff6347 | |||
turquoise | #40e0d0 | |||
violet | #ee82ee | |||
wheat | #f5deb3 | |||
whitesmoke | #f5f5f5 | |||
yellowgreen | #9acd32 | |||
CSS Color Module Level 4 | rebeccapurple | #663399 |
The color rebeccapurple
is equivalent to the color #639
, and more information about why it was introduced can be found in this Codepen blog post by Trezy "Honoring a Great Man."
transparent
keywordThe transparent
keyword represents a fully transparent color, i.e. the color seen will be the background color. Technically, it is a black with alpha channel at its minimum value and is a shortcut for rgba(0,0,0,0)
.
transparent
keyword wasn't a true color in CSS Level 2 (Revision 1). It was a specific keyword that could be used in place of a regular <color>
value on two CSS properties: background
and border
. It was essentially added to allow to override an inherited solid colors.transparent
was redefined as a true color in CSS Colors Level 3 allowing its use in any place where a <color>
value is required, like the color
property.currentColor
keywordThe currentColor
keyword represents the calculated value of the element's color
property. It allows to make the color properties inherited by properties or child's element properties that do not inherit it by default.
It can also be used on properties that inherit the calculated value of the element's color
property and will be equivalent to the inherit
keyword on these elements, if any.
The color of the line (a color-filled div) adapts to the color of its color
property, inherited from its parent.
<div style="color:darkred"> The color of this text is the same as the one of the line: <div style="background:currentcolor; height:1px"></div> Some more text. </div>
<div style="color:blue; border-bottom: 1px dashed currentcolor;"> The color of this text is the same as the one of the line: <div style="background:currentcolor; height:1px"></div> Some more text. </div>
Colors can be defined using the red-green-blue (RGB) model in two ways:
#RRGGBB,
#RGB
#
", followed by six hexadecimal characters (0-9, A-F), where the first two digits represent the red part, the second two the green part and the last two the blue part.#
", followed by three hexadecimal characters (0-9, A-F), where the first digit represents the red part, the second the green part and the last one the blue part.#RGB
) and the six-digit form (#RRGGBB
) are equal, for example #f03
and #ff0033
represent the same color.rgb(R,G,B)
rgb
", followed by three <integer>
or three <percentage>
values./* These examples all specify the same RGB color: */ #f03 #F03 #ff0033 #FF0033 rgb(255,0,51) rgb(255, 0, 51)rgb(255, 0, 51.2)/* ERROR! Don't use fractions, use integers */ rgb(100%,0%,20%) rgb(100%, 0%, 20%)rgb(100%, 0, 20%)/* ERROR! Don't mix up integer and percentage notation */
Colors also can be defined the Hue-saturation-lightness model (HSL) using the hsl()
functional notation. The advantage of HSL over RGB is that it is far more intuitive: you can guess at the colors you want, and then tweak. It is also easier to create sets of matching colors (by keeping the hue the same and varying the lightness/darkness, and saturation).
Hue is represented as an angle of the color circle (i.e. the rainbow represented in a circle). This angle is given as a unitless <number>
. By definition red=0=360, and the other colors are spread around the circle, so green=120, blue=240, etc. As an angle, it implicitly wraps around such that -120=240 and 480=120.
Saturation and lightness are represented as percentages.
100%
is full saturation, and0%
is a shade of grey.
100%
lightness is white, 0%
lightness is black, and 50%
lightness is "normal".
hsl(0, 100%,50%) /* red */ hsl(30, 100%,50%) hsl(60, 100%,50%) hsl(90, 100%,50%) hsl(120,100%,50%) /* green */ hsl(150,100%,50%) hsl(180,100%,50%) hsl(210,100%,50%) hsl(240,100%,50%) /* blue */ hsl(270,100%,50%) hsl(300,100%,50%) hsl(330,100%,50%) hsl(360,100%,50%) /* red */ hsl(120,100%,25%) /* dark green */ hsl(120,100%,50%) /* green */ hsl(120,100%,75%) /* light green */ hsl(120,100%,50%) /* green */ hsl(120, 67%,50%) hsl(120, 33%,50%) hsl(120, 0%,50%) hsl(120, 60%,70%) /* pastel green */
Colors can be defined in the Red-green-blue-alpha model (RGBa) in two ways:
#RRGGBBAA and #RGBA
#
", followed by eight hexadecimal characters (0-9, A-F), where the first two digits represent the red part, the second two the green part, the third two the blue part and the last two the transparency.#
", followed by four hexadecimal characters (0-9, A-F), where the first digit represents the red part, the second the green part, the third one the blue part and the last one the transparency.#RGBA
) and the eight-digit form (#RRGGBBAA
) are equal, for example, #f038
and #ff003388
represent the same color.rgba()
functional notation.#f030 /* 0% opaque red */ #F03F /* full opaque red */ #ff003300 /* 0% opaque red */ #FF003388 /* 50% opaque red */ rgba(255,0,0,0.1) /* 10% opaque red */ rgba(255,0,0,0.4) /* 40% opaque red */ rgba(255,0,0,0.7) /* 70% opaque red */ rgba(255,0,0, 1) /* full opaque red */
Colors can be defined in the hue-saturation-lightness-alpha model (HSLa) using the hsla()
functional notation. HSLa extends the HSL color model to include the alpha channel, allowing specification of the opacity of a color.
a means opacity: 0=transparent; 1=opaque;
hsla(240,100%,50%,0.05) /* 5% opaque blue */ hsla(240,100%,50%, 0.4) /* 40% opaque blue */ hsla(240,100%,50%, 0.7) /* 70% opaque blue */ hsla(240,100%,50%, 1) /* full opaque blue */
Not all system colors are supported on all systems. for use on public web pages.
CaptionText
as foreground color.ButtonText
foreground color.ButtonFace
or ThreeDFace
background color.ActiveCaption
background color.HighlightText
foreground color.Highlight
background color.InactiveCaptionText
foreground color.InactiveCaption
background color.InfoText
foreground color.InfoBackground
background color.MenuText
or -moz-MenuBarText
foreground color.Menu
background color.ButtonText
foreground color.WindowText
foreground color.Window
background color.ThreeDFace
or ButtonFace
when the mouse pointer is not over it). Should be used with the -moz-ButtonHoverText
foreground color.-moz-ButtonHoverFace background
color.-moz-CellHighlightText
foreground color. See also -moz-html-CellHighlight
.-moz-CellHighlight background
color. See also -moz-html-CellHighlightText
.-moz-ComboboxText
foreground color. In versions prior to 1.9.2, use -moz-Field
instead.-moz-Combobox
background color. In versions prior to 1.9.2, use -moz-FieldText
instead.-moz-DialogText
foreground color.-moz-Dialog
background color.-moz-FieldText
foreground color. In Gecko versions prior to 1.9, use -moz-Field
. See also -moz-OddTreeRow
.-moz-FieldText
foreground color.-moz-Field
, -moz-EvenTreeRow
, or -moz-OddTreeRow
background color.<select>
s. Should be used with the -moz-html-CellHighlightText
foreground color. Prior to Gecko 1.9, use -moz-CellHighlight
.<select>
s. Should be used with the -moz-html-CellHighlight
background color. Prior to Gecko 1.9, use -moz-CellHighlightText
.Highlight
. Should be used with the -moz-MenuHoverText
or -moz-MenuBarHoverText
foreground color.HighlightText
. Should be used with the -moz-MenuHover
background color.MenuText
. Should be used on top of Menu
background.-moz-MenuHoverText
. Should be used on top of -moz-MenuHover
background.-moz-FieldText
foreground color. In Gecko versions prior to 1.9, use -moz-Field
. See also -moz-EvenTreeRow
.-moz-appearance
: -moz-win-communications-toolbox;
.-moz-appearance
: -moz-win-media-toolbox
.Specification | Status | Comment |
---|---|---|
CSS Color Module Level 4 The definition of '<color>' in that specification. | Editor's Draft | Added rebeccapurple and four- (#RGBA ) and eight-digit (#RRGGBBAA ) hexadecimal notations. |
CSS Color Module Level 3 The definition of '<color>' in that specification. | Recommendation | Deprecated system-colors; added SVG colors; added rgba() , hsl() , hsla() functional notation. |
CSS Level 2 (Revision 1) The definition of '<color>' in that specification. | Recommendation | Added the orange color and the system-colors. |
CSS Level 1 The definition of '<color>' in that specification. | Recommendation | Initial definition |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
keywords colors | 1.0 | 1.0 (1.0) | 3.0 [1] | 3.5 | 1.0 (85) |
#RRGGBB , #RGB
| 1.0 | 1.0 (1.0) | 3.0 | 3.5 | 1.0 (85) |
rgb() | 1.0 | 1.0 (1.0) | 4.0 | 3.5 | 1.0 (85) |
hsl() | 1.0 | 1.0 (1.5) | 9.0 | 9.5 | 3.1 (525) |
rgba() , hsla()
| 1.0 | 3.0 (1.9) | 9.0 | 10.0 | 3.1 (525) |
currentColor | 1.0 | 1.5 (1.8) | 9.0 | 9.5 | 4.0 (528) |
transparent | 1.0 | 3.0 (1.9) | 9.0 [2] | 10.0 | 3.1 (525) |
rebeccapurple | 38.0 | 33 (33) | 11 | 25.0 | 7.1 |
#RRGGBBAA , #RGBA
| 52.0 | 49 (49) | ? | 39.0 | 9.1 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
rgba() , hsla()
| (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
rebeccapurple | (Yes) | 33.0 (33) | ? | ? | 8 |
#RRGGBBAA , #RGBA
| 52.0 | 49.0 (49) | No support | No support | ? |
[1] The 'e'-grey colors (with an e) (grey
, darkgrey
, darkslategrey
, dimgrey
, lightgrey
, lightslategrey
) are only supported since IE 8.0. IE 3 to IE 7 only support the 'a' variants: gray
, darkgray
, darkslategray
, dimgray
, lightgray
, lightslategray
.
[2] IE 7-8 supports the transparent
keyword only for background
and border
. color: transparent;
is drawn black in IE. IE6 renders transparent borders as black, as well.
[3] This feature is supported in Chrome Canary since version 52.0.
opacity
property, allowing to define the transparency of color at the element level.color
, background-color
, border-color
, outline-color
, text-shadow
, box-shadow
properties.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value