Bitpath

Lesson 2 · Unit 04

Type and colour

Readable text, enough contrast, and a dark theme

13 exercisesabout 3 min

What you practise

  • Font stacks, line height and measure, contrast, a dark theme from custom properties and prefers-color-scheme

Try a question from this lesson

Pick one

A visitor's computer does not have the Inter font, but it has Arial. In which font is the text drawn?

CSS
body {
  font-family: "Inter", Arial,
               sans-serif;
}

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Line height and measure

A unitless line-height is a multiplier: each element multiplies it by its own font size, so a big heading gets tall lines. A length such as 24px is inherited as it is, whatever the size of the text.

Body text reads well at about 1.5. Lines should not be too long either: max-width: 65ch caps a paragraph at about 65 characters.

CSS
body { line-height: 1.5; }
p { max-width: 65ch; }

Concept

Contrast

Contrast is the ratio between the brightness of text and of its background. It runs from 1:1, the same colour twice, to 21:1, black on white.

The accessibility guidelines (WCAG, level AA) ask for at least 4.5:1 for body text and 3:1 for large text such as headings.

Pale grey on white looks elegant and fails: #999 on white is under 3:1.

Concept

One theme, two modes

Name your colours once, as custom properties on :root, and use them everywhere with var().

The media feature prefers-color-scheme reports whether the user's system is set to light or dark. A query on it only has to redefine the properties. Every rule that uses them follows.

CSS
:root { --bg: white; --ink: black; }
@media (prefers-color-scheme: dark) {
  :root { --bg: black; --ink: white; }
}
body { background: var(--bg);
       color: var(--ink); }

9 more exercises in the app

  • 2× type the answer
  • 3× multiple choice
  • 2× true or false
  • 1× fill the blanks
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy