TExcelTAD
Home › HTML › HTML Paragraphs

HTML Paragraphs

Most of the text on a web page lives in paragraphs. The <p> element marks a block of related sentences, and the browser automatically adds a little space before and after it.

The <p> element

html · try it yourself
<p>Bees can recognise human faces.</p>
<p>Honey never spoils if it is stored properly.</p>
<p>A single bee makes about a twelfth of a teaspoon of honey in its life.</p>

Each <p> starts on a new line and is separated from its neighbours by a margin.

Whitespace is collapsed

This surprises almost everyone at first: the browser ignores extra spaces and line breaks in your HTML source. Any run of spaces, tabs and newlines becomes a single space.

html · try it yourself
<p>
  This     paragraph   has
  lots of      extra spaces
  and
  line breaks     in the source code.
</p>
<p>But it is displayed as one tidy line of text.</p>

Because of this, you can't control layout by pressing Enter or Space in your HTML. You also can't predict exactly where lines will wrap — that depends on the width of the screen. Resize the result panel and watch the text reflow.

Line breaks with <br>

When you need a new line inside a paragraph — in an address or a poem, for example — use <br>.

html · try it yourself
<p>
  ExcelTAD Bakery<br>
  12 Flour Street<br>
  Breadville, BR1 2AD
</p>

Note: Don't use <br> to create space between paragraphs. Use separate <p> elements and, if needed, CSS margins.

Preformatted text with <pre>

The <pre> element is the exception to whitespace collapsing. Inside it, spaces and line breaks are kept exactly as written, and the text is shown in a monospace font.

html · try it yourself
<pre>
   /\_/\
  ( o.o )   Whitespace
   > ^ <    is preserved!

Name     Score
Alice       91
Bob         78
</pre>

<pre> is ideal for ASCII art, code samples and plain-text tables.

Thematic breaks with <hr>

<hr> separates paragraphs that belong to different topics. It has no closing tag.

html · try it yourself
<p>Our summer opening hours are 8:00–20:00.</p>
<hr>
<p>Unrelated news: the café now sells oat milk.</p>

Paragraph reference

Element Purpose Closing tag?
<p> Paragraph of text Yes
<br> Line break within text No
<hr> Thematic break between topics No
<pre> Preformatted text, whitespace kept Yes

Things a paragraph cannot contain

A <p> may only contain inline content such as text, links, <strong>, <em> and images. You cannot put block elements like headings, lists, tables or another <p> inside it. If you try, the browser silently closes the paragraph early, which can mess up your styling.

<p>Shopping:
  <ul><li>Milk</li></ul>   ← the browser ends the <p> before the list
</p>

Tip: If you notice an empty paragraph appearing in your developer tools, look for a block element hidden inside a <p>.

Test yourself

What does the browser do with several spaces in a row inside a <p>?

  1. Shows all of them
  2. Collapses them into one space
  3. Removes them completely
  4. Converts them into line breaks

Which element keeps spaces and line breaks exactly as typed?

  1. <p>
  2. <br>
  3. <pre>
  4. <hr>

Which element should you use for a new line inside an address?

  1. <br>
  2. <hr>
  3. A new <p> for every line
  4. <newline>