Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 122 ยท Links and Navigation

Links in Depth

Master the HTML a element. Learn the kinds of href values, how to write link text people can trust, image links, the title attribute and when to use a button.

Links are the reason the web is a web. A single element, <a>, connects every page to every other page on the internet, and it is probably the element you will write most often after <p>.

You met href briefly in the Attributes lesson. This lesson takes a closer look: how a link is built, what you can put in href, how to write link text that people (and screen readers) understand, and when a link is the wrong tool for the job.

A link has three parts: the <a> element, its href attribute and the content between the tags.

HTML
<a href="https://example.com/recipes">Browse all recipes</a>
  • <a> stands for anchor. The name comes from the early web, when links "anchored" one document to another.
  • href holds the destination: the URL the browser loads when someone follows the link.
  • The content, here Browse all recipes, is the link text. It is the part people see and click.

The browser gives links a few things for free. They are underlined and colored, they change color once visited, the cursor turns into a pointer, and, most importantly, they can be reached with the Tab key and followed with Enter.

No href, no link. An <a> without an href is only a placeholder for a link. It is not underlined, cannot be focused with the keyboard and does nothing when clicked. That can be handy in a menu where the current page should not link to itself, but if you want a real link, the href must be there.

What can go in href?

The value of href is a URL, and URLs come in several flavors. Try each link below and watch what happens in the preview:

Kinds of href values

Here is what each kind means:

href starts with Example What it does
https:// https://example.com/about Loads a page on any site. Called an absolute URL.
a path about.html, ../index.html, /blog/ Loads a page on the same site, relative to the current one.
# #pricing Scrolls to the element with id="pricing" on the same page.
mailto: mailto:[email protected] Opens the visitor's email program.
tel: tel:+15555550123 Offers to call the number (mostly on phones).

Paths and fragments each get a lesson of their own: File Paths and URLs and Link Targets and Page Jumps. Email and phone links are covered in Email, Phone and Download Links.

Avoid href="javascript:...". You may see old code that runs JavaScript from a link. It breaks middle-click and "open in new tab", and it mixes behavior into the markup. If clicking should run code rather than go somewhere, use a <button> (more on that below).

Link text is a promise. It tells people where the link goes before they click. Many visitors scan a page for links instead of reading every word, and screen-reader users often pull up a list of all links on a page, read out of context. A list that says "click here, click here, read more" is useless.

Compare these two versions of the same sentence:

HTML
<!-- Vague -->
<p>Our refund policy changed. <a href="/refunds">Click here</a> for details.</p>

<!-- Clear -->
<p>Our <a href="/refunds">refund policy</a> changed last week.</p>

A few guidelines:

  • Describe the destination. "Download the 2026 price list" beats "Download".
  • Keep it short but complete. Link the meaningful words, not the whole paragraph.
  • Don't say "link". Screen readers already announce it as a link, so "link to the help center" is heard as "link, link to the help center".
  • Mention surprises. If a link opens a PDF or a large file, say so: "Annual report (PDF, 4 MB)".
  • Same text, same destination. Two links with identical text should go to the same place.

The <a> element is transparent: it can contain whatever its parent could contain. That means you can wrap an image, or even a whole card with a heading and a paragraph, in one link.

Image and card links

Two things to notice:

  • When an image is the only content of a link, its alt text becomes the link text. So describe where the link goes, not just what the picture shows. "Sunset photo gallery" works; "orange sky" does not.
  • A link must not contain other interactive elements, such as another link or a button. Nesting them confuses both browsers and people.

The title attribute

You can add a title to show a tooltip when the mouse rests on a link:

HTML
<a href="/pricing" title="Plans start at $5 per month">Pricing</a>

Treat it as a small bonus and never as the only place for important information. Touch screens have no hover, keyboard users never see the tooltip, and screen readers handle it inconsistently. If something matters, put it in the visible text.

Links and buttons look similar once styled, but they mean different things:

  • A link takes you somewhere: another page, another part of the page, a file.
  • A button does something: submits a form, opens a menu, plays a video, adds an item to a cart.

The difference is not just philosophical. Keyboards and assistive technology treat them differently. A link is followed with Enter and can be opened in a new tab or bookmarked. A button is pressed with Enter or Space and is announced as a button, so people expect an action.

A link and a button side by side

Pick the element by what it does, then use CSS to make it look however you like. A <button> styled as a text link is fine. An <a> that navigates nowhere and only runs a script is not.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What happens when you leave out the href attribute on an a element?

    Without href, <a> is only a placeholder for a link: no underline, no keyboard focus, no navigation.
  2. 2. Which link text is the most helpful for someone scanning a list of links?

    Good link text describes the destination and makes sense on its own. Saying "link" is redundant because screen readers already announce it.
  3. 3. An image is the only thing inside a link. What should its alt text describe?

    The alt text becomes the link's text, so it should tell people what they will get by following the link.
  4. 4. Clicking a control should add a product to the shopping cart without leaving the page. Which element fits best?

    Buttons perform actions; links go somewhere. Adding to a cart is an action, so a button is the right element.

Summary

  • <a href="..."> creates a link; the content between the tags is the link text.
  • Without href, an <a> is just a placeholder and is not interactive.
  • href can hold an absolute URL, a relative path, a #fragment, or a scheme such as mailto: or tel:.
  • Write link text that describes the destination and makes sense out of context.
  • Links can wrap images and whole blocks; an image's alt text becomes the link text.
  • Use title only for extras, and use a <button> when the control performs an action instead of navigating.

Next lesson: File Paths and URLs, where you will learn exactly how relative and absolute addresses are resolved.