Search w3schools.com:

SHARE THIS PAGE

Style color Property

Style Object Reference Style Object

Definition and Usage

The color property sets or returns the color of the text.

Syntax

Set the color property:

Object.style.color="color|inherit"

Return the color property:

Object.style.color

Value Description
color Specifies the color of the text. Look at CSS Color Values for a complete list of possible color values
inherit The value of the color property is inherited from parent element


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The color property is supported in all major browsers.

Note: The value "inherit" is not supported in IE7 and earlier. IE8 requires a !DOCTYPE. IE9 supports "inherit".


Example

Example

Change the color of the text:

<html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.color="#ff0000";
document.getElementById("p2").style.color="magenta";
}
</script>
</head>
<body>

<p id="p1">This is an example paragraph.</p>
<p id="p2">This is also an example paragraph.</p>

<input type="button" onclick="displayResult()" value="Change text color">

</body>
</html>

Try it yourself »


Style Object Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]