Sub topic 2
Headings: Levels, Order, and Emphasis
Assume you know basic HTML structure and CSS selectors, including font-size, font-weight, and color. This chapter focuses on choosing text elements by meaning, then styling them.
Headings: Levels, Order, and Emphasis
A heading introduces a section. Use one h1 for the page topic, then use h2 for major sections and h3 for subsections inside an h2. The level describes structure, not the size you want to display.
Do not choose a heading because it looks bold. Use CSS when you need visual emphasis without creating a new section.
<main>
<h1>Trail Guide</h1>
<h2>Planning the Route</h2>
<p>Choose a route that matches your time and experience.</p>
<h2>Packing List</h2>
<h3>Clothing</h3>
<p>Pack layers that can handle changing weather.</p>
<h3>Food and Water</h3>
<p>Carry enough supplies for the full route.</p>
</main>A logical heading order helps keyboard and screen-reader users understand the page. Skipping from h2 to h4 can make the outline harder to follow. If a heading is visually too large, change its CSS rather than its HTML level.
Body Text: Size, Line Height, and Line Length
Body text carries the main message. Keep it comfortable to read with a relative size, enough space between lines, and a limited line length.
body {
font-size: 1rem;
line-height: 1.5;
}
p {
max-width: 65ch;
}The rem unit scales from the user's root font size. The ch unit limits a paragraph to roughly the width of 65 characters. This prevents long lines that are difficult to track.
Captions and Other Secondary Text
A caption describes related content, such as an image, chart, or example. Use figcaption inside figure so the relationship is explicit.
<figure>
<img src="boots.jpg" alt="Leather hiking boots on a rock">
<figcaption>Boots used during a week-long hike.</figcaption>
</figure>Style captions as secondary text with a smaller size or muted color, but keep enough contrast for comfortable reading. Do not use captions for information that readers must not miss.
Exercise
A subsection currently uses an h4 directly after an h2. What should you check first?
Show answer
Check the document structure. If it is a direct subsection of the h2, change it to h3; adjust its visual size with CSS if needed.