We can change the color of an element using predefined color names or RGB, HEX, HSL, RGBA, HSLA values.
A color of an element can be changed using the color name.
If it's the background color you want to change, use the background-color property.
If it's the text color you want to change, use the color property.
You can change the borders color using the border property.
To have more choices of colors, we can use RGB values, HEX values, HSL values, RGBA values, and HSLA values.
RGB value can be specified using this formula: rgb(red, green, blue).
The parameter (red, green, and blue) defines the intensity of the color. Use between 0 and 255 as the value of the parameter.
Here are some examples so you can understand more the RGB value:
Try to experiment by setting different values.
Shades of gray are often defined using equal values for all the 3 light sources.
We can also use hexadecimal as value of the color. The hexadecimal value looks like this: #rrggbb. rr (red), gg (green) and bb (blue) are the parameters. Use between 00 and ff as the value of the parameter. It's just the same as decimal 0-255 but since this is a hexadecimal 255 is equal to f.
Here's an example:
Shades of gray are often defined using equal values for all the 3 light sources.
We can also use HSL (hue, saturation, and lightness) value for changing the colors. HSL value should be written in this form: hsl(hue, saturation, lightness).
Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue.
Saturation is a percentage value, 0% means a shade of gray, and 100% is the full color.
Lightness is also a percentage, 0% is black, 50% is neither light or dark, 100% is white
Saturation is the intensity of the color.
Lightness is the amount of light you want to give to the color.
Shades of gray are often defined by setting the hue and saturation to 0, and adjust the lightness from 0% to 100% to get darker/lighter shades.
Another way of changing the color is using the RGBA value. It is almost the same with the RGB value but this one has an alpha channel which specifies the opacity for a color. RGBA is written like this: rgba(red, green, blue, alpha).
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all).
The last form we can use for the colors is the HSLA value. It is almost the same as HSL value but it has an alpha channel which specifies the opacity for a color. This is the form for HSLA value: hsla(hue, saturation, lightness, alpha).
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all).
HTML 5 Tutorial #1 - Introduction
HTML 5 Tutorial #2 - HTML Editors
HTML 5 Tutorial #3 - HTML Basic
HTML 5 Tutorial #4 - HTML Elements
HTML 5 Tutorial #5 - HTML Attributes
HTML 5 Tutorial #6 - HTML Headings
HTML 5 Tutorial #7 - HTML Paragraphs
HTML 5 Tutorial #8 - HTML Styles
HTML 5 Tutorial #9 - HTML Text Formatting
HTML 5 Tutorial #10 - HTML Quotation and Citation Elements
HTML 5 Tutorial #11 - HTML Comments