HTML Headings h1 to h6, Paragraphs and Line Breaks
Most web content is text, and HTML gives text its outline with headings and paragraphs. Getting these right is the single biggest step toward pages that are easy to scan, accessible to screen-reader users, and understandable to search engines.
Six levels of headings
<h1> through <h6> mark headings from most to least important. A page normally has one <h1> describing what the whole page is about, then <h2> for its main sections, <h3> for subsections inside those, and so on. Do not skip levels on the way down, for example jumping from <h2> straight to <h4>, and never pick a heading level just because of its default font size; CSS can make any heading look the way you want.
Screen-reader users often jump from heading to heading to find the section they need, the way sighted readers skim. A clean outline makes that possible.
Paragraphs and whitespace
<p> wraps a paragraph. Browsers add space between paragraphs automatically. Inside the HTML source, however, line breaks and runs of spaces are collapsed into a single space. That is why the third paragraph in the example appears on one line with normal spacing, despite the line break and extra spaces in the source.
Expected page text
Learning HTML HTML pages are built from elements. Headings Use one h1, then h2 for sections and h3 for subsections. Why the order matters Screen readers and search engines use headings as an outline, so extra spaces collapse. Line one Line two
Line breaks and thematic breaks
<br>forces a line break inside a block of text. Use it where the line break is part of the content, such as an address or a poem, not to create vertical spacing between paragraphs.<hr>marks a thematic break: a change of topic or scene between paragraphs. Browsers draw it as a horizontal line by default, but its meaning is the topic shift, not the line.
To show text exactly as typed, with spaces and line breaks preserved, use <pre>, which is common for code samples and ASCII diagrams.
Common mistakes
- Using several
<h1>elements for visual size, or<h4>just because it looks smaller. - Stacking
<br><br>to create space; use separate paragraphs or CSS margins. - Expecting extra spaces in the source to appear on the page.
- Wrapping block elements such as headings or lists inside a
<p>. A paragraph may only contain inline content, and browsers will close it early.
Summary
- One
<h1>per page, then<h2>to<h6>in order without skipping levels. <p>marks paragraphs; source whitespace collapses to single spaces.<br>is a meaningful line break,<hr>a change of topic,<pre>preserves spacing.
Quiz: Headings and paragraphs