CSS Colors
Colors can be expressed using different formats, including named colors, hexadecimal notation, RGB values, RGBA values, HSL values, HSLA values, and more.
Foramt
Description
Example
Named Colors
These are predefined color names like red, green, blue, etc. They are easy to use but somewhat limited in number.
Syntax: color: green;
Hexadecimal
Hex values use a combination of six characters (0-9 and A-F) to represent colors. The first two characters represent red, the next two green, and the last two blue.
Syntax: color: #FFA500;
RGB
RGB uses integers from 0 to 255 to specify the intensity of red, green, and blue respectively. It offers a wide range of colors.
Syntax: color: rgb(255, 0, 0);
RGBA
Similar to RGB, RGBA includes an alpha channel for transparency. The alpha value ranges from 0 (completely transparent) to 1 (fully opaque).
Syntax: color: rgba(0, 128, 0, 0.5);
HSL
Hue (0-360), Saturation (0-100%), and Lightness (0-100%) are used to define colors. HSL is often intuitive for designers.
Syntax: color: hsl(240, 100%, 50%);
HSLA
Just like HSL, HSLA adds an alpha value for transparency.
Syntax: color: hsla(120, 100%, 50%, 0.7);
Usage of colors
- Text
- Background
- Borders