Text Hierarchy — UI/UX

Text hierarchy is the reading order (what is read first, second, last) set through four cues: size, weight, colour and space. 3 levels are enough: primary or…

The order summary in a shopping app has more than ten lines: item names, shipping, discount, service fee, address. Yet in one glance your eye finds the total you have to pay. You don't read everything. The way the text looks leads your eye to that total.

The reading order you set through how text looks is called text hierarchy. Text hierarchy decides what gets read first, second and last, without the reader having to read everything first. Imagine a newspaper hanging at a kiosk. From a distance you can read the big headline. Up close you see the subheading. The story only becomes readable once you hold the paper. The editors set that order with four tools: size, weight, ink colour and space. In CSS you use the same four tools.

Four texts, three levels

The Mist Homestay booking card has four texts. Level 1 (primary, the main one) is read first, level 2 (secondary) next, and level 3 (tertiary, the third) last. Their order comes from Mrs. Sri's research: of 40 guest chats, 11 asked "What's the total?". So the total moves up to level 2: in the reading order, it comes right after the room name.

Text Level Why
Terrace Room 1 (primary) The guest confirms which room they are booking
2 nights × $35 = $70 2 (secondary) The amount they pay, the second most asked question
$35 / night · 2 guests 3 (tertiary) Supporting detail, already part of the total
Free cancellation up to 3 days before check-in. 3 (tertiary) Important, but read once the guest is sure

3 levels are enough. If every text has a style of its own, nothing feels most important any more.

The hierarchy in code

Here is the code of the card. Each text is one paragraph (<p>) with its own class. The CSS sets the size (font-size), the weight (font-weight), the colour (color), the line height (line-height) and the space to the text below (margin-bottom):

<p class="room">Terrace Room</p>
<p class="price">$35 / night · 2 guests</p>
<p class="total">2 nights × $35 = $70</p>
<p class="note">Free cancellation up to 3 days before check-in.</p>

<style>
  p { margin: 0; }
  /* Level 1: 36px, heaviest, darkest */
  .room { font-size: 2.25rem; font-weight: 700; color: #111827; line-height: 1.2; margin-bottom: 4px; }
  /* Level 3: 16px, regular, medium grey, relaxed lines */
  .price { font-size: 1rem; font-weight: 400; color: #6B7280; line-height: 1.6; margin-bottom: 16px; }
  /* Level 2: 20px, semibold, dark grey */
  .total { font-size: 1.25rem; font-weight: 600; color: #374151; line-height: 1.2; margin-bottom: 4px; }
  /* Level 3 again */
  .note { font-size: 1rem; font-weight: 400; color: #6B7280; line-height: 1.6; }
</style>

In the exercise, the same three levels are written on h1, h2 and p (heading, subheading and paragraph).

Remove the cues one at a time

How to check a hierarchy: turn off one cue (size, weight, colour or space), keep the others, and see what still reads. In the Lab you can do it on the same text.

Turned off What happens
Size (all 16px) The room name is still the heaviest and darkest, but no longer stands out from a distance
Weight (all 400) The order still reads from size and colour
Colour (all #6B7280) The order still reads from size and weight
Space (all 8px) The price no longer sticks to the room name, the group is gone
All four Four identical lines: the guest has to read all of them

A strong hierarchy uses several cues at once. If one is lost, for example colour on a dim phone screen, the order still reads. A quick way to check: the squint test. Squint (half-close your eyes), or blur the page (filter: blur(3px)). What is still visible should be levels 1 and 2.

Colour: lighter, but still readable

Lighter colours make text feel less important, but there is a lower limit: if the text is too light, it is hard to read. That limit is measured with the contrast ratio: how much lighter one colour is than the other, from 1:1 (identical) to 21:1 (black on white). WCAG 2.2, the web accessibility standard (rules so that everyone can use a page), asks for at least 4.5:1 for normal text. This rule is criterion 1.4.3, level AA (the middle of WCAG's three levels: A, AA, AAA).

For example, say you give the small note on the booking card the light grey #9CA3AF on a white background, so it looks less important. Can everyone still read it? Don't guess, calculate.

The formula: (L lighter + 0.05) ÷ (L darker + 0.05). L is relative luminance, which is how light a colour is: 0 for black and 1 for white. "L lighter" is the L of the lighter colour (here the white background), and "L darker" the L of the darker colour (here the text). For #6B7280 text on white: L of the text = 0.1672 and L of white = 1, so (1 + 0.05) ÷ (0.1672 + 0.05) = 4.83:1. It passes, because it is above 4.5:1. Here is the same calculation for other greys:

Colour Used for Contrast on white
#111827 Primary text 17.74:1
#374151 Secondary text 10.31:1
#4B5563 Secondary text (another choice) 7.56:1
#6B7280 Tertiary text 4.83:1
#9CA3AF Disabled text, such as a button that can't be pressed 2.54:1

So that light grey doesn't pass. #9CA3AF is only 2.54:1, far below 4.5:1. Yet 8 of 40 guest chats asked about the cancellation rule. In that light grey, the cancellation note becomes hard to read for exactly the people whose eyes aren't as sharp as they were, like Mr. Hadi. The lightest grey in this palette (set of colours) that is still safe for body text is #6B7280.

Line height: tight for headings, relaxed for body

Line height is part of the hierarchy too. Write it without a unit, so it is multiplied by the element's own font size:

⚠️ What scrambles the reading order

TL;DR: Text hierarchy is the reading order (what is read first, second, last) set through four cues: size, weight, colour and space. 3 levels are enough: primary or main (size 2.25rem, weight 700, colour #111827), secondary (1.25rem, 600, #374151 or #4B5563), tertiary or third (1rem, 400, #6B7280, line-height 1.6). Check a hierarchy by turning off these cues one at a time, and with the squint test (half-close your eyes): what is still visible must be levels 1 and 2. Text colour may get lighter as long as the contrast ratio (how much lighter the background is than the text) is at least 4.5:1, the WCAG AA rule: #6B7280 at 4.83:1 passes, #9CA3AF at 2.54:1 does not. Headings get a line height of 1.1 to 1.3, body text 1.5 to 1.7, written without a unit.

⚡ Three levels are enough

Meaning: Text hierarchy is the reading order: what gets read first, second and last. You set that order through size, weight, colour and space. 3 levels are enough. On the Mist Homestay booking card, the room name is level 1. The total price moves up to level 2, right after the room name in the reading order, because 11 of 40 guest chats asked for it.

⚡ Four cues step down together

Write:

<p class="room">Terrace Room</p>
<p class="total">2 nights × $35 = $70</p>
<p class="note">Free cancellation up to 3 days before check-in.</p>

<style>
  .room { font-size: 2.25rem; font-weight: 700; color: #111827; line-height: 1.2; }
  .total { font-size: 1.25rem; font-weight: 600; color: #374151; line-height: 1.2; }
  .note { font-size: 1rem; font-weight: 400; color: #6B7280; line-height: 1.6; }
</style>

Meaning: In this code, size (font-size), weight (font-weight) and colour (color) step down together from level 1 to level 3: primary (main) #111827 almost black, secondary dark grey #374151, tertiary (third) medium grey #6B7280. Headings get a line height of 1.1 to 1.3, body text 1.5 to 1.7. If one cue (such as colour) is lost, the order still reads from the others.

⚡ Grey has a limit

Guess first: WCAG, the web accessibility standard, asks for a contrast ratio (how much lighter the background is than the text) of at least 4.5:1. The cancellation note gets the light grey #9CA3AF on white. Does it pass?

No. Its contrast is only 2.54:1, far below 4.5:1. The lightest grey in this palette (set of colours) that is still safe for text is #6B7280, at 4.83:1.

Meaning: Text colour may get lighter as long as the contrast is at least 4.5:1 for normal text (WCAG AA). Calculate it, don't guess.

What you will learn