CSS color
property specifies the color of the text.
The color value can be specified in any valid CSS color format such as ‘color name’, ‘HEX’, ‘RGB’, ‘HSL’, etc.
The example below sets different text colors for the <h1>
, <h2>
and <p>
tags.
Example:
h1{ color: red; } h2{ color: #0000ff; } p{ color: rgb(240, 12, 217); }
CSS Syntax
The color
property has the below syntax:
color: color|initial|inherit;
Property Values
The color
property accepts the following values:
color | Specifies the color of the text in any valid CSS color format such as ‘color name’, ‘HEX’, ‘RGB’, ‘HSL’, etc. |
initial | Sets the color property to its default value. |
inherit | Inherits the color value from its parent element. |
General Info
Default Value | Depends on browser |
Inherited | Yes |
JavaScript Usage | element.style.color = “red” |