Find a course

Module 2: Writing HTML ContentLesson 3 of 1212 min

Text, Headings, Lists and Links

Structure text with headings and paragraphs, add emphasis, build ordered and unordered lists, and create absolute, relative and anchor links.

Step 1 of 16Learn

Headings are an outline, not a font size

HTML has six heading levels, <h1> to <h6>. Browsers display h1 the largest and h6 the smallest, which tempts beginners to choose headings by size: "I want medium text, so I'll use h4." That's a mistake.

Headings describe the outline of your page, like a table of contents:

<h1>Growing Tomatoes</h1>
  <h2>Choosing a variety</h2>
  <h2>Planting</h2>
    <h3>In containers</h3>
    <h3>In the ground</h3>
  <h2>Common problems</h2>

Rules of thumb:

  • Use one h1 per page, describing the whole page.
  • Don't skip levels going down: an h3 should sit under an h2, not straight under the h1.
  • Choose levels by structure, then use CSS to set any size you like.

Why it matters: screen reader users often navigate by jumping from heading to heading, much like sighted users skim. Search engines use headings to understand what a page covers. A page where headings were picked for their looks is confusing for both.

Regular text goes in paragraphs, <p>. Browsers ignore extra spaces and line breaks in your HTML source, so pressing Enter in your editor doesn't create a new paragraph on the page; a new <p> element does.

Step 2 of 16Practice · Spot the mistake

This outline is for a recipe page. Tap the two headings that break good heading structure.

Step 3 of 16Diagram

A well-structured heading outline

Headings nest like a table of contents: one h1, then h2 sections, h3 subsections, never skipping a level.

A well-structured heading outlineHierarchy diagram: h1: Banana Bread, h2: Ingredients, h2: Steps, h2: Tips, h3: Dry ingredients, h3: Wet ingredients, h3: Prepare the pan, h3: Bake.h1: BananaBreadh2:Ingredientsh2: Stepsh2: Tipsh3: Dryingredientsh3: Wetingredientsh3: Preparethe panh3: Bake
h1: Banana Bread
h2: Ingredients
h2: Steps
h2: Tips
h3: Dry ingredients
h3: Wet ingredients
h3: Prepare the pan
h3: Bake

Step 4 of 16Learn

Emphasis and lists

Inside paragraphs, a few elements add meaning to words:

  • <strong> marks strong importance ("Warning: unplug before cleaning"). Browsers show it in bold.
  • <em> marks stress emphasis, the kind that changes how a sentence is read aloud ("I said Tuesday"). Browsers show it in italics.
  • <b> and <i> give bold or italic styling without extra importance, for things like product names or foreign words.

Screen readers may change their voice for strong and em, which is why you should choose by meaning, not by look.

Lists are everywhere on the web, from navigation menus to ingredient lists. There are two main kinds:

<ul>
  <li>Flour</li>
  <li>Bananas</li>
</ul>

<ol>
  <li>Preheat the oven.</li>
  <li>Mash the bananas.</li>
</ol>

An unordered list (ul) shows bullets and is for items where order doesn't matter. An ordered list (ol) shows numbers and is for steps or rankings. Each item is an li (list item), and only li elements can be direct children of ul or ol. To nest a list, put the inner ul inside an li of the outer list.

Step 5 of 16Note

Step 6 of 16Practice · Choose one

Which markup is best for the steps of a recipe?

Step 7 of 16Flashcards

Text elements and what they mean

Tap a card to flip it.

Step 8 of 16Learn

Links: the "hyper" in hypertext

Links are what make the web a web. A link is an a (anchor) element with an href attribute:

<a href="https://www.example.org/">Visit Example</a>

There are three common kinds of link destination:

Absolute URLs include the full address and are used for other websites: href="https://www.example.org/guide".

Relative URLs point to files on your own site, relative to the current file:

  • href="about.html": a file in the same folder.
  • href="blog/post-1.html": a file inside the blog folder.
  • href="../index.html": a file one folder up (.. means "parent folder").

Fragment links jump to an element with a matching id on a page: href="#pricing" goes to <section id="pricing">.

Special links include href="mailto:hello@example.com" (opens an email) and href="tel:+15551234567" (calls on phones).

Write descriptive link text. "Click here" and "read more" tell screen reader users, who often list all links on a page, nothing about the destination. "Download the 2-page price list (PDF)" tells everyone exactly what they'll get.

Step 9 of 16Practice · Match the pairs

Match each href value with what it links to.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. https://www.example.org/
  2. contact.html
  3. ../index.html
  4. #faq
  5. mailto:help@example.com

Step 10 of 16Diagram

Kinds of href values

Kinds of href valuesHierarchy diagram: href, Absolute URL, Relative path, Fragment, mailto:, tel:.hrefAbsoluteURLRelativepathFragmentmailto:tel:

Tap a shape with to see more.

href
Absolute URL

https://example.com/page: another site, or a full address.

Relative path

contact.html or ../images/map.pdf: a file in your own site, found relative to the current page.

Fragment

#prices: jumps to the element with id="prices" on the same page.

mailto:

Opens an email to that address.

tel:

Starts a phone call on mobile devices.

Step 11 of 16Note

Step 12 of 16Note

Step 13 of 16Practice · Code challenge

Write makeLink(url, text) that returns an HTML link string. For example, makeLink("about.html", "About us") returns <a href="about.html">About us</a>.

Runs in a sandbox in your browser.
  • makeLink("about.html", "About us")
  • makeLink("#top", "Back to top")

Step 14 of 16Note

Step 15 of 16Practice · True or false

"Click here" is good link text because everyone knows what it means.

Step 16 of 16Practice · Fill in the blanks

Fill in the blanks

An unordered list uses the element, an ordered list uses , and each item in either list uses .