Style color property

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";

Try it yourself

Example 2

Returns the text color of the <p> element:

alert(document.getElementById("myP").style.color);

Try it yourself

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