CSS Colors
Colors are one of the most fundamental and important properties in CSS. CSS provides multiple ways to define and use colors, making web design more vibrant and engaging.
Color Representation Methods
1. Color Names
CSS supports 140+ predefined color names.
Syntax:
Example:
Common Color Names:
- Basic colors:
red,blue,green,yellow,orange,purple,pink,brown - Black, white, gray:
black,white,gray,silver,darkgray,lightgray - Special colors:
transparent(transparent),currentColor(current color)
2. Hexadecimal Colors
Uses # followed by 6 or 3 hexadecimal digits to represent colors.
Syntax:
Example:
Hexadecimal Reference:
#000000= Black#FFFFFF= White#FF0000= Red#00FF00= Green#0000FF= Blue#FFFF00= Yellow#FF00FF= Magenta#00FFFF= Cyan
3. RGB Colors
Defines colors using Red, Green, and Blue primary color values.
Syntax:
Example:
4. RGBA Colors (With Transparency)
RGBA adds an Alpha channel (transparency) to RGB.
Syntax:
Example:
5. HSL Colors
HSL stands for Hue, Saturation, and Lightness.
Syntax:
- Hue: 0-360 degrees on the color wheel
- 0 or 360 = Red
- 120 = Green
- 240 = Blue
- Saturation: 0%-100%
- 0% = Gray
- 100% = Fully saturated
- Lightness: 0%-100%
- 0% = Black
- 50% = Normal
- 100% = White
Example:
6. HSLA Colors (With Transparency)
HSLA adds an Alpha channel to HSL.
Syntax:
Example:
Color Properties
color Property
Sets text color.
background-color Property
Sets background color.
border-color Property
Sets border color.