Anchor links and URL types
Links connect pages and resources, turning separate documents into a navigable site.
✓ What you will learn in this topic
- Explain the purpose of Anchor links and URL types in a real HTML document.
- Choose and apply the elements shown in both examples.
- Recognize the specific mistake described in this lesson.
Concept explanation
The anchor element uses href to specify a destination. An absolute URL includes the scheme and host; a relative URL is resolved from the current site or path. Use link text that describes the destination, because people may scan links out of context. A fragment URL such as #hours can point to an element with the matching id on the current page.
Syntax
Use descriptive link text; use a fragment only when a matching id exists.
Example 1: a small page
The first destination is a page in the same site; the second is a complete external URL.
<a href=\"about.html\">About the studio</a>
<a href=\"https://example.com/events\">Community events</a>Expected result: Two clickable links appear, each with a destination determined by href.
Example 2: a practical page
The site links use local paths; mailto and tel request the visitorâs configured contact app.
<nav aria-label=\"Trip guide\">
<a href=\"/trails.html\">Trail map</a>
<a href=\"/visit.html#hours\">Opening hours</a>
<a href=\"mailto:hello@example.com\">Email the visitor centre</a>
<a href=\"tel:+14165550123\">Call the visitor centre</a>
</nav>Expected result: A navigation region presents map and hours links plus email and phone actions.
Common mistakes
A link needs a valid href and descriptive text; opening a new tab should be a deliberate choice rather than a default.
Best practices
Make link purpose understandable from its text, use relative URLs for pages in the same site, and protect new-tab links with rel=\"noopener\".
Practice exercise
Create a small site navigation with links to two local pages, a full external URL, an email address, and a telephone number.
Lesson summary
- Anchor href defines the destination; descriptive text tells people where a link leads.
- Make link purpose understandable from its text, use relative URLs for pages in the same site, and protect new-tab links with rel=\"noopener\".
Knowledge check
What makes an anchor a working navigation link?
Show the explanation
An anchor with a valid href has a destination; its text should describe that destination.
Practical example
html<a href=\"about.html\">About the studio</a>
<a href=\"https://example.com/events\">Community events</a>
Expected result:
Two clickable links appear, each with a destination determined by href.
Hands-on practice task
Create a small site navigation with links to two local pages, a full external URL, an email address, and a telephone number.
In this section
Other lessons in Links and Navigation
Broaden your knowledge