HTML Β· Chapter 7 of 45

HTML Paragraphs

The <p> tag defines a paragraph of text. Browsers automatically add space before and after each paragraph.

HTML collapses extra whitespace and line breaks in source code into a single space, so you cannot create visual line breaks just by pressing Enter in your code β€” you need the <br> tag or CSS instead.

Syntax
<p>Text content</p>

Whitespace collapsing

Multiple spaces, tabs, and newlines in your HTML source are all rendered as a single space by the browser. This keeps your source code flexible for formatting.

Line breaks

Use <br> to force a line break within a paragraph without starting a new one, useful for addresses or poems.

Example 1 (html)
<p>This is   a    paragraph
with line breaks in the source.</p>
Output
This is a paragraph with line breaks in the source.

Extra whitespace and newlines collapse into single spaces.

Example 2 (html)
<p>123 Main St.<br>Springfield, USA</p>
Output
123 Main St.
Springfield, USA

<br> forces a line break inside the same paragraph.

Key points

  • <p> defines a paragraph with automatic spacing.
  • Browsers collapse extra whitespace into one space.
  • Use <br> for a forced line break.
  • Don't use empty paragraphs just to add spacing β€” use CSS.
πŸ’‘ Note: For visual spacing between elements, prefer CSS margin over empty <p></p> tags.

πŸ“ Quick Quiz

1. Which tag defines a paragraph?

2. How does HTML treat multiple spaces in source code?

3. Which tag forces a line break without a new paragraph?