HTML Colors
HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values.
HTML Color Names
HTML supports 140 standard color names. You can use these names directly in your styles.
Example
<h1 style="background-color:Tomato;">Tomato</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style="background-color:DodgerBlue;">DodgerBlue</h1>RGB and RGBA Colors
RGB stands for Red, Green, and Blue. An RGB color value is specified with: rgb(red, green, blue). Each parameter defines the intensity of the color from 0 to 255.
RGB Example
<h1 style="background-color:rgb(255, 99, 71);">rgb(255, 99, 71)</h1>RGBA color values are an extension of RGB with an alpha channel (opacity). An RGBA color value is specified with: rgba(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).
RGBA Example
<h1 style="background-color:rgba(255, 99, 71, 0.5);">rgba(255, 99, 71, 0.5)</h1>HEX Colors
A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color.
HEX Example
<h1 style="background-color:#FF6347;">#FF6347</h1>HSL and HSLA Colors
HSL stands for Hue, Saturation, and Lightness. HSL color values are specified with: hsl(hue, saturation, lightness).
- Hue: A degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue.
- Saturation: A percentage value; 0% means a shade of gray, and 100% is the full color.
- Lightness: Also a percentage; 0% is black, 50% is "normal," and 100% is white.
HSL Example
<h1 style="background-color:hsl(9, 100%, 64%);">hsl(9, 100%, 64%)</h1>HSLA color values are an extension of HSL with an alpha channel (opacity).
Test Yourself with an Exercise
Which of the following is NOT a valid way to specify a color in HTML/CSS?