Skip to main content
Albero Academy

Colors & Gradients

Every way to specify colour — hex, rgb, hsl and modern functions — plus transparency, gradients, and choosing accessible colours.

Chapter 7CSS14 min readBeginner friendly
  • #CSS
  • #Colors
  • #Gradients

Colour is where a design comes alive. CSS has several ways to specify it, each useful in different situations, plus gradients for smooth transitions between colours. Knowing them — and how to keep colour accessible — is core visual craft.

Colour formats

FormatExampleGood for
Namedred, tomatoQuick prototyping
Hex#2563ebThe common default
rgb()rgb(37 99 235)When you need alpha
hsl()hsl(217 91% 60%)Tweaking lightness/hue by hand

Transparency

alpha & opacity
background: rgb(37 99 235 / 0.1); /* 10% opaque blue (modern syntax) */
background: hsl(217 91% 60% / 0.5);
color: #2563eb80; /* 8-digit hex: last 2 = alpha */
.overlay { opacity: 0.5; } /* fades the WHOLE element + children */

Note the difference: an alpha in the colour makes just that colour translucent; opacity fades the entire element, content and all.

Gradients

linear & radial
/* Linear — a direction and colour stops */
background: linear-gradient(to right, #2563eb, #4f7cff);
background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%);
/* Radial — from a centre outward */
background: radial-gradient(circle, #4f7cff, transparent 70%);
/* Repeating & conic exist too */
background: conic-gradient(from 0deg, red, blue, red);

Accessible colour

Practice

Build a button with an hsl() background and a hover state that's just 10% darker (lower the lightness). Add a translucent overlay using rgb(… / 0.6), and a hero background with a linear-gradient. Verify your text/background contrast passes 4.5:1.

Key takeaways

  1. 01Specify colour as named, hex (#rrggbb), rgb() or hsl(); hsl is easiest to adjust by hand.
  2. 02Add alpha in the colour (rgb(… / 0.5)) to fade just that colour; opacity fades the whole element.
  3. 03Gradients: linear-gradient (direction + stops), radial-gradient, conic-gradient.
  4. 04Body text needs ≥ 4.5:1 contrast — check it, and never rely on colour alone for meaning.