Home / Learn HTML / HTML Links

HTML Links

Links connect pages. The a (anchor) element is what makes the web a web.

Definition

A hyperlink (link) lets the visitor go from one page to another. It is made with the a (anchor) element and its href attribute, which holds the address. The text between the tags is what the visitor clicks.

Kinds of addresses

KindExampleGoes to
Absolute URLhttps://example.com/pageAnother website
Relative URLabout.htmlA file in the same site
Root relative/blog/postPath from the site root
Fragment#contactA place on the same page (needs a matching id)
Emailmailto:hi@example.comOpens the mail app
Phonetel:+911234567890Starts a call on phones

Important attributes

Tip:Write meaningful link text. "Download the price list (PDF)" is much better than "click here".

Theory in plain words

A click on a linkUser clicksBrowser reads hrefRequest to serverNew page loads
A click on a link

What it is

Links (the a element) take visitors to another page, a file, an email address or a place on the same page.

Why we use it

Links are what make the web a web. Good links also help search engines find and rank your pages.

How it works

The browser makes the content clickable and sends a request to the address in href. Relative links use the current page as the starting point.

Where it is used

  • Menus and navigation
  • Download buttons
  • mailto: and tel: links
  • Jump links to a section id
A basic linkTry it Yourself
Open in a new tabTry it Yourself

_self is the default. _blank opens a new tab.

Link on an imageTry it Yourself
Link on a button lookTry it Yourself
Email linkTry it Yourself
Phone linkTry it Yourself

On a phone this starts a call.

WhatsApp linkTry it Yourself
SMS linkTry it Yourself
Jump to a place on the same pageTry it Yourself

An id on the target and #id in the link.

Table of contentsTry it Yourself
Download linkTry it Yourself

download saves the file instead of opening it.

Link colours with CSSTry it Yourself
Remove the underlineTry it Yourself
Title tooltipTry it Yourself
Relative and absolute linksTry it Yourself
Sponsored and no followTry it Yourself

Tells search engines how to treat the link.

Language of a linkTry it Yourself
Tip:Make link text meaningful. Write "Read the pricing page" instead of "Click here".

Quick quiz

1. Which attribute holds the address?

2. How to open a link in a new tab?

3. Which link starts an email?

Common questions

Which attribute holds the address?

href. href is the link target.

How to open a link in a new tab?

target="_blank". Add rel="noopener" too.

Which link starts an email?

mailto:. mailto: opens the mail app.

My notes
Ask a question about this lesson