12
HTML – Links & Navigation
Chapter 12 • Beginner
20 min
Links (anchors) are what make the web "clickable". They allow users to navigate between pages, websites, or sections of the same page.
The Anchor Tag (<a>)
- The <a> tag defines a link.
- The href (hypertext reference) attribute specifies the destination URL.
- The text between <a> and </a> is the clickable part.
Example:
html.js
<a href="https://google.com">Go to Google</a>
Absolute vs Relative URLs
- Absolute URL: The full web address (e.g., https://www.example.com/page.html).
- Used for linking to external websites.
- Relative URL: The path relative to the current file (e.g., about.html, /images/logo.png).
- Used for internal links within your own website.
Opening in a New Tab
Use the target attribute to control where the link opens.
- target="_blank": Opens the link in a new tab or window.
- target="_self": Opens in the same tab (default).
When using target="_blank", it is a security best practice to add rel="noopener noreferrer".
noopener: Prevents the new page from accessingwindow.openerproperty of the original page (security).noreferrer: Prevents the browser from sending theRefererheader to the new page (privacy).
Example:
html.js
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Open in new tab</a>
Anchor Links (Jumping to a section)
You can link to a specific part of a page using IDs.
- Give an element an ID: <h2 id="contact">Contact</h2>
- Link to it with a hash (#): <a href="#contact">Go to Contact</a>
Email and Phone Links
- Email: <a href="mailto:someone@example.com">Send Email</a>
- Phone: <a href="tel:+1234567890">Call Us</a>
Suggested image prompt
"Diagram showing different types of links: one pointing to an external globe (Absolute), one pointing to a local file folder (Relative), and one pointing to a section on the same page (Anchor)."
Interview-style questions from this topic
- What does the href attribute stand for?
- What is the difference between absolute and relative URLs?
- How do you make a link open in a new tab?
- How do you create a link that jumps to a specific section on the same page?
Hands-on Examples
Links & Navigation Example
<!DOCTYPE html>
<html>
<body>
<h1>Navigation</h1>
<p>
<a href="about.html">About Us (Relative)</a> |
<a href="https://www.google.com" target="_blank">Google (Absolute, New Tab)</a> |
<a href="#footer">Jump to Footer</a>
</p>
<p style="height: 500px;">(Long content placeholder...)</p>
<h3 id="footer">Footer Section</h3>
<p>Contact us: <a href="mailto:info@schoolabe.com">info@schoolabe.com</a></p>
</body>
</html>This example shows how to link to internal pages, external websites (opening in a new tab), sections within the same page using IDs, and email addresses.