📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials CSS Mastery Colors

Colors

5 min read Quiz at the end
CSS colours: hex (#3b82f6), rgb(59, 130, 246), and hsl(217, 91%, 60%). Use CSS custom properties for colour tokens: --primary: #3b82f6. HSL is the most intuitive for making colour adjustments and variations.

CSS Colors

color: red;                      /* named */
color: #ff0000;                  /* hex */
color: #f00;                     /* shorthand hex */
color: rgb(255, 0, 0);           /* RGB */
color: rgba(255, 0, 0, 0.5);     /* with opacity */
color: hsl(0, 100%, 50%);        /* HSL */
color: oklch(0.6 0.25 30);       /* modern OKLCH */

/* CSS variable */
:root { --primary: #3b82f6; }
h1 { color: var(--primary); }
Topic Quiz · 5 questions

Test your understanding before moving on

1. Which color format is most readable for humans?
💡 HSL (Hue, Saturation, Lightness) is the most intuitive for humans to understand and adjust.
2. rgba() adds:
💡 rgba() adds an alpha channel: rgba(255, 0, 0, 0.5) = 50% transparent red.
3. How do you define a CSS variable?
💡 CSS variables are declared with -- prefix: --color-primary: #3b82f6; inside :root {}.
4. How do you use a CSS variable?
💡 CSS variables are used with var(): color: var(--primary);
5. Which is the modern CSS color format?
💡 OKLCH is the modern perceptually uniform color space recommended in CSS Color Level 4.