CSS color property
- Previous page clip-path
- Next Page color-scheme
Definition and Usage
The color attribute specifies the text color.
This attribute sets the foreground color of an element (in HTML rendering, it is the color of the element text); raster images are not affected by color. This color will also be applied to all borders of the element unless overridden by border-color or another border color attribute.
The easiest way to set the foreground color of an element is to use the color attribute.
See Also:
CSS Tutorial:CSS Text
HTML DOM Reference Manual:color attribute
Example
Set text color for different elements:
body { color:red; } h1 { color:#00ff00; } p { color:rgb(0,0,255); }
Tips and Comments
Tip:Use a reasonable combination of background and text colors to improve readability.
CSS Syntax
color: color|initial|inherit;
Attribute Value
Value | Description |
---|---|
color_name | Specifies the color as a color name (e.g., red). |
hex_number | Specifies the color as a hexadecimal value (e.g., #ff0000). |
rgb_number | Specifies the color as an RGB code (e.g., rgb(255,0,0)). |
inherit | Specifies that the color should be inherited from the parent element. |
Technical Details
Default Value: | not specified |
---|---|
Inheritance: | yes |
Version: | CSS1 |
JavaScript Syntax: | object.style.color="#FF0000" |
More examples
- Set text color
- This example demonstrates how to set the text color.
Browser support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | IE / Edge | Firefox | Safari | Opera |
---|---|---|---|---|
1.0 | 3.0 | 1.0 | 1.0 | 3.5 |
- Previous page clip-path
- Next Page color-scheme