In this lesson you will
- Write the same colour as a keyword, hex, rgb() and hsl(), with or without transparency
- Check that text and background have enough contrast to read
- Choose between px, rem, em, %, vw and ch for each job
- Build a font stack for English and Arabic with a safe fallback
Colours: keywords, hex, rgb and hsl
CSS knows about 150 colour keywords such as navy, teal and crimson. They are quick for experiments, but real designs use exact values. Hex notation writes red, green and blue as two hexadecimal digits each: #ff0000 is pure red, #000000 black and #ffffff white. Three-digit hex such as #f00 is a short form when each pair repeats.
rgb(15 118 110) gives the same three channels as numbers from 0 to 255. hsl(174 77% 26%) describes a colour as hue (an angle on the colour wheel), saturation and lightness, which makes it easy to build a palette: keep the hue and change only the lightness for lighter or darker shades. Modern browsers accept spaces between the numbers; older code uses commas, as in rgb(15, 118, 110), and both work.
For transparency, add an alpha value after a slash: rgb(0 0 0 / 50%) is half-transparent black, perfect for shadows and overlays. Hex can carry alpha too, as a fourth pair: #00000080. The keyword currentColor means "the current text colour" and is handy for borders and icons that should match the text.
Console
- Console messages, errors, form data and clicked links appear here.
Change the last number of the hsl() lightness from 26% to 45% to get a lighter shade of the same green.
Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 3 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
Should I use rem or px for font size?
Use rem. It respects the text size each visitor set in their browser, which matters for people with low vision. px is still fine for borders, outlines and small shadows.
What is the difference between rem and em?
rem is always relative to the root (html) font size. em is relative to the current element’s font size, so it changes inside nested elements. Use rem by default and em when something must scale with its own text.
Which is better, hex or hsl?
They describe the same colours. Hex is short and common in design tools; hsl() is easier to adjust by hand because lightness and saturation are separate numbers. Use whichever your team reads more easily, and stay consistent.
How do I use a Google Font or another web font?
Either add the provider’s <link> in the head, or host the font file yourself and declare it with @font-face. Then put its name first in font-family. Load only the weights you use, and add font-display: swap so text shows while the font downloads.
What is a good font for Arabic websites?
Pick a font designed for Arabic with clear letter shapes at small sizes, such as Noto Naskh Arabic, Noto Kufi Arabic, Cairo or Tajawal, and test it with real text including diacritics. System fonts such as Tahoma and Segoe UI also cover Arabic well and need no download.
Sources
Facts in this lesson were checked against these official pages on 21 October 2026.
- MDN: CSS color values
- MDN: CSS values and units
- MDN: font-family
- W3C WAI: Understanding WCAG 2.2 Contrast (Minimum)
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.