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
| Kind | Example | Goes to |
|---|---|---|
| Absolute URL | https://example.com/page | Another website |
| Relative URL | about.html | A file in the same site |
| Root relative | /blog/post | Path from the site root |
| Fragment | #contact | A place on the same page (needs a matching id) |
mailto:hi@example.com | Opens the mail app | |
| Phone | tel:+911234567890 | Starts a call on phones |
Important attributes
target="_blank"opens the link in a new tab. Addrel="noopener"for safety.downloadsaves the file instead of opening it.rel="nofollow"tells search engines not to pass credit to the target.titlegives a tooltip.
Theory in plain words
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
_self is the default. _blank opens a new tab.
On a phone this starts a call.
An id on the target and #id in the link.
download saves the file instead of opening it.
Tells search engines how to treat the link.
Quick quiz
1. Which attribute holds the address?
href is the link target.
2. How to open a link in a new tab?
Add rel="noopener" too.
3. Which link starts an email?
mailto: opens the mail app.
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.