HTML Tutorials for Beginners to Advance

HTML Basic Structure, Elements in HTML, HTML Headlines, List in HTML, Insert Images in Web Pages, Tables in HTML, HTML form design, HTML5 Elements, HTML Canvas, etc.

HTML Colors

In HTML, a color can be specified by using a color name, an RGB value, or a HEX value.

You can specify colors on page level using <body> tag or you can set colors for individual tags using bgcolor attribute.

The <body> tag has following attributes which can be used to set different colors:-

  • bgcolor :- sets a color for the background of the page.
  • text :- sets a color for the body text.
  • alink :- sets a color for active links or selected links.
  • link :- sets a color for linked text.
  • vlink :- sets a color for visited links − that is, for linked text that you have already clicked on.

Methods of HTML Color Coding

There are following three different methods to set colors in your web page :-

  • Color names − You can specify color names directly like green, blue or red.

  • Hex codes − A six-digit code representing the amount of red, green, and blue that makes up the color.

  • Color decimal or percentage values − This value is specified using the rgb( ) property.

RGB Value

In HTML, a color can also be specified as an RGB value, using this formula: rgb(red, green, blue)

Each parameter (red, green, and blue) defines the intensity of the color between 0 and 255.

For example, rgb(255,0,0) is displayed as red, because red is set to its highest value (255) and the others are set to 0.

To display the color black, all color parameters must be set to 0, like this: rgb(0,0,0).

To display the color white, all color parameters must be set to 255, like this: rgb(255,255,255).

Experiment by mixing the RGB values below: