edubun
English
1 / 15

4 / 10 · Intro

Links

The H in HTML stands for hypertext: text that links to other text. One element, a, makes every link on the web.

Jump to the 10 practice questions

You will learn

  • Choose absolute, relative and same-page addresses
  • Write link text that says where the link goes

Before this: Headings and paragraphs

1Explain

The anchor element

A link is made with the <a> element, short for anchor. Its href attribute holds the address to go to, and its content is the text people click. In <a href="https://developer.mozilla.org/">MDN Web Docs</a>, the words MDN Web Docs appear underlined, and activating them loads that address. Links work with a mouse, a finger, or the keyboard: press Tab to move from link to link and Enter to follow one.

Your code
<p>Read the <a href="https://developer.mozilla.org/">MDN guide</a>.</p>
Preview

2Explain

Absolute and relative addresses

An absolute URL contains everything: the scheme (https:), the domain and the path, for example https://example.com/menu/bread.html. Use it for links to other sites. A relative URL leaves out the parts that are the same as the current page. On a page at https://example.com/menu/index.html, the link bread.html means the file in the same folder, ../about.html means one folder up, and /contact.html starts from the root of the site.

<a href="https://www.w3.org/">W3C</a>          <!-- another site -->
<a href="bread.html">Bread</a>                <!-- same folder -->
<a href="../about.html">About us</a>          <!-- one folder up -->
<a href="#hours">Opening hours</a>           <!-- same page -->
<a href="mailto:hello@example.com">Email us</a>

<h2 id="hours">Opening hours</h2>

Five kinds of link target. The last line is the element that #hours jumps to.

3Problem

A relative address

On https://example.com/menu/index.html, where does bread.html point?

Hint

A relative address starts from the folder of the current page.

Solution

Answer: https://example.com/menu/bread.html

A plain file name is relative to the current folder, /menu/.

4Problem

One folder up

On the same page, where does ../about.html point?

Hint

.. means the folder above.

Solution

Answer: https://example.com/about.html

../ goes up one folder, from /menu/ to the root.

5Explain

Links inside the same page

Give any element an id, and a link whose href is a hash followed by that id jumps straight to it. <a href="#hours"> scrolls to <h2 id="hours">. An id must be unique within the page and cannot contain spaces. Long articles use this for a table of contents.

Click the link in the preview: it jumps to the element whose id matches.

Your code
<p><a href="#hours">Opening hours</a></p>
<p style="height:260px">Scroll down…</p>
<h2 id="hours">Opening hours</h2>
<p>Daily from 7 am.</p>
Preview

6Problem

href="#prices"

What does href="#prices" link to?

Hint

A hash links to an id on the same page.

Solution

Answer: The element with id="prices" on this page

A hash plus an id is a fragment link within the page.

7Problem

A jump that does not work

<p>
  <a href="#Hours">Opening hours</a>
</p>
<h2 id="hours">Opening hours</h2>

Clicking the link does not jump to the heading. Why?

Hint

Compare the two spellings letter by letter.

Solution

Answer: #Hours and hours differ in capital letters

The part after # must match the id exactly, capital letters included. Write href="#hours".

8Explore

Email, phone, downloads and link text

target="_blank" opens the link in a new tab. Use it sparingly: it takes control away from the visitor, and the Back button no longer brings them back. When you do use it, mention it in the link text, for example (opens in a new tab). Most important of all is the link text itself. Screen reader users often pull up a list of every link on a page, and a list of ten entries that all say click here or read more tells them nothing.

Compare the link texts: the first three say where they lead; click here says nothing when read on its own.

Tap a choice: the code and the preview change together.

Link
<p><a href="mailto:hello@example.com">Email the bakery</a></p>
Preview

9Problem

The best link text

Which link text is best?

Hint

Imagine hearing only the link text in a list of links.

Solution

Answer: Download the 2026 timetable

It makes sense even in a list of links with no surrounding text.

10Problem

Real links

<p>
  <a href="#hours">Hours</a> ·
  <a>Prices</a> ·
  <a href="tel:+12025550123">Call</a>
</p>

How many of these a elements are links that can be followed?

Hint

A link needs an address.

Solution

Answer: 2

The first and the last a have href. An a without href is only a placeholder, not a link, so the answer is 2.

11Problem

A phone link

Which href makes a link that starts a phone call?

Hint

It is short for telephone.

Solution

Answer: tel:+12025550123

tel: is the scheme for phone numbers, like mailto: for email. On a phone, tapping the link offers to call.

12Practice

A link out and a link in

Make MDN a link to https://developer.mozilla.org/. Give the FAQ heading id="faq" and make the FAQ in the second line a link to it.

Checks
  • link to MDN
  • id="faq" on the heading
  • link to #faq
Your code
<p>Read the HTML guide on MDN.</p>
<p>Jump to the FAQ.</p>

<h2>Lessons</h2>
<p>Ten short units.</p>

<h2>FAQ</h2>
<p>Is it free? Yes.</p>
Preview
Hint

The same-page link needs both parts: href="#faq" on the link and id="faq" on the heading.

A solution
<p>Read the HTML guide on <a href="https://developer.mozilla.org/">MDN</a>.</p>
<p>Jump to the <a href="#faq">FAQ</a>.</p>

<h2>Lessons</h2>
<p>Ten short units.</p>

<h2 id="faq">FAQ</h2>
<p>Is it free? Yes.</p>

13Practice

An email link

Replace the vague link with one that opens an email to hello@example.com and whose text says Email the bakery.

Checks
  • mailto link
  • clear link text
Your code
<p>Questions? <a href="#">Click here</a>.</p>
Preview
Hint

href starts with mailto: and the link text says what happens.

A solution
<p>Questions? <a href="mailto:hello@example.com">Email the bakery</a>.</p>

14Explain

Common mistakes

Mistake
<p><a href="faq">FAQ</a></p>
<h2 id="faq">FAQ</h2>
Fixed
<p><a href="#faq">FAQ</a></p>
<h2 id="faq">FAQ</h2>

Without the hash, the browser looks for a file called faq instead of the heading on this page.

15

Summary

  • a + href makes a link; the content is the clickable text.
  • Absolute URLs for other sites, relative URLs inside your site, #id for the same page.
  • Write link text that makes sense on its own.

Next unitImages and alt text
Full text · The whole lesson as one text

The anchor element

A link is made with the <a> element, short for anchor. Its href attribute holds the address to go to, and its content is the text people click. In <a href="https://developer.mozilla.org/">MDN Web Docs</a>, the words MDN Web Docs appear underlined, and activating them loads that address. Links work with a mouse, a finger, or the keyboard: press Tab to move from link to link and Enter to follow one. Without href, an <a> is only a placeholder and cannot be reached with Tab.

Absolute and relative addresses

An absolute URL contains everything: the scheme (https:), the domain and the path, for example https://example.com/menu/bread.html. Use it for links to other sites. A relative URL leaves out the parts that are the same as the current page. On a page at https://example.com/menu/index.html, the link bread.html means the file in the same folder, ../about.html means one folder up, and /contact.html starts from the root of the site. Relative links keep working when the whole site moves to a new domain.

<a href="https://www.w3.org/">W3C</a>          <!-- another site -->
<a href="bread.html">Bread</a>                <!-- same folder -->
<a href="../about.html">About us</a>          <!-- one folder up -->
<a href="#hours">Opening hours</a>           <!-- same page -->
<a href="mailto:hello@example.com">Email us</a>

<h2 id="hours">Opening hours</h2>
Five kinds of link target. The last line is the element that #hours jumps to.

Links inside the same page

Give any element an id, and a link whose href is a hash followed by that id jumps straight to it. <a href="#hours"> scrolls to <h2 id="hours">. An id must be unique within the page and cannot contain spaces. Long articles use this for a table of contents. Many sites also put a skip link at the very top (Skip to main content) so keyboard users do not have to Tab through the whole menu on every page.

Email, phone and downloads

Other schemes open other programs. mailto:hello@example.com opens a new email in the visitor's mail program, and tel:+82212345678 offers to call the number on a phone. Adding the download attribute to a link asks the browser to save the file instead of opening it. These links are convenient, but say what they do in the link text, because people do not expect a mail program to pop up.

New tabs and good link text

target="_blank" opens the link in a new tab. Use it sparingly: it takes control away from the visitor, and the Back button no longer brings them back. When you do use it, mention it in the link text, for example (opens in a new tab). Most important of all is the link text itself. Screen reader users often pull up a list of every link on a page, and a list of ten entries that all say click here or read more tells them nothing. Write text that makes sense out of context: Download the 2026 timetable, not click here.

Browsers underline links and colour them blue by default, and show visited links in purple. You can restyle links with CSS, but keep something other than colour alone, such as the underline, so that people who cannot tell the colours apart still see which words are links. When a link has keyboard focus, browsers draw a focus ring around it; never remove that ring without putting a clear replacement in its place.

Key points
  • a + href makes a link; the content is the clickable text.
  • Absolute URLs for other sites, relative URLs inside your site, #id for the same page.
  • Write link text that makes sense on its own.

Practice questions from Links on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (9)
  • WHATWG, HTML Living Standard (html.spec.whatwg.org, checked 2026-10-17)
  • MDN Web Docs, Learn web development: Structuring content with HTML, and the HTML element reference (developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content and developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements, checked 2026-10-17)
  • MDN, HTML images (alt text guidance, checked 2026-10-17)
  • W3C WAI, Images tutorial and alt decision tree (w3.org/WAI/tutorials/images/decision-tree, checked 2026-10-17)
  • CERN, A short history of the Web (home.cern/science/computing/the-birth-of-the-web/short-history-web/, checked 2026-10-17)
  • W3C and WHATWG memorandum of understanding, 28 May 2019 (w3.org/2019/04/WHATWG-W3C-MOU.html, checked 2026-10-17)
  • W3C, Using ARIA, first rule of ARIA use (w3.org/TR/using-aria/, checked 2026-10-17)
  • W3C Markup Validation Service (validator.w3.org, checked 2026-10-17)
  • MDN, Viewport meta element (checked 2026-10-17).

Checked: 2026-10-17