W3Schools.com

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.


Example

Example

Change the color of the text:

<html>
<head>
<script type="text/javascript">
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
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE