HTML Colors
HTML Colors
HTML Colors
Colors are very important to give a good look and feel to your website. You can specify colors on the page
level using the <body> tag or you can set colors for individual tags using the bgcolor attribute.
The <body> tag has the 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 a linked text that you have already clicked on.
You can specify direct a color name to set text or background color. W3C has listed 16 basic color names that
will validate with an HTML validator but there are over 200 different color names supported by major
browsers.
Note − Check a complete list of HTML Color Name.
Example
Here are the examples to set the background of an HTML tag by color name −
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by Name</title>
</head>
</html>
Result
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
Example
Here are the examples to set the background of an HTML tag by color code in hexadecimal −
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by Hex</title>
</head>
</html>
rgb(0,0,0)
rgb(255,0,0)
rgb(0,255,0)
rgb(0,0,255)
rgb(255,255,0)
rgb(0,255,255)
rgb(255,0,255)
rgb(192,192,192)
rgb(255,255,255)
Example
Here are the examples to set the background of an HTML tag by color code using RGB () values −
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by RGB code</title>
</head>
</html>