Sub topic 1
Why Text Needs a Hierarchy
Prerequisites
This chapter assumes basic HTML structure and CSS selectors. You should know font-size, font-weight, color, and how to connect a stylesheet to a page.
Why text needs a hierarchy
Visual hierarchy is the pattern that shows readers what matters first. Size, weight, spacing, and color create this pattern. A page title should attract more attention than a caption. Body text should be easy to read without competing with headings.
Hierarchy helps readers scan a page, understand its structure, and find relevant information quickly. It should reflect meaning, not decoration alone.
Choosing elements by role, then styling them
Semantic HTML uses an element that describes a piece of content. A heading is a heading, body text is a paragraph, and a caption describes nearby content. CSS then controls how those elements look.
Do not choose an element only because its default appearance seems suitable. For example, use h2 for a section heading, not p with a larger font size. This keeps the document outline useful to screen readers and other tools.
<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="Leather hiking boots on a rock">
<figcaption>Leather boots after a week on the trail.</figcaption>
</figure>
</main>Building a simple type scale
A type scale is a small set of related text sizes. Use rem, a unit based on the root font size, so user font-size settings remain effective.
:root {
--text-sm: 0.875rem;
--text-base: 1rem;
--text-lg: 1.25rem;
--text-xl: 1.5rem;
--text-2xl: 2rem;
}
body {
font-size: var(--text-base);
line-height: 1.5;
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
figcaption { font-size: var(--text-sm); }These tokens keep related components consistent. Keep body text readable, and reserve the largest sizes for the most important headings.
Exercise
Which is better for a section title: an h2 element or a paragraph styled to look large?
Show answer
Use an h2 because it communicates the section's role to browsers, assistive technology, and other tools.