Style color property
- Previous Page Clip
- Next Page columnCount
- Go Up One Level HTML DOM Style Object
Definition and Usage
color
Sets or returns the text color of an attribute.
See also:
CSS Tutorial:CSS Text
CSS Reference Manual:color property
Example
Example 1
Set the text color of different elements:
document.getElementById("myH2").style.color = "#ff0000"; document.getElementById("myP").style.color = "magenta"; document.getElementById("myP2").style.color = "blue"; document.getElementById("myDiv").style.color = "lightblue";
Example 2
Returns the text color of the <p> element:
alert(document.getElementById("myP").style.color);
Syntax
Return the color property:
object.style.color
Set the color property:
object.style.color = "color|initial|inherit"
Property value
Value | Description |
---|---|
color |
to specify the text color. Please see CSS color valuesfor a complete list of possible color values. |
initial | Sets this property to its default value. See also initial. |
inherit | Inherits this property from its parent element. See also inherit. |
Technical details
Default value: | Not specified |
---|---|
Return value: | A string representing the text color of an element. |
CSS Version: | CSS1 |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page Clip
- Next Page columnCount
- Go Up One Level HTML DOM Style Object