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.
Console
- 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
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.
- MDN: The a element
- MDN: Creating links
- Google Search Central: Qualify your outbound links
- W3C WCAG technique G201: Warn about new windows
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.