Headings, Paragraphs and Text Semantics

Beginner · 10 min

Use h1 to h6 for structure, p for prose, and strong, em, b and i for meaning. See what the browser and the accessibility tree make of each.

Before thisElements, Attributes and Nesting

Dave Gray · 21 min · from 0:25

Headings, Paragraphs and Text Semantics

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Dave GrayReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Headings give a page its outline. Pick the level by structure, `h1` for the page topic and `h2` for its sections, never by how big the text looks. Size is CSS's job.
  • The accessibility tree records the heading level you wrote. In a test, `<h1>` followed by `<h4>` came out as levels 1 and 4, so skipping levels is visible to tools that list headings.
  • A paragraph is a `<p>`. Blank lines and extra spaces in the source do nothing: the browser collapses runs of whitespace into one space.
  • `<strong>` and `<em>` carry meaning (importance and stress emphasis). `<b>` and `<i>` carry none and are for text offset without extra importance, such as a product name or a technical term.
  • A `<br>` forces a line break and an `<hr>` marks a thematic break. Neither is for spacing. Use CSS margins for that.

Text with a shape

A newspaper article has a headline, subheadings and paragraphs. A reader skims the headings to decide where to read. HTML gives you the same structure with six heading elements, h1 through h6, and the paragraph element, p.

<h1>Growing tomatoes</h1>
<p>Tomatoes need sun, water and patience.</p>
<h2>Choosing a variety</h2>
<p>Cherry types ripen first.</p>
<h2>Watering</h2>
<h3>How often</h3>
<p>Deeply, twice a week.</p>

The levels form an outline: h1 is the title, each h2 is a major section, an h3 is a part of the h2 above it. The browser gives each level a default size, but the size is incidental. In a test with headless Chromium 159, every h1 measured 32px whether it was at the top of the page or inside a <section>, and the paragraph had a 16px top margin and display: block. Both are defaults that CSS can change. You pick the heading level for the outline and set the size separately.

Why levels matter

People who use a screen reader often jump between headings to find what they want, much as sighted readers scan. That only works if the levels mean something. The accessibility tree preserves exactly the level you wrote: in a test, <h1>Title</h1><h4>Deep</h4> was reported as heading "Title" [level=1] and heading "Deep" [level=4]. Nothing in the browser stops you from skipping from 1 to 4, but the reader hears a structure with a hole in it.

A working rule: one h1 for the page’s topic, then h2 for sections, h3 inside those, and never skip a level to get a smaller font. The semantic HTML lesson in the frontend roadmap takes the same view. The later article, section and the outline lesson covers why the old “section resets heading levels” idea never worked.

Paragraphs and whitespace

A p is a block of prose. The source file’s layout doesn’t affect what you see: browsers collapse whitespace, turning any run of spaces, tabs and newlines into one space. In a test, a b, a blank line, then c and a tab before d displayed as a b c d, while the raw textContent kept every space. Writing <p> twice is how you get two paragraphs. Pressing Enter twice does nothing.

For the rare cases where line breaks are part of the content, such as a poem or a postal address, use <br>. In a test, one<br>two gave one and two on separate lines. Don’t use <br> to space things out. Margins in CSS do that. The related <hr> is a thematic break, reported as a separator role in the accessibility tree. It is not a decorative line.

Meaning versus appearance in inline text

Inside a paragraph, some words need marking. HTML has pairs that look alike but say different things:

Element Default look Means
<strong> bold this is important
<b> bold draw attention, no extra importance
<em> italic stress emphasis, like voice stress in speech
<i> italic alternate voice or term: a ship name, a foreign phrase

In a test, the computed styles matched that table (strong and b at weight 700, em and i italic), but the accessibility tree reported only the first and third as strong and emphasis. When someone changes <em> to <i> to “fix the italic”, they change the meaning. If you only want a look, use CSS. The inline semantics lesson extends this to mark, abbr, time and code.

What the video covers

The embed is a clip, 0:25 to 10:05, from Dave Gray’s “HTML Tag Text Basics | HTML5 Element Text Tutorial” (December 2021, 21 minutes). The chapters in the clip are web pages being like essays or newspapers (0:25), headings organising content (0:51), a horizontal rule (4:28), whitespace collapsing (5:54), line breaks (6:37) and adding more text content (7:52). The chapter after the clip, block versus inline elements, starts at 10:05. The remainder (entities, abbr, address, comments) is used in the later lesson on entities, whitespace and comments. I could not read a transcript, so I describe only the chapter titles. The video doesn’t have a chapter on strong and em, so that section and the accessibility-tree checks are the prose’s own. The deeper link, Kevin Powell on heading levels, is a 16-minute talk on the outline.

Where this fits

Headings and paragraphs are the first real elements after elements, attributes and nesting. Next comes the other everyday text structure, lists and description lists.

Check yourself

  1. 01Why choose `h2` over `h4` just because `h4` looks smaller?

    Heading level describes where the heading sits in the document outline, not its size. Assistive technology lists headings and their levels, so jumping from level 1 to level 4 implies missing structure. Use the right level and change the size with CSS.

  2. 02What is the difference between `<strong>` and `<b>`?

    Both render bold by default. `<strong>` says the content is important and the accessibility tree exposes it as strong. `<b>` only draws attention without extra importance, like a keyword in a summary. Likewise `<em>` is stress emphasis and `<i>` is an alternate voice or term.

  3. 03You press Enter twice between two lines of text inside one `<p>`. What does the page show?

    One line of wrapped text. HTML collapses whitespace including newlines into a single space. In a test, `a b`, a blank line and `c` all rendered as `a b c`. Use two `<p>` elements, or `<br>` if it is truly one line of text, such as an address.

  4. 04When is an `<hr>` appropriate?

    When there is a real thematic break between paragraph-level content, such as a scene change in a story. It is not a decoration or a spacer. Use a CSS border for visual dividers.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark