Color is the most powerful psychological tool in a designer's arsenal. CSS provides granular control over how colors are calculated, mixed, and displayed across different devices.
1The Science of Light
Understanding how browsers interpret color is key to consistent design.
- →Hex codes: Compact and standard. Use 3-digit shorthand (like
#f00for#ff0000) whenever possible to save bytes. - →RGB/RGBA: Additive color. Maxing Red, Green, and Blue results in White. The Alpha channel is non-destructive, meaning it only fades the background color, not the nested text.
- →HSL/HSLA: Designers' favorite. Hue is the 'tint' (0-360), Saturation is the 'intensity' (0-100%), and Lightness is the 'brightness' (0-100%). It's perfect for creating color themes dynamically.
2Advanced Gradients
Gradients aren't just for backgrounds; they are images created by the browser.
- →Linear Gradients: Flow in a straight line. You can use degrees (
45deg) or keywords (to bottom right). - →Radial Gradients: Emerge from a center point. You can control the shape (circle or ellipse) and the starting position.
- →Color Stops: You can add specific percentage markers (e.g.,
gold 20%, red 80%) to create sharp transitions or complex multi-color patterns.
