Lesson 3 +10 XP

Headings and Text

Text is the heart of the web. Let's learn how to make headings and paragraphs.

Headings: h1 to h6

Headings are like titles in a book. There are six sizes:

  • <h1>: the biggest, most important title (usually one per page)
  • <h2>: section titles
  • <h3>: sub-section titles
  • ...all the way down to...
  • <h6>: the smallest
Code

html
<h1>My Story</h1>
<h2>Chapter One</h2>
<h3>Part One</h3>

Think of it like a family tree: h1 is the grandpa title, and each smaller heading is a child beneath it. Don't skip levels: go 1, 2, 3 in order!

Paragraphs: &lt;p&gt;

Paragraphs are for chunks of text. Browsers put a little space before and after each one.

Code

html
<p>This is one paragraph.</p>
<p>This is another paragraph.</p>

Line breaks: &lt;br&gt;

&lt;br&gt; makes a new line without starting a new paragraph. It's like pressing Enter inside a sentence. It has no closing tag!

Code

html
<p>First line<br>Second line</p>

Horizontal rule: &lt;hr&gt;

&lt;hr&gt; draws a straight line across the page. It's like a divider between sections.

Code

html
<p>Part one</p>
<hr>
<p>Part two</p>

Whitespace

  • Here's a secret: HTML squashes extra spaces and newlines into one space. So:
Code

html
<p>Hello      there!</p>

shows up as &quot;Hello there!&quot;

If you really want to keep spaces and line breaks, use &lt;pre&gt; (preformatted text): it keeps everything exactly as you type it, like a typewriter.

TL;DR

  • &lt;h1&gt; to &lt;h6&gt; are headings, biggest to smallest.
  • &lt;p&gt; is a paragraph.
  • &lt;br&gt; makes a line break (no closing tag).
  • &lt;hr&gt; makes a divider line.
  • &lt;pre&gt; keeps spaces and line breaks.