smartyfy.mrindigi.com

Web Development Pro | Lesson 013 | Typography, Color, and Readability

Web Development Pro · Lesson 13 of 60

Module 2: CSS and responsive design

In this lesson

Prerequisites and learning outcomes

Complete lesson 12 first. This lesson builds on text rhythm and accessible visual choices. By the end, you can create a readable type scale and evaluate color without relying on color alone. Plan 10–15 minutes for the core explanation and additional time for the worked practice.

Design for sustained reading

A workshop website is useful only if visitors can comfortably read it. Typography includes font choice, size, line spacing, line length, and hierarchy. Color helps organize information, but it also affects legibility and meaning. Start with a small, consistent system rather than choosing a different size and color for every sentence.

Use a system font stack for this first project. It avoids extra font downloads and gives a familiar interface on many devices. A custom web font can be added later when its licensing, loading cost, fallback behavior, and readability justify it. A distinctive typeface is not a substitute for a clear heading or a readable paragraph width.

Establish a flexible text rhythm

The body below uses a root-relative size and a unitless line-height. A unitless line-height scales with each element's own font size when inherited, which is usually easier to manage than inheriting a fixed line-height length. Headings use a tighter line-height because large display text often needs less relative vertical space than paragraphs.

body {
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: #243746;
  background: #ffffff;
}
main { max-width: 65ch; margin-inline: auto; padding: 1rem; }
h1 { font-size: 2.25rem; line-height: 1.15; }
h2 { font-size: 1.5rem; line-height: 1.25; }
p { margin-block: 0 1rem; }
a { color: #174b36; text-decoration: underline; }
.notice { border-inline-start: 0.3rem solid #8a2400; padding-inline-start: 1rem; }

Ch is based on a font's zero-character advance, so 65ch is an approximate reading measure rather than a guarantee of exactly sixty-five characters per line. Different letters have different widths. The goal is to avoid lines so long that readers lose their place, while allowing the container to shrink on small screens.

Do not force a tiny root font size simply to make arithmetic convenient. Respect browser defaults and user settings, then use rem values that express the hierarchy you need. Test text enlargement and long headings. A size that looks balanced on your laptop may feel cramped on a phone or with a different default font.

Evaluate contrast as a pair

Contrast depends on foreground and background together. A dark green that works on white may fail on a dark photograph. WCAG's common minimum for ordinary text at level AA is 4.5:1, with 3:1 for qualifying large text; other requirements and exceptions also exist. Do not infer compliance from a color name or from the fact that a color looks dark to you.

Use a reliable contrast calculation or checker with the actual colors. The supplied test calculates the ratio for #243746 on white and #174b36 on white. These solid-color pairs comfortably exceed the ordinary-text threshold. That result does not cover text placed over gradients, images, transparency, or a later hover background; those combinations need their own evaluation.

The contrast formula uses relative luminance, not a simple average of red, green, and blue values. This matters because equal numerical differences in color channels do not produce equal perceived brightness differences. You do not need to memorize the formula for everyday design, but you should know why judging by channel values alone is unreliable.

Do not make color carry meaning alone

If an error is indicated only by red text, a visitor may miss the distinction. Add a clear message and, when useful, another visual cue such as an icon with appropriate text handling or a border. Similarly, links embedded in paragraphs should remain identifiable without requiring the reader to distinguish one hue from another. Underlines are a strong default.

A muted text color should still be readable. “Secondary” information can be less visually prominent without becoming low contrast. Do not make preparation instructions pale simply because they are below the main heading. The information's priority and its legibility are separate decisions.

Avoid fully justified text for this small site. It can create irregular gaps that make reading harder, especially in narrow columns. Left alignment is a straightforward choice for this English-language example. Other languages and writing directions need their own appropriate alignment and typography decisions.

Review real content and user changes

Test a short title, a long title, a paragraph with a link, and the warning notice. Increase browser zoom and, where available, text-only zoom or default font size. Look for clipping, overlapping lines, and controls whose labels no longer fit. Keep the semantic heading levels unchanged when adjusting the visual scale.

Static tests here check color-pair arithmetic and the existence of the supplied stylesheet rules. They cannot judge reading comfort or render text with every platform's fonts. Record the visual checks you perform and the contexts you have not tested. Good typography is a measured design choice that still benefits from human reading.

Worked practice

Worked exercise 1: Predict line-height

Task: Body text is 16px with line-height: 1.6. Worked answer: the nominal line-height is 25.6px. A child with a 20px font inheriting the unitless 1.6 gets 32px. This scaling is why unitless values are useful for a flexible text system.

Worked exercise 2: Repair a color-only warning

Task: “Batteries are not accepted” is shown only in red. Worked answer: retain the explicit warning sentence and add a visible label such as “Safety note,” with a border or other non-color cue if useful. Color can reinforce the message without being its only carrier.

Worked exercise 3: Review a background change

Task: A link color passed contrast on white, but the section becomes dark blue. Worked answer: measure the link color against the new background and choose a suitable alternative if needed. The earlier passing ratio belongs to the old pair and cannot be reused automatically.

Knowledge check

Question 1

What does a unitless line-height multiply? A) The parent’s font size regardless of the child’s size. B) The element's font size. C) The paragraph’s available line width. D) The root font size regardless of the element’s size.

Check question 1: answer and explanation

Answer: B. The ratio scales line spacing with the font size.

Question 2

What does 65ch guarantee? A) Exactly 65 letters on every line. B) Exactly 65 pixels. C) A measure based on the font's zero advance. D) A fixed number of words.

Check question 2: answer and explanation

Answer: C. It is a useful approximation, not an exact character count.

Question 3

Which pairing must be evaluated for contrast? A) Actual foreground and background. B) Text foreground and the default white, regardless of the actual background. C) Text foreground and the container border instead of its fill. D) Only the normal link color, ignoring its hover background.

Check question 3: answer and explanation

Answer: A. Contrast is a relationship between the colors that meet.

Question 4

Which link treatment avoids depending only on hue? A) Green text with no other cue. B) Slightly lighter gray text. C) A color change only on hover. D) An underline plus adequate contrast.

Check question 4: answer and explanation

Answer: D. The underline supplies a non-color identification cue.

Question 5

Does one passing solid-color calculation cover text over every image? A) Yes, if the text color stays the same. B) No; the actual background varies. C) Yes, if the image is local. D) Yes, if the font is a system font.

Check question 5: answer and explanation

Answer: B. Changing background luminance can change the contrast at different positions.

Sources and further reading