2 ways to use font color in CSS and HTML

The Font color property

The color attribute of HTML font sets the color of the text in the web documents. You can specify a color by the following ways.

Font color can be set by using:

  • Hexadecimal value: This value is given by using a hash sign (#) and up to 6 HEX values (0-F).
  • Color name: Giving a color name like red, green, yellow etc. Generally this is not the preferred method.
  • RGB: RGB stands for Red, Green, and Blue. It defines the values of red, green and blue at the range of 0-255 for each. For example, in the R part if its value is set to 0 would mean no red while 255 would mean the full red.

You can use the <font> tag to specify color for text in the headings, paragraphs or div etc. However, the recommended way is to use the CSS to set the color of the text. Following example shows using the font color attribute in the font tag. You can also see, setting the font color of different text in HTML elements by using the CSS.

Specify color in <font> tag example

The example sets font color in the <font> tag. For that example, we have created a heading 1 (h1 tag), a heading 2 (h2 tag) and a paragraph (the <p> tag). The font is used as follows:

In this example, we will set the color for heading 1heading 2, and the paragraph with color value in HEXcolor name and RGB value respectively. See online demonstration of this example by clicking link below:

You see, we have defined the CSS in the head section for each element. In the CSS part, we set the color by using the color property of the CSS.

Also see HTML Font | HTML table | CSS font | HTML form

Was this article helpful?

Related Articles

Leave A Comment?