CSS Property color








color property sets the foreground color of an element. It is usually setting text of an element.

The color can be specified by:

ValueDescription
name a color name, like "red"
RGB an RGB value, like "rgb(255,0,0)"
Hex a hex value, like "#ff0000"

To set the body color for all use the following:

body {color:blue;} 

To use the hex color value:


h1 {color:#00ff00;}

To use the RGB value:

h2 {color:rgb(255,0,0);}




Summary

ItemValue
Inherited Yes.
Version CSS1
JavaScript syntax object.style.color="#FF0000"
Applies to All elements.

CSS Syntax

color: color | inherit

Property Values

The property values are listed in the following table.

Value Description
color Set the text color.
inherit Inherit the color from the parent element




Browser compatibility

color Yes Yes Yes Yes Yes

Example

The following code uses different color values.

strong {color: rgb(255,128,128);} 
h3 {color: navy;} 
p.warning {color: #ff0000;} 
pre.pastoral {color: #0f0;}

To add color for a paragraph.

<html>
<head>
<style>
.style1 {<!--from  ww w  . j a v a 2  s.c om-->
  color: purple
}
</style>
</head>
<body>
  <p class="style1">A color style rule has 
  been applied to this text.</p>
</body>
</html>

Click to view the demo