W3cubDocs

/CSS

color

The color CSS property sets the foreground color value of an element's text content and text decorations. It also sets the currentcolor value, which may be used as an indirect value on other properties, and is the default for other color properties, such as border-color.

For an overview of using color in HTML, see Applying color to HTML elements using CSS.

/* Keyword values */
color: currentcolor;

/* <named-color> values */
color: red;
color: orange;
color: tan;
color: rebeccapurple;

/* <hex-color> values */
color: #090;
color: #009900;
color: #090a;
color: #009900aa;

/* <rgb()> values */
color: rgb(34, 12, 64, 0.6);
color: rgba(34, 12, 64, 0.6);
color: rgb(34 12 64 / 0.6);
color: rgba(34 12 64 / 0.3);
color: rgb(34.0 12 64 / 60%);
color: rgba(34.6 12 64 / 30%);

/* <hsl()> values */
color: hsl(30, 100%, 50%, 0.6);
color: hsla(30, 100%, 50%, 0.6);
color: hsl(30 100% 50% / 0.6);
color: hsla(30 100% 50% / 0.6);
color: hsl(30.0 100% 50% / 60%);
color: hsla(30.2 100% 50% / 60%);

/* Global values */
color: inherit;
color: initial;
color: unset;

Note that the value must be a uniform color. It can't be a <gradient>, which is actually a type of <image>.

Initial value Varies from one browser to another
Applies to all elements. It also applies to ::first-letter and ::first-line.
Inherited yes
Media visual
Computed value If the value is translucent, the computed value will be the rgba() corresponding one. If it isn't, it will be the rgb() corresponding one. The transparent keyword maps to rgba(0,0,0,0).
Animation type a color
Canonical order the unique non-ambiguous order defined by the formal grammar

Syntax

The color property is specified as a single <color> value.

Values

<color>
Sets the color of the textual and decorative parts of the element.

Formal syntax

<color>

where
<color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>

where
<rgb()> = rgb( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] )
<rgba()> = rgba( [ [ <percentage>{3} | <number>{3} ] [ / <alpha-value> ]? ] | [ [ <percentage>#{3} | <number>#{3} ] , <alpha-value>? ] )
<hsl()> = hsl( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] )
<hsla()> = hsla( [ <hue> <percentage> <percentage> [ / <alpha-value> ]? ] | [ <hue>, <percentage>, <percentage>, <alpha-value>? ] )

where
<alpha-value> = <number> | <percentage>
<hue> = <number> | <angle>

Examples

The following are all ways to make a paragraph's text red:

p { color: red; }
p { color: #f00; }
p { color: #ff0000; }
p { color: rgb(255,0,0); }
p { color: rgb(100%, 0%, 0%); }
p { color: hsl(0, 100%, 50%); }

/* 50% translucent */
p { color: rgba(255, 0, 0, 0.5); } 
p { color: hsla(0, 100%, 50%, 0.5); }

Specifications

Specification Status Comment
CSS Color Module Level 4
The definition of 'color' in that specification.
Editor's Draft Adds commaless syntaxes for the rgb(), rgba(), hsl(), and hsla() functions. Allows alpha values in rgb() and hsl(), turning rgba() and hsla() into (deprecated) aliases for them.
Adds color keyword rebeccapurple.
Adds 4- and 8-digit hex color values, where the last digit(s) represents the alpha value.
Adds hwb(), device-cmyk(), and color() functions.
CSS Transitions
The definition of 'color' in that specification.
Working Draft Defines color as animatable.
CSS Color Module Level 3
The definition of 'color' in that specification.
Recommendation Deprecates system-colors. Adds SVG colors. Adds the rgba(), hsl(), and hsla() functions.
CSS Level 2 (Revision 1)
The definition of 'color' in that specification.
Recommendation Adds the orange color and the system colors.
CSS Level 1
The definition of 'color' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 1 12 1 Yes Yes Yes
Keyword color values 1 Yes 1 31 3.5 1
RGB hexadecimal notation (#RRGGBB, #RGB) 1 Yes 1 3 3.5 1
RGB functional notation (rgb()) 1 Yes 1 4 3.5 1
HSL color values (hsl()) 1 Yes 1 9 9.5 3.1
Alpha color values (rgba(), hsla()) 1 Yes 3 9 10 3.1
currentcolor 1 ? 1.5 9 9.5 4
transparent 1 ? 3 9 10 3.1
rebeccapurple 38 ? 33 11 25 Yes
RGB hexadecimal notation (#RRGGBBAA, #RGBA)

63

522

? 49 ? 393 9.1
Space-separated functional color notations 65 ? 52 ? 52 ?
Feature Android webview Chrome for Android Edge mobile Firefox for Android Opera Android iOS Safari Samsung Internet
Basic support 1 1 12 4 Yes Yes ?
Keyword color values Yes Yes Yes Yes Yes Yes ?
RGB hexadecimal notation (#RRGGBB, #RGB) Yes Yes Yes Yes Yes Yes ?
RGB functional notation (rgb()) Yes Yes Yes Yes Yes Yes ?
HSL color values (hsl()) Yes Yes Yes Yes Yes Yes ?
Alpha color values (rgba(), hsla()) Yes Yes Yes 4 Yes Yes ?
currentcolor ? ? ? ? ? ? ?
transparent ? ? ? ? ? ? ?
rebeccapurple Yes ? ? 33 ? 8 ?
RGB hexadecimal notation (#RRGGBBAA, #RGBA) ? ? ? ? No ? ?
Space-separated functional color notations ? ? ? 52 ? ? ?

1. Internet Explorer 8 and later support gray color keywords spelled with an e (grey, darkgrey, darkslategrey, dimgrey, lightgrey, and lightslategrey). Internet Explorer 3 to Internet Explorer 7 only support the keywords spelled with a (gray, darkgray, darkslategray, dimgray, lightgray, and lightslategray).

2. From version 52: this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.

3. From version 39: this feature is behind the Enable experimental Web Platform features preference.

See also

© 2005–2018 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