Lesson 4 of 12

HTML Headings, Paragraphs and Formatting

Most of the web is text, and well-structured text is easier to read, easier to search and easier for assistive technology to understand. In this lesson you will use HTML headings to build an outline, paragraphs to hold your writing, and a handful of formatting elements that add meaning to individual words. You will use the element and attribute rules from HTML Elements and Attributes throughout.

HTML headings: h1 to h6

HTML has six heading levels, from <h1> (most important) to <h6> (least important). Together they form an outline of the page, much like the chapter and section titles in a textbook.

  • Use one <h1> for the main topic of the page. This is a widely followed best practice that keeps the outline clear.
  • Go down one level at a time. After an <h2>, the next sub-heading should be an <h3>, not an <h5>.
  • You can jump back up to any higher level whenever a new section starts.
  • Never choose a heading level for its size. If an <h3> looks too big, change its size with CSS.
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Travel guide</title>
</head>
<body>
  <h1>A weekend in Hampi</h1>

  <h2>Getting there</h2>
  <p>The nearest railway station is Hosapete, about 13 km away.</p>

  <h2>What to see</h2>

  <h3>Virupaksha Temple</h3>
  <p>A working temple that is still visited by pilgrims every day.</p>

  <h3>Vittala Temple</h3>
  <p>Famous for its stone chariot and musical pillars.</p>

  <h2>Where to stay</h2>
  <p>Guest houses are available in Hampi Bazaar and across the river.</p>
</body>
</html>

Tip: Screen reader users often jump from heading to heading to scan a page, just as sighted users skim the bold titles. A logical order of HTML headings makes your page usable for them.

Paragraphs, line breaks and thematic breaks

The <p> element holds a paragraph – a block of related sentences. Browsers add space above and below each paragraph by default, so you never need empty paragraphs or repeated line breaks to create gaps. Spacing is a job for CSS.

The <br> element inserts a line break inside a block of text. Use it only where the line break is part of the content itself, such as a postal address or the lines of a poem. The <hr> element marks a thematic break – a change of topic or scene – and browsers show it as a horizontal line.

Formatting elements with meaning

HTML has several elements that change how words look, but each one also carries a meaning. Pick the element for the meaning; the default look is just a hint.

ElementMeaningDefault look
<strong>Strong importance, seriousness or urgencyBold
<em>Stress emphasis that changes how a sentence is readItalic
<b>Draws attention without extra importance, e.g. product names in a reviewBold
<i>Text in an alternate voice: foreign words, technical terms, thoughtsItalic
<mark>Highlighted because it is relevant in the current context, e.g. search matchesYellow background
<small>Side comments and fine printSmaller text
<sub> / <sup>Subscript and superscript, e.g. H₂O and 10²Lowered / raised
<del> / <ins>Text removed from or added to a documentStruck through / underlined
<abbr>An abbreviation, with the full form in its titleSometimes dotted underline
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Formatting</title>
</head>
<body>
  <p><strong>Warning:</strong> the ghat road is closed after 6 pm.</p>
  <p>I <em>never</em> said the dosa was cold.</p>
  <p>The word <i lang="ta">kolam</i> means a floor pattern drawn with rice flour.</p>
  <p>Search results for "idli": soft <mark>idli</mark> with sambar.</p>
  <p>Price: <del>₹250</del> <ins>₹199</ins> <small>(taxes extra)</small></p>
  <p>Water is H<sub>2</sub>O and 5<sup>2</sup> = 25.</p>
  <p>The <abbr title="Indian Space Research Organisation">ISRO</abbr> headquarters is in Bengaluru.</p>
</body>
</html>

Notice the difference between <strong> and <b>. Both are bold by default, but only <strong> says “this matters”. The same goes for <em> and <i>. If you only want bold styling with no extra meaning, a <span> with a CSS class is often the cleanest choice; you will learn text styling in CSS Text and Fonts.

Watch out: The old <font>, <center> and <big> elements are obsolete. Do not use them – control fonts, alignment and sizes with CSS.

Quotations, code and preformatted text

For longer quotations from another source, use <blockquote>; browsers indent it by default. Short inline quotes go in <q>, which adds quotation marks automatically. The <cite> element marks the title of a creative work, such as a book or film.

For technical writing, <code> marks a fragment of computer code and <kbd> marks keyboard input. The <pre> element displays text exactly as written, keeping every space and line break – useful for code blocks or ASCII art.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Quotes and code</title>
</head>
<body>
  <blockquote>
    <p>Arise, awake, and stop not till the goal is reached.</p>
  </blockquote>
  <p>— Swami Vivekananda</p>

  <p>My favourite novel is <cite>Ponniyin Selvan</cite>.</p>
  <p>My friend said <q>let us meet at the beach at five</q>.</p>

  <p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save, then use the <code><p></code> element.</p>

  <pre>
  Line one
      Line two, indented
  Line three
  </pre>
</body>
</html>

Notice the &lt; in the last example. Because < starts a tag, you write it as the character reference &lt; when you want to show it as text. Similarly, &gt; shows > and &amp; shows an ampersand.

Text is rarely useful on its own – it needs to connect to other pages. That is the subject of the next lesson, HTML Links.

Further reading

Key takeaways

  • Use <h1>–<h6> to build a logical outline: one main heading, no skipped levels, never chosen for size.
  • <p> holds paragraphs; use <br> only where line breaks are part of the content.
  • <strong> and <em> add importance and emphasis; <b> and <i> are for styling-like conventions without extra importance.
  • <blockquote>, <q>, <cite>, <code>, <kbd> and <pre> describe quotes and technical text.
  • Write &lt;, &gt; and &amp; to show those characters as text.

Quick quiz

Check what you learned – pick an answer.

1. After an <h2>, which heading should a sub-section use?

2. Which element marks text as seriously important, such as a safety warning?

3. Which element keeps all spaces and line breaks exactly as typed?

Practice exercise

Write a short recipe page for "Rava Upma" with an h1, an h2 called "Tips", a paragraph where the word "always" is emphasised and "roast the rava first" is marked as important, and a small note "(serves 2)".

Show a hint

Use <em> for emphasis, <strong> for importance and <small> for the side note.

Show the solution
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Rava Upma</title>
</head>
<body>
  <h1>Rava Upma <small>(serves 2)</small></h1>
  <p>A quick, filling breakfast from South India.</p>
  <h2>Tips</h2>
  <p>You should <em>always</em> <strong>roast the rava first</strong>, so the upma does not turn lumpy.</p>
</body>
</html>

Progress is saved in this browser only.