Skip to main content

✏️ Lesson 5: Text & Headings

Every web page is built on text. Before you can style anything, you need to know how to structure words on a page — with headings that organize, paragraphs that group ideas, and inline elements that add meaning.

🎯 Learning Objectives

By the end of this lesson, you will be able to:

  • Use all six heading levels (<h1> through <h6>) to create a clear content hierarchy
  • Write paragraphs with the <p> element
  • Add emphasis with <em> and strong importance with <strong>
  • Insert line breaks with <br> and thematic separators with <hr>
  • Understand why HTML structure matters for accessibility and SEO

Estimated Time: 40 minutes

Hands-on: You'll build a structured "About Me" page using only text elements.

📑 In This Lesson

Why Text Structure Matters

Open any news article, textbook, or blog post. You'll notice it's not just a wall of text — it has a title, subheadings, and paragraphs that break the content into digestible pieces. That structure isn't just for looks. It serves three audiences:

  • Readers can scan headings to find what they need instead of reading everything
  • Screen readers use headings to let visually impaired users jump between sections — like a table of contents they can navigate by voice
  • Search engines use headings to understand what your page is about, which affects how it appears in search results

In HTML, you don't just make text bigger to create a heading — you use a heading element that tells the browser (and everyone else) "this is a heading." The visual appearance is secondary; the meaning is what counts.

graph LR A["HTML Text Elements"] --> B["Headings
h1 – h6"] A --> C["Paragraphs
p"] A --> D["Inline Emphasis
em, strong"] A --> E["Separators
br, hr"] style A fill:#eff6ff,stroke:#3b82f6,stroke-width:2px,color:#1e293b style B fill:#fdf4ff,stroke:#a855f7,stroke-width:2px,color:#1e293b style C fill:#f0fdf4,stroke:#22c55e,stroke-width:2px,color:#1e293b style D fill:#fffbeb,stroke:#f59e0b,stroke-width:2px,color:#1e293b style E fill:#fef2f2,stroke:#ef4444,stroke-width:2px,color:#1e293b

Heading Levels: h1 through h6

HTML provides six levels of headings, from <h1> (the most important) down to <h6> (the least important):

<h1>Main Page Title</h1>
<h2>Major Section</h2>
<h3>Subsection</h3>
<h4>Sub-subsection</h4>
<h5>Minor heading</h5>
<h6>Smallest heading</h6>

By default, browsers render these in decreasing sizes — <h1> is the largest and <h6> is the smallest. But remember: you're not choosing heading levels for their size. You're choosing them for their importance in the page hierarchy. You'll change sizes later with CSS.

The Heading Hierarchy

Think of headings like a document outline. You wouldn't put a sub-sub-section before a section, and you shouldn't skip heading levels either:

graph TD A["h1: My Travel Blog"] --> B["h2: Europe Trip"] A --> C["h2: Asia Trip"] B --> D["h3: Paris"] B --> E["h3: Rome"] C --> F["h3: Tokyo"] C --> G["h3: Seoul"] D --> H["h4: Eiffel Tower"] D --> I["h4: Louvre Museum"] style A fill:#eff6ff,stroke:#3b82f6,stroke-width:2px,color:#1e293b style B fill:#fdf4ff,stroke:#a855f7,stroke-width:2px,color:#1e293b style C fill:#fdf4ff,stroke:#a855f7,stroke-width:2px,color:#1e293b style D fill:#f0fdf4,stroke:#22c55e,stroke-width:1px,color:#1e293b style E fill:#f0fdf4,stroke:#22c55e,stroke-width:1px,color:#1e293b style F fill:#f0fdf4,stroke:#22c55e,stroke-width:1px,color:#1e293b style G fill:#f0fdf4,stroke:#22c55e,stroke-width:1px,color:#1e293b style H fill:#f8fafc,stroke:#64748b,stroke-width:1px,color:#1e293b style I fill:#f8fafc,stroke:#64748b,stroke-width:1px,color:#1e293b

Rules of Thumb

💡 Heading Best Practices

  • One <h1> per page. This is your main title. Search engines treat it as the most important text on the page.
  • Don't skip levels. Go from <h2> to <h3>, not from <h2> to <h4>. Skipping confuses screen readers and weakens your document outline.
  • Don't use headings just for size. If you want bigger text, use CSS. Headings carry meaning, not just style.

⚠️ Common Mistake

Beginners often use <h1> or <h2> everywhere because the text looks big and bold. But a page with five <h1> tags is like a book where every chapter is titled "Chapter 1" — it tells the browser (and search engines) nothing useful about the page structure.

Paragraphs

The <p> element defines a paragraph — a block of related text separated from surrounding content by vertical space:

<p>This is a paragraph. It can contain as many
   sentences as you want. The browser will wrap
   the text to fit the window width.</p>

<p>This is a second paragraph. Notice how the
   browser adds space between them automatically.</p>

White Space Collapsing

Here's something that surprises everyone the first time: HTML collapses white space. No matter how many spaces, tabs, or line breaks you put in your source code, the browser treats them all as a single space.

<!-- You type this: -->
<p>Hello      World!

   How    are      you?</p>

<!-- Browser displays: "Hello World! How are you?" -->

All those extra spaces and the blank line between sentences? Gone. The browser collapses them into single spaces and removes the line break entirely. This is called white space collapsing, and it means you can't create visual spacing just by pressing Enter or Space. You'll use CSS for spacing (or the <br> element for intentional line breaks — more on that below).

💡 Why Does HTML Collapse White Space?

Because HTML is about structure, not presentation. If every space and newline in your code appeared on screen, formatting your code neatly would wreck the page layout. White space collapsing lets you indent and organize your code however you like without affecting what the user sees.

Emphasis and Importance

Sometimes you need to call attention to specific words within a paragraph. HTML gives you two elements for this:

<em> — Emphasis

The <em> element marks text that has stress emphasis — as if you're stressing that word when speaking aloud:

<p>You need to submit the form <em>before</em> Friday.</p>
<p>I <em>never</em> said that.</p>

Browsers render <em> in italics by default. But the point isn't the italics — it's the meaning. Screen readers change their tone of voice when they encounter <em>, emphasizing the word audibly.

<strong> — Strong Importance

The <strong> element marks text of strong importance — content that is serious, urgent, or critical:

<p><strong>Warning:</strong> Do not delete this file.</p>
<p>The deadline is <strong>absolutely final</strong>.</p>

Browsers render <strong> in bold by default. Again, the styling is secondary — what matters is the semantic meaning.

Nesting <em> and <strong>

You can combine them for text that's both emphasized and important:

<p><strong><em>Do not</em> touch the red button.</strong></p>

⚠️ <b> and <i> — The Old Way

You'll sometimes see <b> (bold) and <i> (italic) in older code. These still work, but they're purely visual — they don't convey any meaning. Prefer <strong> and <em> because they tell browsers, screen readers, and search engines why the text is different, not just how it looks.

There are edge cases where <b> and <i> are appropriate (like a ship name in italics or a keyword in a technical definition), but when in doubt, use <strong> and <em>.

Line Breaks and Horizontal Rules

<br> — Line Break

The <br> element forces a line break within a block of text. It's a void element — no closing tag needed:

<p>
    Roses are red,<br>
    Violets are blue,<br>
    HTML is fun,<br>
    And so are you.
</p>

Use <br> when a line break is part of the content itself — poetry, song lyrics, addresses, or anywhere the break carries meaning:

<p>
    123 Main Street<br>
    Springfield, IL 62701<br>
    United States
</p>

⚠️ Don't Abuse <br>

Never use <br><br> to create space between paragraphs. That's what separate <p> elements are for. And never use repeated <br> tags to push content down the page — that's a job for CSS margins and padding.

<hr> — Horizontal Rule (Thematic Break)

The <hr> element creates a thematic break — a visible horizontal line that signals a shift in topic or section. Like <br>, it's a void element:

<p>That concludes our discussion of headings.</p>

<hr>

<p>Now let's talk about something completely different.</p>

Think of <hr> like the * * * separator you see in novels between scenes. It means "we're changing topics." Don't use it as a decorative line — if you just want a line, use CSS borders.

Putting It All Together

Here's a complete example using every element from this lesson:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>About Me</title>
</head>
<body>
    <h1>About Alex Johnson</h1>
    <p>Welcome to my personal page! I'm a student learning
       <strong>web development</strong> from scratch.</p>

    <h2>Background</h2>
    <p>I started coding in <em>January 2026</em> with no
       prior experience. My goal is to build a portfolio
       website by the end of this course.</p>

    <p><strong>Fun fact:</strong> I once tried to learn
       HTML from a YouTube video and gave up after 10
       minutes. This course is <em>much</em> better.</p>

    <hr>

    <h2>Contact</h2>
    <p>You can reach me at:</p>
    <p>
        Alex Johnson<br>
        123 Web Dev Lane<br>
        Codeville, TX 75001
    </p>
</body>
</html>

Notice how the document flows naturally: one <h1> for the main title, <h2> headings for sections, paragraphs for content, <strong> and <em> for inline emphasis, <hr> for a topic shift, and <br> for address formatting.

Hands-on Exercise

🏋️ Exercise: Build a Structured Profile Page

Objective: Create a page that uses headings, paragraphs, emphasis, line breaks, and a horizontal rule.

Instructions:

  1. In your my-website folder, open about.html (or create it if you haven't)
  2. Use the Emmet shortcut (! + Tab) if starting fresh
  3. Set the <title> to "About Me"
  4. Add the following content inside <body>:
    • An <h1> with your name
    • A <p> introducing yourself, with at least one word wrapped in <strong>
    • An <h2> for "My Interests"
    • Two or more <p> paragraphs describing your interests, with at least one word wrapped in <em>
    • An <hr> to separate the content from a contact section
    • An <h2> for "Contact"
    • A <p> containing a mailing address formatted with <br> tags
  5. Save and view in the browser with Live Server
💡 Hint

Use only one <h1> at the top of the page. The sections underneath should use <h2>. If you needed to subdivide a section, you'd use <h3> — but that's not required for this exercise.

✅ Example Solution
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>About Me</title>
</head>
<body>
    <h1>Jordan Rivera</h1>
    <p>Hi there! I'm Jordan, a <strong>web development
       student</strong> who is learning to build websites
       from the ground up.</p>

    <h2>My Interests</h2>
    <p>I spend most of my free time drawing and painting.
       I'm <em>especially</em> interested in digital
       illustration and hope to combine art with code
       someday.</p>

    <p>I also enjoy board games, hiking, and trying out
       new recipes in the kitchen. My latest obsession
       is <em>sourdough bread</em> — my third attempt
       was <strong>finally</strong> edible.</p>

    <hr>

    <h2>Contact</h2>
    <p>
        Jordan Rivera<br>
        456 Pixel Avenue<br>
        Webtown, CA 90210
    </p>
</body>
</html>

🎯 Quick Quiz

Question 1: How many <h1> headings should a page have?

Question 2: What happens when you put 10 spaces between two words in HTML?

Question 3: What's the difference between <em> and <i>?

Question 4: When should you use <br>?

Summary

🎉 Key Takeaways

  • <h1> through <h6> create a heading hierarchy — use one <h1> per page and don't skip levels
  • <p> defines a paragraph — the browser adds spacing between paragraphs automatically
  • HTML collapses all consecutive spaces and line breaks into a single space (white space collapsing)
  • <em> marks emphasized text (renders italic); <strong> marks important text (renders bold) — both carry semantic meaning
  • Prefer <em>/<strong> over <i>/<b> for meaning, not just appearance
  • <br> inserts a line break within content; <hr> creates a thematic break between sections
  • Both <br> and <hr> are void elements — no closing tag needed

📁 Your Project So Far

my-website/
├── index.html     ← homepage (from Lesson 4)
└── about.html     ← profile page (updated in this lesson)

🚀 What's Next?

You now know how to structure text — but a page with only text and headings would be pretty boring. In the next lesson, you'll learn how to connect pages together with links and make your content visual with images. These two elements are what make the web a web.