Find a course

Module 2: HTML Building BlocksLesson 3 of 1111 min

Headings, Paragraphs and Lists

Structure text the way readers and search engines expect, using six heading levels, paragraphs, emphasis and two kinds of lists.

Step 1 of 12Learn

Headings are an outline, not a font size

Leo wanted big text at the top of his gaming page, so he used <h3> because it "looked about right." Then he used <h1> further down for a small note because he liked its boldness. The page looked fine to him. But a screen reader user jumping between headings heard a confusing outline, and search engines couldn't tell what the page was about.

HTML has six heading levels, <h1> through <h6>. They describe importance and structure, like an outline in a school report:

<h1>Leo's Game Reviews</h1>
  <h2>Puzzle Games</h2>
    <h3>Block Builder</h3>
    <h3>Color Match</h3>
  <h2>Racing Games</h2>

The rules of thumb:

  • Use one <h1> per page for its main title.
  • Don't skip levels going down: an <h2> section contains <h3>s, not <h5>s.
  • Choose the level by meaning, then change the size with CSS if you don't like how it looks.

That last point is the big lesson. HTML says what something is. CSS decides how it looks. Mixing the two jobs makes pages harder to read for people and machines alike.

Step 2 of 12Practice · Put in order

Arrange these headings for a school club page from the top of the outline to the most detailed level.

Drag the items, or use the arrow buttons, to put them in order.

  1. <h3>Line-Following Robot</h3>
  2. <h4>Parts List</h4>
  3. <h2>Our Projects</h2>
  4. <h1>Robotics Club</h1>

Step 3 of 12Diagram

Headings form an outline

Headings form an outlineHierarchy diagram: h1: Robotics Club, h2: About us, h2: Events, h2: How to join, h3: Weekly meetings, h3: Competitions.h1: Robotics Clubh2: About ush2: Eventsh2: How to joinh3: Weeklymeetingsh3: Competitions
One h1 per page; never skip a level just to get a smaller font.
h1: Robotics Club
h2: About us
h2: Events
h2: How to join
h3: Weekly meetings
h3: Competitions

Step 4 of 12Learn

Paragraphs, emphasis and line breaks

Normal text goes in <p> elements, one per paragraph. A surprise for beginners: pressing Enter in your HTML file does not create a new line on the page. Browsers collapse all spaces and line breaks in your code into a single space. So this:

<p>I love
     drawing     dragons.</p>

shows up as "I love drawing dragons." on one line. To start a new paragraph, close the <p> and open another. For a line break inside a paragraph, like in a poem or address, use <br>, but don't use stacks of <br> to create space; that's CSS's job.

To mark words as important or stressed, use:

  • <strong> for strong importance ("Do not share your password"). Browsers show it bold.
  • <em> for emphasis that changes the meaning, as when you stress a word while speaking ("I said the blue one"). Browsers show it in italics.

Screen readers can change their voice for these, which is why they're better than tags that only change appearance.

Step 5 of 12Practice · True or false

If you press Enter three times between two sentences inside one p element, the browser shows two blank lines between them.

Step 6 of 12Compare

What you type vs what the browser shows

AspectIn your HTML fileOn the page
Pressing EnterA new line in the codeJust a space
Five spaces in a rowFive spacesOne space
<br>A line-break tagA new line
A new <p>A new paragraph elementA new paragraph with space above

Step 7 of 12Learn

Two kinds of lists

Lists are everywhere on the web: navigation menus, recipes, top-ten rankings, feature lists. HTML has two main kinds.

An unordered list <ul> is for items where order doesn't matter. Browsers show bullet points:

<ul>
  <li>Sketchbook</li>
  <li>Pencils</li>
  <li>Eraser</li>
</ul>

An ordered list <ol> is for steps or rankings where order matters. Browsers number the items automatically, so if you insert a new step in the middle, the numbers update themselves:

<ol>
  <li>Preheat the oven</li>
  <li>Mix the batter</li>
  <li>Bake for 20 minutes</li>
</ol>

In both cases, every item is an <li> (list item), and only <li> elements may sit directly inside <ul> or <ol>. You can put a whole new list inside an <li> to create sub-points. Navigation menus on most professional sites are secretly unordered lists of links, styled with CSS to sit in a row.

Step 8 of 12Compare

Unordered vs ordered lists

Aspect<ul><ol>
ShowsBulletsNumbers
Use whenOrder does not matterOrder matters
ExamplesMenu links, features, ingredientsRecipe steps, top-ten list, directions
Items<li> elements<li> elements

Step 9 of 12Practice · Sort into groups

Ordered list or unordered list?

Tap an item, then tap its group (or drag it there).

Step 10 of 12Note

Step 11 of 12Practice · Code challenge

Write a function makeList(items) that takes an array of strings and returns an unordered list as one string, with no spaces or line breaks. For example, makeList(["a", "b"]) returns "<ul><li>a</li><li>b</li></ul>".

Runs in a sandbox in your browser.
  • makeList(["a", "b"])
  • makeList(["Sketchbook", "Pencils", "Eraser"])
  • makeList([])

Step 12 of 12Practice · Choose one

Sam wants the subtitle under his main page title to look smaller. Which approach is best?