Paragraphs & Text
<p> element does far more than wrap a paragraph; combined with inline elements like <strong>, <em>, and <mark>, it lets you convey emphasis, importance, and context that plain text simply cannot.
The Paragraph Element
The <p> element defines a block of text as a paragraph. Browsers automatically add margin above and below each paragraph to separate it visually. It is a block-level element — it starts on a new line and takes up the full available width.
<p>This is the first paragraph. It contains a full thought and may span many sentences on multiple lines in your code.</p> <p>This second paragraph starts fresh. Browsers render each <p> with top and bottom margin — no need for <br> to separate paragraphs.</p> <!-- Never nest paragraphs! This is invalid HTML --> <p>Outer paragraph <p>inner paragraph</p></p> <!-- WRONG -->
HTML Whitespace Rules
HTML collapses all consecutive whitespace (spaces, tabs, newlines) into a single space when rendering. This is called whitespace normalisation — your source formatting doesn't affect the output.
<!-- All these render identically: "Hello World" --> <p>Hello World</p> <p>Hello World</p> <!-- extra spaces collapsed --> <p>Hello World</p> <!-- newlines = one space --> <!-- To preserve whitespace, use <pre> --> <pre> This preserves spacing and newlines exactly </pre>
Line Breaks & Horizontal Rules
Two simple elements give you control over visual flow without creating new paragraph blocks:
<!-- <br> — single line break, self-closing --> <p> 123 Main Street<br> Apt 4B<br> New York, NY 10001 </p> <!-- <hr> — horizontal rule / thematic break --> <p>Chapter 1 content here.</p> <hr> <p>Chapter 2 starts after the divider.</p>
<br><br> to create paragraph spacing is bad practice. Use separate <p> elements instead — they carry semantic meaning and are styleable with CSS. Reserve <br> for genuine line breaks within a block (like addresses and poetry).Inline Text Semantics
Inline elements live inside paragraphs and headings. Unlike block elements, they don't start on a new line — they flow with the surrounding text. Each carries a specific semantic meaning:
<p> This is <strong>critical information</strong> you must read. This is <em>emphasised</em> for stress (like speaking aloud). Search results <mark>highlight</mark> the searched term. <small>Terms and conditions apply.</small> </p> <p>Water is H<sub>2</sub>O and Einstein's formula is E=mc<sup>2</sup>.</p> <p>Sale price: <del>£99</del> <ins>£49</ins></p>
Preformatted Text
The <pre> element preserves whitespace exactly as written in the HTML source — including spaces, tabs, and newlines. It's typically rendered in a monospace font. Perfect for code samples and ASCII art.
<!-- <pre> preserves all whitespace --> <pre> function greet(name) { return `Hello, ${name}!`; } </pre> <!-- <pre> + <code> is the standard combo for code blocks --> <pre><code> for i in range(10): print(i) </code></pre>
| Element | Use case | Whitespace |
|---|---|---|
<p> | Regular paragraphs of text | Collapsed |
<br> | Line break within a paragraph | N/A |
<hr> | Thematic break between sections | N/A |
<pre> | Preformatted text, code samples | Preserved |
<pre><code> | Code blocks (semantic standard) | Preserved |
Create a short article page about "The History of the Internet" that includes:
1. A
<p> with a sentence containing <strong> for the most important point2. A
<p> with <em> to emphasize a key term (first use = italicised by convention)3. A
<p> with a date using <sup> (e.g., "the 21st century")4. A price comparison using
<del> and <ins>5. An address block using
<p> with <br> between lines6. A
<pre><code> block containing a sample command or code snippet7. An
<hr> to separate the main article from a footer section
Show hints
- <strong> and <b> both render bold but strong has semantic meaning
- <em> and <i> both render italic but em has semantic meaning
- Always wrap code inside both <pre> and <code> for best semantics
- <hr> is a self-closing element, no closing tag needed