Skip to content

HTML Links: href, Absolute and Relative URLs, New Tabs, Email and Phone Links

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

Links are what make the web a web. One element, <a>, connects your page to other sites, to other pages on your own site, to a section further down the page, to an email address or to a phone number that dials on a tap. Getting the URL right and writing clear link text are two small skills that save visitors a lot of frustration.

Quick answer

A link is <a href="URL">link text</a>. Use a full URL (https://...) for other sites and a relative path (about.html or /about) for pages on your own site. #id jumps to an element with that id, mailto: opens email and tel: starts a call.

15 min read and practice · Content checked on 20 October 2026

In this lesson you will

  • Write absolute, relative and root-relative links correctly
  • Link to a section of a page, an email address and a phone number
  • Write link text that makes sense out of context

The a element and href

The href attribute holds the destination; the content between the tags is what people click. That content can be text or an image. An <a> without href is not a link at all: it is not focusable with the keyboard, so always include one.

An absolute URL contains everything: the scheme (https://), the domain and the path, for example https://developer.mozilla.org/en-US/docs/Web/HTML. Use it for any page on another site. If you leave out https:// and write www.example.com, the browser treats it as a file on your own site and the link breaks.

Try it: Links to other sites
Code
ResultUpdates as you type
Console
  1. Console messages, errors, form data and clicked links appear here.

Click each link in the result. The console shows the full address the browser built, so you can see why the second one points to the wrong place.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 2 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

Should external links open in a new tab?

Usually not. Accessibility guidance from W3C advises warning people when a link opens a new window, and many users prefer to decide themselves. Keep target="_blank" for cases like a help page opened in the middle of a form.

What is the difference between an absolute and a relative URL?

An absolute URL includes the scheme and domain and points to the same place from anywhere. A relative URL is read from the current page’s location, so it is shorter and survives a domain change but depends on where the page lives.

Can I put a whole card or image inside a link?

Yes. Since HTML5 an <a> can wrap block content such as a heading, an image and a paragraph, as long as there are no other links or buttons inside it. If the link holds only an image, the image’s alt text becomes the link text.

Why do people add rel="nofollow" or rel="sponsored"?

These values tell search engines about the link. Google asks sites to mark paid or sponsored links with rel="sponsored" and links in user content with rel="ugc"; nofollow is a general hint not to pass ranking credit.

Is a mailto link safe from spam bots?

Not really: any address in a page can be collected. Many sites use a contact form instead, or accept that a public business address will get some spam and rely on the mail provider’s filter.

Sources

Facts in this lesson were checked against these official pages on 20 October 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.