Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.

The shortcut

For every image, imagine reading the page aloud over the phone. What would you say at the spot where the image sits? That sentence is the alt. If you would say nothing, it is decorative: alt="".

Adding the homepage photo and linksStep 1 of 4
  1. The loaf photo

    Over the phone you would say "a round sourdough loaf with a golden crust". That becomes the alt.

A classic mistake is writing href="www.example.com" without https://. The browser treats that as a relative path on your own site and looks for a file called www.example.com.

Drills

Answer fast — trust the rule.

quick drill

Which href jumps to <section id="opening-hours"> on the same page?

quick drill

What is the best alt for a photo of the bakery's cinnamon buns on the menu page?

quick drill

A link is written <a href="www.bakerynews.com">. What happens when it is clicked?

quick drill

Why give an <img> its width and height?

Remember

  • Every link needs a destination; every image needs a text alternative.
  • Read it aloud over the phone: that sentence is the alt; nothing to say means alt="".
  • Trap: a link without https:// is treated as a path on your own site.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainDestinations and alternatives

The bakery page needs a link to its own menu page, a link to an external map, a link that jumps to the opening hours section, a photo of a cake and a decorative divider. Write the markup for each and explain your choice of href and alt values.