How do you change the font color using CSS?

In CSS, we use the color property to set the foreground color of the text content for an element.

svg viewer

The code snippet below shows the syntax of using the color property to set the color of the <h1> element.

The value of the color property can be specified in three ways:

  1. Using RGB values e.g. rgb(250,0,0), rgb(0,250,0), etc.
  2. Using a Hexadecimal(HEX) value e.g. #FFFFFF, #000000, etc.
  3. Using a valid color name e.g. “white”, “red”, “black”, “blue”, etc.

In the code snippet above, a valid color name is used to set the color for <h1>. In case of <h3>, rgb values are used and a HEX value is used to set the color for the <p> tag.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved