Headings & Paragraphs
Headings and paragraphs are the backbone of almost every web page. Headings give the page an outline that readers can scan, that screen-reader users can jump through and that search engines use to understand the topic. Paragraphs hold the body text in between.
Six levels of heading
HTML has six heading elements, from <h1> (most important) to <h6> (least important).
<h1>Visiting Mombasa</h1> <h2>Getting there</h2> <h3>By train (SGR)</h3> <h3>By bus</h3> <h2>Where to stay</h2> <h3>Budget hostels</h3>
By default the browser shows each level in bold, with <h1> the largest and each level after it smaller. But the point of headings is not their size: it is the structure they create, like the chapters and sub-chapters of a textbook.
Heading rules that matter
- Use one
<h1>per page for the main topic, usually matching the page title. The standard does not forbid more, but one clear<h1>is the widely recommended practice. - Don't skip levels. After an
<h2>, the next deeper heading should be<h3>, not<h4>. Going back up (from<h3>to<h2>) is fine. - Choose by meaning, not size. If you want smaller text, use CSS; don't pick
<h4>just because it looks right. - Never use headings just to make text bold. A screen reader announces every heading, so fake headings confuse its users.
Screen-reader users often press the H key to jump from heading to heading, much as sighted people skim. A clean heading outline is one of the cheapest, biggest accessibility wins you can make.
Paragraphs
The <p> element marks a paragraph. Browsers start each paragraph on a new line and add space above and below it.
Something surprises every beginner: HTML collapses whitespace. Any run of spaces, tabs and line breaks in your code is displayed as a single space.
<p>Jambo! My name is Achieng.</p>
The browser displays this on one line as "Jambo! My name is Achieng." with single spaces. Line breaks in your code do not create line breaks on screen. To start a new paragraph, use a new <p>.
Line breaks and thematic breaks
The br element
<br> forces a line break inside a block of text. Use it only where the line break is part of the content, such as an address or a poem:
<p>Kuza Ndoto Hub<br> Moi Avenue<br> Nairobi, Kenya</p>
Stacking <br><br><br> to create space between paragraphs. That's a layout job for CSS margins. Use separate <p> elements for separate paragraphs.
The hr element
<hr> represents a thematic break: a change of topic within a section, such as a scene change in a story. Browsers draw it as a horizontal line. Like <br>, it is a void element with no closing tag.
Preformatted text
If you need whitespace kept exactly as typed, use <pre>. The browser preserves every space and line break and normally uses a monospace font. It is useful for poetry with special layouts, ASCII art and code.
<pre> Day Shift Mon Morning Tue Evening </pre>
Try it
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Visiting Mombasa</title>
</head>
<body>
<h1>Visiting Mombasa</h1>
<p>Mombasa is Kenya's oldest
coastal city, famous for Fort Jesus and its beaches.</p>
<h2>Getting there</h2>
<h3>By train (SGR)</h3>
<p>The Madaraka Express runs between Nairobi and Mombasa.</p>
<h3>By bus</h3>
<p>Many companies run day and night buses.</p>
<hr>
<h2>Contact</h2>
<p>Coast Travel Desk<br>
Moi Avenue<br>
Mombasa</p>
</body>
</html>
Notice that the extra spaces and the line break inside the first paragraph disappear, while the <br> tags in the contact paragraph do create new lines. The headings get smaller from <h1> to <h3>, and the <hr> draws a line before the contact section.
Key points
<h1>–<h6>create an outline; use one<h1>and don't skip levels.- Choose headings for meaning, never for their size.
<p>makes paragraphs, and the browser collapses extra whitespace to one space.<br>is for line breaks that belong to the content;<hr>marks a change of topic;<pre>keeps whitespace exactly.
Tip: use the ← and → keys to move between pages.
