loading

Text Color


Numerous properties are available in CSS to format text.


text formatting

This text is styled with some of the text formatting properties. The heading uses the text-align, text-transform, and color properties. The paragraph is indented, aligned, and the space between characters is specified. The underline is removed from this colored "Try it Yourself" link.

Margin Collapse

 

The text’s color can be changed using the color attribute. The following specifies the color:

  • a name for a hue, such as “red”
  • a number in HEX, such as “#ff0000”
  • an RGB number, such as “rgb(255,0,0)”

For an exhaustive list of all possible color values, see CSS Color Values.

The body selector defines the text color that appears on a page by default.

Example

				
					body {
  color: blue;
}

h1 {
  color: green;
}
				
			

Text Color and Background Color

Here, we define the color property as well as the background-color property:

				
					body {
  background-color: lightgrey;
  color: blue;
}

h1 {
  background-color: black;
  color: white;
}

div {
  background-color: blue;
  color: white;
}
				
			

The CSS Text Color Property

Property Description
color Specifies the color of text
Share this Doc

Text Color

Or copy link

Explore Topic