Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 122 Β· Getting Started

Headings and Paragraphs

Structure your text with the six heading levels, paragraphs, line breaks and thematic breaks, and learn why a logical heading outline matters for readers and search engines.

Most of the web is text, and most text is organized in the same way: titles, sub-titles and blocks of sentences. HTML has dedicated elements for each of these. Using them correctly makes your pages easier to read, easier to navigate with assistive technology and easier for search engines to understand.

In this lesson you will learn the six heading levels and how to arrange them into a logical outline, how paragraphs and whitespace behave, and when line breaks, thematic breaks and preformatted text are the right tool. You will also see the most common mistakes, such as "fake" headings, and why they matter more than they look.

Six levels of headings

HTML provides six heading elements, from <h1> (the most important) to <h6> (the least important):

Heading levels

Browsers display higher-level headings in larger text, but size is not the point. The number describes a heading's rank in the document: whether it introduces a whole page, a section, or a smaller part inside a section. If you just want bigger text, that is a job for CSS. If you want a small heading that is still an <h2>, that is also a job for CSS.

In practice, most pages use <h1> to <h3>, sometimes <h4>. If you find yourself reaching for <h5> and <h6> often, the page may be trying to do too much and could be split into several pages.

Build a logical outline

Headings work like the table of contents of a book. Picture a page about houseplants:

HTML
<h1>Caring for Houseplants</h1>

  <h2>Light</h2>
    <h3>Bright, indirect light</h3>
    <h3>Low-light plants</h3>

  <h2>Watering</h2>
    <h3>How often to water</h3>
    <h3>Signs of overwatering</h3>

(The indentation is only there to show the structure; you would normally write each heading at the left edge.)

Follow these guidelines:

  • Use one <h1> per page for its main topic, usually matching the page title.
  • Do not skip levels on the way down. After an <h2>, the next sub-heading should be an <h3>, not an <h4>.
  • Going back up is fine. After some <h3> sections, start a new <h2> section whenever the topic changes.
  • Every heading should introduce some content. A heading followed immediately by another heading of the same level usually means something is missing.

Why it matters: many screen-reader users navigate by jumping from heading to heading, much like skimming a book. Some open a list of all headings on the page and pick one. Search engines also use headings to work out what each part of a page is about. A clean outline helps both.

Headings versus the page title

Beginners often confuse the <h1> with the <title> element from your first page. They are different things:

  • <title> lives in the <head>. It labels the page on the browser tab, in bookmarks and in search results. It is never shown inside the page itself.
  • <h1> lives in the <body>. It is the visible main heading at the top of the content.

They often say similar things, but the title usually adds the site name: the title might be "Caring for Houseplants – Green Corner" while the <h1> is just "Caring for Houseplants". See Page Titles for more.

Writing good heading text

A heading is a promise about what comes next. Good headings are short, specific and make sense on their own, because people often see them out of context, in a list of headings or a search result. "Watering" is better than "Part 2", and "How often to water" is better than "More info". Avoid ending headings with a colon, and keep links and long sentences out of them.

Fake headings

The most common heading mistake is styling an ordinary paragraph to look like a heading:

HTML
<!-- Looks like a heading, but isn't one -->
<p><strong>Watering</strong></p>

<!-- A real heading -->
<h2>Watering</h2>

Sighted readers may not notice a difference, but software does. A bold paragraph does not appear in a screen reader's heading list, does not help search engines and cannot be found by "jump to next heading" shortcuts. The opposite mistake, using a heading tag for text that is not a heading just because it is big, is just as confusing.

What software sees

The console lists every real heading. "Opening hours" is missing, because it is only a bold paragraph, and "Bread and pastries" jumps from level 2 to level 4. Fix both: turn "Opening hours" into an <h2> and change the <h4> into an <h3>, then run the example again.

Paragraphs

The <p> element holds a paragraph: one or more sentences about a single idea. Browsers add some space before and after every paragraph automatically.

Remember from Elements and Tags that HTML collapses whitespace. Pressing Enter in your code does not create a new line on the page:

Whitespace in paragraphs

To start a new paragraph, close the current <p> and open a new one. Never use empty paragraphs (<p></p>) to add space; they are announced by some screen readers and are hard to control. Spacing is a job for CSS.

Writing readable paragraphs

On screens, people scan before they read. Short paragraphs of two to four sentences, each about one idea, are much easier to scan than a single wall of text. Put the most important point first, so a reader who only reads the first line of each paragraph still gets the gist. If a paragraph lists several parallel items, consider a list instead.

Line breaks with <br>

Sometimes the line break itself is part of the content: a postal address, or the lines of a poem. That is the job of <br>:

Line breaks

Do not use <br> to create space between blocks. Stacking several <br> tags to push content down is a common beginner habit. Use separate paragraphs, and later CSS margins, instead.

Thematic breaks with <hr>

The <hr> element marks a change of topic within a section, like the row of asterisks you sometimes see between scenes in a novel. Browsers draw it as a horizontal line, and screen readers may announce it as a separator.

HTML
<p>…and that was the end of the long journey north.</p>
<hr>
<p>Three years later, a letter arrived.</p>

Use <hr> for meaning, not decoration. If you only want a line under a heading, add a border with CSS. And there is no need for an <hr> right before a new heading: the heading already marks the change.

Preformatted text with <pre>

When whitespace does matter, for example in text art or code samples, wrap the text in <pre>. The browser keeps every space and line break exactly as written and uses a monospaced font.

Preformatted text

A <pre> block does not wrap long lines, so on a narrow phone screen it may scroll sideways. Keep lines short. For code, combine it with <code>, as you will see in Computer Code.

Practice: put it all together

Use the editor below to write a short page about a hobby of yours. Include an <h1>, at least two <h2> sections with a paragraph each, and one <hr>.

Your turn

Check your understanding

Quick check Β· 5 questions

of 5 answered You scored / 5 Β· perfect!

  1. 1. You want a sub-heading inside a section that starts with an <h2>. Which element should you use?

    Sub-headings go one level down, so an <h2> section uses <h3> for its parts. Jumping to <h4> skips a level, and bold paragraphs aren't headings at all.
  2. 2. Why should you not pick a heading level just to get bigger or smaller text?

    Screen readers and search engines read the heading levels as an outline. CSS can make any heading look however you like.
  3. 3. What is wrong with <p><strong>Opening hours</strong></p> used as a section title?

    Only real heading elements appear in the outline that assistive technology and search engines use. Use an <h2> (or whatever level fits) instead.
  4. 4. You write three spaces between two words inside a <p>. What does the browser show?

    HTML collapses runs of whitespace into a single space. Use <pre> when every space matters.
  5. 5. Which element is right for the lines of a postal address inside one paragraph?

    <br> creates a line break that is part of the content, which is exactly what address lines need. <hr> marks a change of topic.

Summary

  • <h1>–<h6> define headings by importance, not by size.
  • Use a single <h1> per page, do not skip levels on the way down, and write short, specific heading text.
  • The <h1> is the visible main heading; <title> labels the page in tabs and search results.
  • Never fake a heading with bold text; software only sees real heading elements.
  • <p> holds paragraphs; extra whitespace in your code is collapsed.
  • <br> breaks a line where the break is part of the content; <hr> marks a change of topic.
  • <pre> preserves whitespace exactly as written.

You now know enough HTML to structure a complete article. Next: Formatting Text, where you give words extra meaning with emphasis, highlights and more.