HTML Links and Navigation
Why is it called the World Wide Web? Because it is a web. Billions of pages, each one connected to others by threads you can follow with a single click or tap. Take those threads away and you would have a pile of separate documents that nobody could find.
The thread is the link. It is one of the oldest and most important ideas in HTML, and it is the reason you can start on a recipe and end up reading about the history of spices. In this section, you will learn how to build every kind of link: to other websites, to other pages of your own site, to a spot on the same page, to an email address, to a phone number, and even to a file someone can download.
What You Will Learnβ
In this section, you will be able to:
- Write a link with the anchor element (
<a>) - Tell absolute and relative URLs apart, and know when to use each
- Link inside your own site, and jump to a section on the same page
- Link to other websites, and decide how the new page should open
- Keep your links secure with
relvalues - Create email, telephone, and download links
- Build a clear navigation menu that works for everyone
You should be comfortable with basic text elements such as headings and paragraphs. If not, start with the Text Content section.
Your First Linkβ
A link has three parts: the tag, the destination, and the words people click.
- HTML Code
- Browser Output
<p>
Learn more about web standards at
<a href="https://www.w3.org/">the W3C website</a>.
</p>
Learn more about web standards at the W3C website.
The demo link above points to # so it stays on this page. In your own file, it would take you to the address in href.
The Anatomy of a Linkβ
Here is the same link, split into its parts.
<a href="https://www.w3.org/">the W3C website</a>
| Part | In the example | What it does |
|---|---|---|
| Opening tag | <a ...> | Starts the link. a means anchor |
href attribute | href="https://www.w3.org/" | The destination. href means hypertext reference |
| Link text | the W3C website | The words people see and click |
| Closing tag | </a> | Ends the link |
The href attribute is the heart of every link. Without it, the <a> tag is just text.
Reading a URLβ
A URL is an address on the web. Once you can read one, links become much easier to understand.
https://codeharborhub.github.io:443/tutorial/html?lang=en#links
βββ¬ββ βββββββββββββ¬β ββββββββββββ¬βββββββββββ¬βββββββββ¬βββββββ¬ββ
scheme host port path query fragment
| Part | Meaning | Example |
|---|---|---|
| Scheme | The rule for talking to the resource | https, mailto, tel |
| Host | The server or website name | codeharborhub.github.io |
| Port | The door on the server, usually hidden | 443 |
| Path | Which page or file | /tutorial/html |
| Query | Extra information | ?lang=en |
| Fragment | A spot within the page | #links |
The Different Kinds of Linksβ
Every link is a variation on the same idea. The destination in href decides what kind of link you get.
| Type | What it does | Example href |
|---|---|---|
| Absolute URL | A full address, including the scheme and host | https://example.com/about |
| Relative URL | An address from the current page's location | about.html or ../images/logo.png |
| Internal link | Goes to another page or section in your own site | /contact or #pricing |
| External link | Goes to a different website | https://developer.mozilla.org/ |
| Email link | Opens the visitor's email app | mailto:hello@example.com |
| Telephone link | Starts a phone call | tel:+911234567890 |
| Download link | Saves a file to the device | report.pdf with the download attribute |
- HTML Code
- Browser Output
<ul>
<li><a href="https://example.com/about">Absolute: About page</a></li>
<li><a href="about.html">Relative: About page</a></li>
<li><a href="#pricing">Internal: jump to Pricing</a></li>
<li><a href="https://developer.mozilla.org/">External: MDN</a></li>
<li><a href="mailto:hello@example.com">Email us</a></li>
<li><a href="tel:+911234567890">Call us</a></li>
<li><a href="guide.pdf" download>Download the guide</a></li>
</ul>
How Links Behaveβ
By default, a link:
- Is shown in a different color and underlined, so people know it can be clicked
- Opens the destination in the same tab
- Changes color after you have visited it
- Can be reached and activated with the keyboard, using Tab and Enter
You can change the look with CSS. You can change where it opens with the target attribute. You will learn both in this section.
Good Link Textβ
The words inside a link matter more than most beginners expect. Many screen reader users move through a page by listening to a list of links only. If every link says "click here," that list is useless.
- Unclear
- Clear
<p>To read our privacy policy, <a href="/privacy">click here</a>.</p>
<p>For the full guide, <a href="/guide">read more</a>.</p>
<p>Read our <a href="/privacy">privacy policy</a>.</p>
<p>Open the <a href="/guide">full HTML guide</a>.</p>
Imagine each link on its own, with nothing around it. Would a stranger understand where it goes? If yes, the link text is good.
Navigation: Links That Form a Mapβ
A single link takes you somewhere. A group of links, laid out clearly, forms navigation: the map of your site. HTML has the <nav> element for this, and a list is the natural way to arrange the links.
- HTML Code
- Browser Output
<nav aria-label="Main">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/courses">Courses</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
You will turn this plain list into a real menu in the last lesson of this section.
Your Learning Pathβ
Follow the lessons in order. Each one builds on the one before.
ποΈ Anchor Element
Learn how the HTML anchor element works. Understand the a tag, the href attribute, link text, link states, styling links with CSS, linking images, accessibility, hreflang for multilingual sites, and common mistakes on CodeHarborHub.
ποΈ Absolute URLs
Learn what absolute URLs are in HTML and when to use them. Understand the parts of a full web address, schemes like https, mailto and tel, URL encoding, international domain names, query strings, common mistakes, and best practices on CodeHarborHub.
ποΈ Relative URLs
Learn how relative URLs work in HTML. Understand file paths, same-folder links, subfolders, the parent folder with ../, root-relative paths, the base element, case sensitivity, and common mistakes, explained step by step on CodeHarborHub.
ποΈ Internal Links
Learn how to create internal links in HTML. Link between pages of your own site, jump to sections with id and fragment links, build a table of contents, add skip links and back-to-top links, and make them accessible. Explained clearly on CodeHarborHub.
ποΈ External Links
Learn how to create external links in HTML. Link to other websites with absolute URLs, show readers a link leaves your site, use rel values like nofollow and sponsored, link to the right language version, and keep outside links healthy. Explained on CodeHarborHub.
ποΈ Target Attribute
Learn how the HTML target attribute decides where a link opens. Understand _self, _blank, _parent, _top, named targets and iframes, when opening a new tab helps, accessibility warnings, security basics, and common mistakes on CodeHarborHub.
ποΈ Link Security
Learn how to keep HTML links safe. Understand reverse tabnabbing, rel noopener and noreferrer, referrer policy, dangerous javascript and data URLs, user-submitted links, look-alike addresses, HTTPS, and how to protect your visitors on CodeHarborHub.
ποΈ Email Links
Learn how to create email links in HTML with mailto. Add recipients, cc, bcc, subject and body text, encode special characters and line breaks, protect addresses from spam, write accessible link text, and know when a contact form is better. Explained on CodeHarborHub.
ποΈ Telephone Links
Learn how to create telephone links in HTML with the tel scheme. Write international phone numbers with country codes, add extensions, use sms links, handle desktop vs mobile, prevent unwanted auto-detection, and make phone links accessible on CodeHarborHub.
ποΈ Download Links
Learn how to create download links in HTML with the download attribute. Suggest file names, understand same-origin limits and Content-Disposition, generate files with JavaScript, show file type and size, keep downloads safe, and make them accessible on CodeHarborHub.
ποΈ Navigation Menus
Learn how to build accessible HTML navigation menus. Use the nav element with lists, mark the current page, style a horizontal menu with CSS, add a mobile toggle button, create breadcrumbs, dropdown safely, and support right-to-left languages on CodeHarborHub.
Common Beginner Mistakesβ
Here are a few traps worth knowing about before you start. Each one has its own lesson later.
| Mistake | What goes wrong | Where you will fix it |
|---|---|---|
Forgetting https:// on an outside link | The browser treats it as a path on your own site | Absolute URLs |
| Wrong folder path in a relative link | The page shows a "not found" error | Relative URLs |
| Using "click here" as link text | Screen reader users cannot tell links apart | Anchor Element |
| Opening every link in a new tab | Visitors lose control of their own browsing | Target Attribute |
Linking out with target="_blank" and no rel | Older browsers can expose a security risk | Link Security |
| Writing a phone number without the country code | The call fails for visitors in other countries | Telephone Links |
Websites move and pages disappear. A link that works today may show an error next year. Good developers check their links from time to time, and you will learn easy ways to keep them healthy.
Quick Recapβ
Test yourself. Click a question to reveal the answer.
1. Which tag creates a link, and which attribute holds the destination?
The <a> (anchor) tag creates the link, and the href attribute holds the destination.
2. What is the difference between an absolute and a relative URL?
An absolute URL contains the full address, including the scheme and host. A relative URL gives a path starting from the current page's location.
3. Which URL scheme opens an email app?
mailto:, for example mailto:hello@example.com.
4. Why is "click here" a poor link text?
It says nothing about the destination. Screen reader users, and anyone scanning the page, rely on link text that makes sense on its own.
5. Which element groups the main links of a site into a navigation area?
The <nav> element, usually with a list of links inside it.
Key Takeawaysβ
- A link is an
<a>element with anhrefattribute that holds the destination. - The
hrefvalue decides the type of link: page, section, website, email, phone number, or file. - Absolute URLs include everything. Relative URLs depend on the current page's location.
- Write link text that is clear on its own, so every visitor knows where the link goes.
- Group your main links in a
<nav>element to build the map of your site.
Ready to begin? Start with the Anchor Element.