Sikau

CSS · Day 3 · about 25 min

Colours and units

hex, rgb, hsl — px, rem and %.

How much, and what colour?

Every colour and size in CSS needs a value. Knowing which colour format and which unit to pick makes designs consistent — and makes pages adapt to the reader's own settings.

Colours

  • px — fixed pixels. Fine for borders and small details.
  • rem — relative to the root font size (usually 16px). Use rem for font sizes so text respects the reader's browser settings.
  • em — relative to the current element's font size.
  • % — relative to the parent. vw / vh — % of the viewport width / height.

Keep enough contrast between text and background (at least 4.5 : 1 for normal text) so everyone can read it.

The rest of this lesson

  • Four ways to write a colourexplain
  • Choosing unitsexplain
  • How big?predict
  • Pick the unitmatch
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 19 lessons of CSS