color
color
The color
property sets the foreground color of an element's text content, and its decorations.
/* Keyword values */ color: currentcolor; /* Use the color of this element's direct ancestor */ /* <named-color> values */ color: red; /* CSS Level 1 color */ color: orange; /* The only color added in CSS Level 2 (Revision 1) */ color: tan; /* CSS Color Level 3 color, sometimes called SVG or X11 color */ color: rebeccapurple; /* The only color keyword added in CSS Color Level 4 */ /* <hex-color> values */ color: #0f0; /* The color 'lime' with the 3-character notation */ color: #00ff00; /* The color 'lime' with the 6-character notation */ color: #0f0a; /* CSS Color Level 4 color in 4-character notation */ color: #00ff0080; /* CSS Color Level 4 color in 8-character notation*/ /* <rgb()> values */ color: rgb(34, 12, 64, 0.3); /* Legacy comma separated functional notation with alpha value */ color: rgba(34, 12, 64, 0.3); /* Legacy comma separated functional notation */ color: rgb(34 12 64 / 0.3); /* Functional notation with spaces */ color: rgba(34 12 64 / 0.3); /* Functional notation with spaces as alias for rgb() */ /* <hsl()> values */ color: hsl(30, 100%, 50%, 0.3); /* Legacy comma separated functional notation with alpha value */ color: hsla(30, 100%, 50%, 0.3); /* Legacy comma separated functional notation */ color: hsl(30 100% 50% / 0.3); /* Functional notation with spaces */ color: hsla(30 100% 50% / 0.3); /* Functional notation with spaces as alias for hsl() */ /* Global values */ color: inherit; color: initial; color: unset;
This property 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.
Note that the color value must be a uniform color, which may include a transparency value from CSS3 onwards. It can't be a <gradient>
which is an <image>
in CSS-
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
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>? ] )
<named-color> = transparent | aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen
<deprecated-system-color> = ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonFace | ButtonHighlight | ButtonShadow | ButtonText | CaptionText | GrayText | Highlight | HighlightText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowTextwhere
<alpha-value> = <number> | <percentage>
<hue> = <number> | <angle>
Examples
The following are all ways to make the element's text red:
element { color: red; } element { color: #f00; } element { color: #ff0000; } element { color: rgb(255,0,0); } element { color: rgb(100%, 0%, 0%); } element { color: hsl(0, 100%, 50%); } /* 50% translucent */ element { color: rgba(255, 0, 0, 0.5); } element { 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 | Added commaless syntaxes for the rgb() , rgba() , hsl() , and hsla() functions and allowed to include the alpha value in rgb() and hsl() , turning rgba() and hsla() into (deprecated) aliases for them.Added color keyword rebeccapurple .Added 4- and 8-digit hex color values where the last digit represents the alpha value. Added 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 | Deprecated system-colors; added SVG colors; added rgba() , hsl() , and hsla() functions. |
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 |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1.0 | ? | 1.0 (1.7 or earlier) | 3.0 | 3.5 | 1.0 |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 1.0 | ? | 1.0 (1) | 6.0 | 6.0 | 1.0 |
See also
- The
<color>
data type
© 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