Skip to the workspace
Pebellslearn by building
HTML  ›  Lesson

Links and Images

HTML 13 minLinks need an href that points to an absolute URL, a path on the site or a fragment, and images need alt text that says what they show, or an empty alt when purely decorative.

frontend / Links and Images

Explore each scene at your own pace.

01 · The rule

The rule

Links and Images

The bakery's homepage needs a link to the menu, a link to a map, and a photo of the morning's loaves. Links are what make the web a web, and images are often most of what a page downloads. Each comes with one attribute you must never forget.

The rule

Every link needs a destination; every image needs a text alternative.

Links use the <a> (anchor) element. Its href attribute is the destination:

<a href="https://maps.example.com/crumb">Find us on the map</a>
<a href="/menu">See the menu</a>
<a href="menu.html">See the menu</a>
<a href="#opening-hours">Opening hours</a>
<a href="mailto:hello@crumbbakery.com">Email us</a>
  • An absolute URL includes the scheme and domain: https://maps.example.com/crumb. Use it for other sites.
  • A root-relative path starts with /: /menu means "the menu page on this same site", wherever you are on the site.
  • A relative path has no leading slash: menu.html is looked up next to the current page.
  • A fragment starting with # jumps to the element with that id on the page.
  • mailto: and tel: open email or the phone dialler.

The link text itself matters. "See the menu" tells everyone where it goes. "Click here" says nothing, which is a problem for screen-reader users who often browse a list of links on their own.

Images use the void element <img>:

<img src="images/sourdough.jpg"
     alt="A round sourdough loaf with a deep golden crust"
     width="800" height="600">
  • src is where the file lives, using the same path rules as links.
  • alt is the text alternative: shown if the image fails, read aloud by screen readers, and used by search engines. Describe what the image shows that matters to the page.
  • width and height let the browser reserve space before the file arrives, so the text below does not jump when it loads.

If an image is pure decoration (a swirl between sections, say), write alt="". The empty value tells screen readers to skip it. Leaving alt out entirely is different and worse: some screen readers then read out the file name.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.