Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14
Chapter 2

Text, Headings, Inline Elements & Entities

Paragraphs, line breaks, headings, semantic inline elements and character entities.


Paragraphs & Line Breaks

<p>This is the first paragraph. The browser wraps it automatically.</p>
<p>This is the second paragraph. It starts on a new line.</p>
  • <p> creates a block of text with top and bottom margin; the browser adds spacing automatically; the closing tag is required in HTML5.
  • <br> inserts a single line break within a block. It is a void element. Use sparingly — prefer CSS margin for spacing.
  • <pre> preserves whitespace and line breaks exactly as typed; used for code samples and ASCII art.
  • <hr> draws a thematic break / dividing line. Void element.

Block vs Inline

  • Block: <p>, <div> — full width, start on a new line.
  • Inline: <span>, <a>, <strong>, <em> — flow within text.

Headings — <h1> to <h6>

<h1>Page Title</h1>
<h2>Chapter 1</h2>
<h3>Section</h3>

Usage rules (2025 best practice)

  • Only one <h1> per page — it is the main topic.
  • Don't skip levels (h1 → h3 breaks accessibility).
  • Use headings for structure, not for visual sizing.
  • Screen readers use headings for page navigation.
  • Don't use <b> or <strong> instead of headings.

Inline & Semantic Elements

ElementMeaning
<strong>Bold + semantic importance
<em>Italic + semantic emphasis
<code>Inline code snippet
<abbr>Abbreviation with tooltip
<sub> / <sup>Subscript / superscript
<del> / <ins>Deleted (strikethrough) / inserted text
<mark>Highlighted text (HTML5)
<time>Machine-readable date/time
<small>Fine print / legal text
<span>Generic inline container for CSS

Obsolete: <b>, <i>, <big>, <tt>, <font>. Use <strong>, <em> and CSS instead.

Character Entities

Some characters have special meaning in HTML and must be encoded as entities.

CharacterNamed entity
Less than <&lt;
Greater than >&gt;
Ampersand &&amp;
Double quote "&quot;
Apostrophe '&apos;
Copyright ©&copy;
Registered ®&reg;
Trademark ™&trade;
Euro € / Pound £&euro; / &pound;
Non-break space&nbsp;
Em dash —&mdash;

Always encode <, > and & in text content. Full reference: https://html.spec.whatwg.org/multipage/named-characters.html

Activity — complete the code

Complete the code correctly to mark this lesson as complete automatically.

Complete the text-formatting example with the correct tags.

Main Title</h1>
<h2>Subtitle</h2>
<p>This is <>important</strong> and <em>emphasised</em>.</p>
<p>The <> element marks text as code.</p>