Colors play an important role to give a good look and feel to your website. You can define colors on page level using Html <body> tag.
The <body> tag has subsequent attributes that can be used to set various colors:
- bgcolor: Specifies a color for the background of the page.
- text: Specifies a color for the body text.
- alink: Define a color for active links or selected links.
- link: Selects a color for linked text.
- vlink: Assigns a color for visited links – that is, for a linked text that you have already clicked on.
NOTE: It is suggested to use CSS to put background or text colors.
HTML Color Coding Methods:
There are observing three different ways to select colors on your web page:
- Color names: Specify color names instantly like blue, red, or green.
- Hex codes:A six-digit code describing the amount of black, green, and red that make up the color.
- Color decimal or percentage values: : This value is determined using the RGB( ) property.
Color Names:
In HTML, colors can be specified directly by a color name to set text or background color. There are listed 16 basic color names:
Black | Gray | Silver | White |
Yellow | Lime | Aqua | Fuchsia |
Red | Green | Blue | Purple |
Maroon | Olive | Navy | Teal |
Background Color
<!DOCTYPE html> <html> <body style="background-color:red;"> <p>This is my first paragraph.</p> <p>This is my second paragraph.</p> </body> </html>
Output
This is my first paragraph.
This is my second paragraph.
Text Color
<!DOCTYPE html> <html> <body"> <p style="color:green;">This is my first paragraph.</p> <p>This is my second paragraph.</p> </body> </html>
Output
This is my first paragraph.
This is my second paragraph.
HTML Colors – Hex Codes:
Hexadecimal is a 6-digit model of color. The first two digits(RR) describe a red value, the next two are a green value(GG), and the last is the blue value(BB).
Each hexadecimal code will be started by a hash sign #.
Color | Color HEX |
---|---|
#000000 | |
#FF0000 | |
#00FF00 | |
#0000FF | |
#FFFF00 | |
#00FFFF | |
#FF00FF | |
#C0C0C0 | |
#FFFFFF |
HTML Colors – RGB Values:
RGB the color value is defined using the rgb( ) property. This property takes three values, one each for red, green, and blue. The value can be an integer between 0 and 255 or a percentage.
rgb(0,0,0) |
rgb(0,255,0) |
rgb(255, 99, 71) |
rgb(192,192,192) |