Colour is the fastest way to make a page feel like yours. CSS gives you several ways to write a colour, plus backgrounds that can be solid, gradient, or an image. Let's make things colourful — and you'll see every change live.
1Ways to write a colour
The color property sets text colour; background-color sets the background. The colour value itself can be written several ways:
| Format | Example | Notes |
|---|---|---|
| Named | tomato, navy | ~140 built-in names. Easy, limited. |
| Hex | #FF6B00 | Most common. Red, green, blue in base-16. |
| RGB | rgb(255, 107, 0) | Red, green, blue from 0–255. |
| RGBA | rgba(255,107,0,0.5) | Adds alpha — transparency from 0–1. |
| HSL | hsl(25, 100%, 50%) | Hue, saturation, lightness — intuitive to tweak. |
colorsets text colour;background-colorsets the background.- Write colours as named, hex (
#FF6B00),rgb(),rgba()(with transparency) orhsl(). - Hex is the everyday default; HSL makes 'same colour, lighter' easy via the lightness value.
2Gradients and background images
Backgrounds can be far more than a flat colour:
- Gradient:
background: linear-gradient(135deg, #1f1a52, #FF6B00);blends smoothly between colours — no image file needed. - Image:
background-image: url('photo.jpg');places a picture behind the content.
With background images you'll usually pair a few properties: background-size: cover (fill the area), background-position: center, and background-repeat: no-repeat.
linear-gradient()blends between colours with no image file.background-image: url(...)places a picture; pair withbackground-size: cover,position,no-repeat.- Keep enough contrast for readable text over images — it's an accessibility requirement.
★ Practical: a colourful card
In any playground, build a card and:
- Give it a
backgroundusing a hex colour. - Set its text
colorusingrgb()orhsl(). - Swap the background for a
linear-gradient()of two colours. - Add a semi-transparent element using
rgba()and check the text stays readable.
Ready to test yourself?
Take the short quiz. Score 60% or more to mark this lesson complete.
Start the quiz →💡 Log in to save your progress and earn the certificate.