CSS Colors
The color property defines the foreground color of text content. However, colors in CSS are used everywhere: backgrounds, borders, shadows, and gradients.
Color Formats
CSS supports multiple formats to define colors:
- Keywords: Predefined names like
red,blue,transparent. - Hexadecimal: A 6-digit code starting with
#, e.g.,#ff0000. - RGB: Functional notation defining Red, Green, and Blue channels, e.g.,
rgb(255, 0, 0). - HSL: Hue, Saturation, Lightness. Intuitive for design, e.g.,
hsl(0, 100%, 50%).
Transparency
Modern CSS allows transparency via the Alpha channel. You can use rgba(), hsla(), or the 8-digit hex code (e.g., #ff000080 for 50% opacity).
Accessibility
When choosing colors, ensure sufficient contrast between the text and background. Tools like the WCAG contrast checker help verify that your content is readable for everyone.
