Sub topic 1
Why Text Needs a Hierarchy
A page full of text is only useful if readers can tell what each piece is for. A title, a paragraph, a photo caption, and a form label all look like "words on a screen". A text hierarchy tells the reader which words to read first, which to read next, and which to treat as supporting detail. This chapter introduces the idea and the tools used to build it. Later chapters cover each tool in depth.
Prerequisites
This chapter assumes you can:
- Write basic HTML: elements, attributes, and a document with a
<main>section. - Write basic CSS: selectors, properties, and rules.
- Use
font-size,font-weight, andcolorin CSS.
You do not need to know anything about accessibility or responsive design yet.
What a text hierarchy is
A visual hierarchy is an ordering of content by importance. Readers scan before they read. They look for the largest, boldest, or highest-contrast item, then move to the next one. If everything looks the same, they must read every line to find what they need.
A text hierarchy applies this to words. Most pages use four text roles:
| Role | Purpose | Typical treatment |
|---|---|---|
| Heading | Names a section and lets readers scan | Larger, bolder, tight spacing |
| Body | Carries the main content | Medium size, comfortable spacing |
| Caption | Describes an image or figure | Smaller, lower emphasis |
| Label | Names a form field | Body-sized, slightly bolder |
Each role gets a distinct but consistent look. Every heading of the same level looks alike. Every caption looks alike. That consistency teaches the reader what the styles mean.
How size, weight, spacing, and color create hierarchy
Four visual tools do most of the work:
- Size. Larger text reads as more important. Size is the strongest signal.
- Weight. Bolder text stands out from regular text of the same size. Labels often use this.
- Spacing. Extra space above a heading groups it with the content below it and separates it from the previous section. Line height and margins also affect how dense the text feels.
- Color. Higher contrast draws attention. A slightly lighter, still readable color pushes secondary text, such as captions, into the background.
Use these in combination, and use only as many differences as you need. A heading that is bigger, bolder, and a different color, in a different font, with an underline, is shouting. Two or three clear differences are enough.
Structure and style are two separate jobs
Text hierarchy has two layers that work together:
- Semantic structure is the HTML you choose.
<h1>,<h2>,<p>,<figcaption>, and<label>state what each piece of text is. Browsers, search engines, and screen readers use this information. - Visual styling is the CSS you write. It decides how each element looks.
A common mistake is to treat them as one thing. A <p> styled with large, bold text looks like a heading, but a screen reader announces it as a paragraph, and it will not appear in the list of headings that assistive technology offers for navigation. The reverse also fails. An <h3> chosen because its default size looks right, even though the content is a top-level section, gives the page a broken outline.
The rule is: choose the element for its role, then use CSS to make it look right.
A small example
This page uses one element per role. The markup carries the structure, and the styling can change later without touching it.
<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">
<figcaption>Leather boots after a week on the trail.</figcaption>
</figure>
<h2>Food</h2>
<h3>Breakfast</h3>
<p>Oats keep well and cook quickly.</p>
</main>Even with no CSS, the browser's default styles show a hierarchy. The <h1> is largest, <h2> and <h3> step down, and paragraphs are plain. A reader can see that "Breakfast" belongs under "Food", which belongs to the guide as a whole.
The following diagram shows the same outline as a tree.
Common errors
- Everything the same size. Headings, body, and captions blend together. Readers must read to find their place.
- Everything emphasized. If every element is large or bold, none stands out.
- Choosing elements by appearance. Using
<h4>because it is small, or<b>in place of a heading, damages the structure. - Inconsistent treatment. Two
<h2>elements that look different make readers wonder whether they mean different things.
What comes next
The next chapters build on this split. You will choose elements by role, define a type scale, and then style headings, body text, captions, and labels. You will finish by checking contrast, text resizing, and the heading outline.
Exercise
A designer styles a <p> with font-size: 2rem; font-weight: 700 so it looks like a section title. Name two problems with this and say what to do instead.
Show answer
First, the element describes the text as a paragraph, so screen readers do not list it as a heading and the page outline has no entry for that section. Second, the page's structure now depends on appearance, so changing the CSS can break the meaning. Use an <h2> (or the level that fits the outline) for the section title, and apply the size and weight in CSS if the default look is not what you want.
Exercise
List the four visual tools that create hierarchy, and say which one you would change first to make a caption less prominent than body text.
Show answer
Size, weight, spacing, and color. Reduce the size first (for example, a smaller font-size than the body), since size is the strongest signal. Then, if needed, use a slightly lighter color that still meets contrast requirements.