Sub topic 1
Why Text Needs a Hierarchy
A page is rarely read from top to bottom. Readers scan it, jump to a heading, skip a paragraph, and come back. A text hierarchy tells them where to look first, what belongs together, and what can be skipped. This chapter explains what a hierarchy is, which tools create it, and why it needs both HTML and CSS. The later chapters build each piece in detail.
Prerequisites
This chapter assumes you already know:
- The basic HTML elements (
h1toh6,p,figure,label,input) and how a document is structured withhtml,head, andbody. - How CSS selectors and declarations work, including linking or embedding a stylesheet.
- What
font-size,font-weight, andcolordo in CSS.
You do not need to know custom properties, rem units, or accessibility standards yet. They are introduced when they are needed.
What a text hierarchy is
A text hierarchy is a consistent system in which each piece of text signals its role and its importance relative to the text around it. The page title looks like a title. A section heading looks like a section heading. A photo caption looks like a note about the photo. A form label looks like the name of its field.
A hierarchy answers three questions for the reader:
- What is this page about?
- How is it divided, and where am I now?
- Which text is the main content, and which text supports it?
Readers answer these questions in the first second or two, mostly without noticing. If the page answers them well, readers feel oriented. If it doesn't, they see a wall of similar-looking text and have to read everything to find anything.
The four roles in this tutorial
This tutorial focuses on four text roles. Each has a different job, so each gets a different treatment.
| Role | Job | Typical treatment |
|---|---|---|
| Heading | Names a section and shows how the page is organized | Larger, heavier, tight line height, extra space above |
| Body text | Carries the main content | Comfortable size, generous line height, limited line length |
| Caption | Explains an image, chart, or table | Smaller, quieter color, placed next to its content |
| Label | Names a form control | Body-sized, slightly bolder, close to its control |
Other roles exist, such as navigation links, buttons, quotes, and code. The same reasoning applies to them, but these four cover most of the text on a typical content page or form.
The cues that create hierarchy
Designers have a small set of visual cues. Each one can make text stand out or recede. Hierarchy comes from using them together and consistently.
Size
Larger text reads as more important. Size is the strongest and most obvious cue, but it works only through contrast. A 24px heading above 16px body text looks like a heading. A 17px heading above 16px body text looks like a mistake.
Weight
Bold text draws the eye without taking more space. Weight suits labels and short headings. It does not suit long passages. If everything is bold, nothing stands out, because emphasis depends on contrast with the text around it.
Spacing
Space groups and separates. A heading with more space above it than below it attaches visually to the paragraph that follows. Line height controls how dense a paragraph feels. Tight line height suits short headings, and looser line height suits multi-line body text.
Color and contrast
Color and lightness can push text forward or back. A mid-gray caption recedes next to near-black body text. This cue has a floor. Text that is too light is hard to read for many people, so it must still meet contrast requirements. A later chapter covers the numbers.
Position and alignment
Text near the top of a section, or aligned to a strong left edge, reads as a starting point. Where text sits relative to its image or field tells the reader what it describes.
How the cues combine
No single cue carries a hierarchy reliably. Combining two or three works better, and it makes the result more robust. A heading that is larger, bolder, and surrounded by more space survives a small font-size change or a missing webfont. A heading that depends only on color disappears for readers who cannot distinguish that color from the text around it.
The diagram shows how the pieces relate.
A worked example
Start with a flat page. Every piece of text is a paragraph with the browser's default styling.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trail Guide</title>
</head>
<body>
<p>Trail Guide</p>
<p>A short introduction to planning a multi-day hike.</p>
<p>Gear</p>
<p>Start with footwear, then add layers.</p>
<p>Leather boots after a week on the trail.</p>
<p>Email address</p>
<input type="email">
</body>
</html>The browser shows seven lines at the same size and weight. You cannot tell the title from the caption. The boots caption has no image to attach to. The "Email address" text is not tied to the field. Nothing about the page's organization is visible, and a screen reader would find no headings to jump between.
Now the same content with a hierarchy. The roles are expressed in HTML, and the cues are applied in CSS.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Trail Guide</title>
<style>
body {
font-family: system-ui, sans-serif;
font-size: 1rem;
line-height: 1.5;
color: #1a1a1a;
margin: 2rem auto;
max-width: 40rem;
padding: 0 1rem;
}
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 0.5rem; }
h2 { font-size: 1.5rem; line-height: 1.2; margin: 2rem 0 0.5rem; }
figcaption { font-size: 0.875rem; color: #595959; }
label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
figure { margin: 1rem 0; }
img { max-width: 100%; height: auto; }
</style>
</head>
<body>
<main>
<h1>Trail Guide</h1>
<p>A short introduction to planning a multi-day hike.</p>
<h2>Gear</h2>
<p>Start with footwear, then add layers.</p>
<figure>
<img src="boots.jpg" alt="A pair of leather hiking boots on a rock" width="320" height="240">
<figcaption>Leather boots after a week on the trail.</figcaption>
</figure>
<h2>Stay in touch</h2>
<label for="email">Email address</label>
<input id="email" name="email" type="email" autocomplete="email">
</main>
</body>
</html>If boots.jpg is missing, the browser shows the alt text instead, and the hierarchy still works. Compare the two versions:
- The title is the largest text on the page, so the reader knows what the page is about.
- The
h2headings have more space above than below, so each one groups with the text that follows it. - The caption is smaller and gray, so it reads as a note on the image and not as part of the main text.
- The label is bolder than the body text and sits directly above its field.
Every one of those effects comes from a role in HTML plus a few CSS declarations. No new content was added.
Two layers: structure and appearance
Look at what the second example does. The HTML says what each piece of text is. The CSS says how it looks. These are separate jobs, and mixing them up causes most hierarchy problems.
- Structure lives in HTML.
h2means "a section heading at the second level." It carries meaning that browsers, search engines, and assistive technology use, such as a screen reader's list of headings. - Appearance lives in CSS.
font-size: 1.5remmakes text bigger. It carries no meaning on its own.
A page can get either layer wrong:
- Correct appearance with wrong structure: a
<p>styled to look like a heading. Sighted users see a heading. Screen reader users hear a paragraph, and the page has no outline for them. - Correct structure with unplanned appearance: an
<h3>left at the default size, or an<h4>picked because it looks smaller. The outline may be correct, but the visual levels do not line up with it.
The next chapter covers this in detail. For now, keep one rule: choose the element by the text's role, then style it to show the level of importance you want.
Common errors
These problems appear often, including on pages built by experienced developers.
- Too many levels. Six distinct heading styles, plus three body sizes, plus assorted colors, give readers too many differences to decode. Most pages work with two or three heading sizes, one body size, and one smaller size for secondary text.
- Differences that are too small. Sizes that differ by one or two pixels look like accidents. Neighboring levels need a clearly visible step. The type scale chapter shows how to choose steps.
- Emphasis everywhere. When bold, large, and colored text are all common, none of them signals importance.
- Color as the only cue. A red heading in otherwise identical text is invisible to some readers and in grayscale printouts. Pair color with size or weight.
- Spacing that groups wrongly. If a heading has equal space above and below, or more space below, it looks detached from its own section.
- Light-gray secondary text. Captions and hints are often made so pale that they fail contrast requirements. Secondary text should be quieter, not unreadable.
- Inconsistency. If one
h2is 24px and another is 22px, the reader senses something is off even when they cannot say what. Consistency is what turns styling into a system.
Edge cases to keep in mind
- Users change text settings. Some readers enlarge their default font size, apply a minimum size, or zoom to 200% or more. A hierarchy built from relative sizes holds up under these changes. One built from fixed pixel sizes may not. A later chapter covers
remunits. - Fonts may not load. If your webfont fails, the fallback font has different proportions. A hierarchy that relies on several cues survives this better.
- Different devices change the available space. A heading that fits on a desktop may wrap to four lines on a phone. Sizes and spacing may need to adapt.
- Not every page needs every role. A form page may have no captions, and an article may have no labels. Use the roles the content actually has.
- Some content needs a visual level that differs from its structural level. For example, a section may need an
h2for the outline but a smaller visual size in a sidebar. Style it with a class instead of switching to a different heading element.
A quick test: the squint test
You can check a hierarchy without any tools. Zoom out, blur your eyes, or step back from the screen so you cannot read the words. Then ask:
- Can you still see the title as the top-level element?
- Can you see where sections start?
- Do captions and labels look different from body text and from each other?
- Do items that belong together look grouped?
If the answers are yes, the visual layer is working. Then check the structure layer: list the headings in order and confirm they read like an outline of the page. The final chapter returns to this with a full checklist.
What comes next
The following chapters take each part in turn. You will choose elements by role, build a small type scale, and apply it to headings, body text, captions, and labels. After that, you will cover contrast and zoom, keep values consistent with CSS custom properties, adjust text across screen sizes, and review the result.
Exercise
A page uses <p class="big-bold">Pricing</p> styled at 28px bold to look like a section heading. It looks correct on screen. Name two problems with this approach and the fix.
Show answer
First, the text has no heading semantics, so screen reader users cannot find it in a list of headings and the page outline is missing this section. Second, the look depends on a class, so any page or tool that ignores the stylesheet shows plain paragraph text with no sign of a heading. The fix is to use a heading element at the right level, for example <h2>Pricing</h2>, and apply the 28px bold style to h2 in CSS.
Exercise
In a stylesheet, body text is 16px, h2 is 17px, and h3 is 16px bold. Why is this hierarchy weak, and what would you change?
Show answer
The size steps are too small, so the headings barely differ from body text, and h2 and h3 are not clearly different levels. Increase the step between levels, for example body at 1rem, h3 at 1.25rem, and h2 at 1.5rem, with tighter line height on the headings and more space above them than below.
Exercise
You are told that the caption under a photo should be "less important" than the paragraph before it. Name two cues you can change, and one limit on how far you can take them.
Show answer
You can reduce the size (for example 0.875rem against 1rem) and use a softer color (for example #595959 against #1a1a1a). The limit is readability. The caption must still meet contrast requirements and remain legible when the reader zooms or enlarges the default font size.