Lesson 2.7: Hyperlinks and Advanced Link Types
Hyperlinks & Advanced Link Types
Links are what make the web a web. Master every link type — from external sites and page anchors to email, phone, and file downloads — and learn how to write them accessibly.
Lesson Objectives
- Create hyperlinks using the
<a>anchor tag andhrefattribute - Build all six link types: external, internal, anchor/jump, email, phone, and download
- Use
target="_blank"andrel="noopener noreferrer"safely - Create anchor (jump) links to specific sections of the same page using
id - Write descriptive, accessible link text — never "click here"
- Understand the
mailto:,tel:, anddownloadadvanced link attributes
Part 1: The <a> Tag — How Every Link Works
Every hyperlink on the web is built with the same element: the <a> tag (short for anchor). Unlike most HTML elements, the anchor tag wraps around the clickable content — which can be text, an image, or even a whole section — and uses the href attribute to define where clicking it takes the user.
href — where the link goes (required)target="_blank" — opens new tabrel="noopener noreferrer" — required security pair| Attribute | Required? | Purpose |
|---|---|---|
href | Yes | The destination — a URL, file path, email, phone number, or section ID |
target="_blank" | No | Opens the link in a new browser tab instead of the current one |
rel="noopener noreferrer" | With _blank | Security: prevents the new tab from accessing or controlling the original page |
title | No | Tooltip text shown on hover — adds extra context for users |
download | No | Triggers a file download instead of navigating to the resource |
Part 2: The Six Link Types You Need to Know
The href attribute is more powerful than it looks. Depending on what you put inside it, the same <a> tag can navigate to a website, jump to a section, open an email app, dial a phone, or trigger a file download. Here are all six types:
Links to another website. Always use the full URL starting with https://. Use target="_blank" to open in a new tab — and always pair it with rel="noopener noreferrer".
Links to another page within your own website. Use a relative file path — no full URL needed. The path is relative to the current file's location.
Scrolls to a specific section on the same page by targeting an element's id. The link's href starts with # followed by the target ID. Essential for long-page navigation.
Opens the user's default email application with your address pre-filled in the "To" field. Uses the mailto: prefix. A must-have for any contact section.
On mobile devices, tapping a tel: link automatically opens the phone dialer with the number ready to call. Use international format with + and country code for best compatibility.
The download attribute forces the browser to download the linked file instead of opening it. You can optionally give the downloaded file a custom name. Perfect for résumés, PDFs, or resources.
Part 3: Building Page Navigation with Anchor Links
Anchor links are one of the most useful tools for long webpages. By giving each major section an id attribute and linking to it with href="#section-id", you can create a navigation menu at the top of the page that jumps users directly to what they want to read.
id="about-me", not id="About Me". The href in your link must match the id exactly, including the # prefix.
Part 4: Writing Accessible Link Text
The text inside your <a> tags is called link text. It's the most important part of any link — it tells users (and screen readers) exactly where the link goes before they click it. Screen readers often read links out of the context of the surrounding paragraph, so link text must make sense on its own.
alt attribute becomes the link text for screen readers. Make sure it describes the link's destination — e.g., alt="Visit our Facebook page", not just alt="Facebook logo".
Part 5: New Tabs & Security — target and rel
Opening external links in a new tab (target="_blank") is a common pattern — it keeps your page open while the user browses away. But it comes with a subtle security risk: by default, the new tab can access and manipulate the originating page through JavaScript. The fix is simple and must always be paired together.
target="_blank", you must also write rel="noopener noreferrer" on the same tag. They are always a pair. Omitting rel is a known security vulnerability called "reverse tabnapping."
target="_blank"? Use it for external links to other websites — it keeps your page open in its own tab. For internal links (other pages on your own site) or anchor links (same-page jumps), you generally do not need target="_blank".
🖥️ Code Skills Lab Reminder
Student Activity
Add All Six Link Types to Your Webpage — Code Skills Lab
Open your index.html in the Code Skills Lab. You're going to add a complete set of links to your personal webpage — covering every type. Work through each step and save after every change. Test every link you add!
-
Add a page navigation menu using anchor links. At the top of your
<body>, add a<nav>element with jump links to your main sections. Then add matchingidattributes to each section.<!-- Top of body --> <nav> <a href="#about">About Me</a> | <a href="#interests">Interests</a> | <a href="#contact">Contact</a> </nav> <!-- Add matching ids to your sections --> <section id="about">...</section> <section id="interests">...</section> <section id="contact">...</section>💾 Save — clicking the nav links should jump down the page! -
Add an external link. In one of your paragraphs, link to a website you actually use. Use
target="_blank"andrel="noopener noreferrer". Make the link text descriptive!<p> One of my favorite resources is <a href="https://www.codecademy.com" target="_blank" rel="noopener noreferrer" title="Free interactive coding tutorials"> Codecademy </a>, where I practice HTML and CSS. </p>💾 Save — click the link to confirm it opens in a new tab! -
Add a
mailto:email link. In your Contact section, give visitors an easy way to reach you directly.<section id="contact"> <h2>Contact Me</h2> <p> Want to connect? <a href="mailto:jordan@email.com"> Send me an email </a>. </p> </section>💾 Save — clicking the link should open your email client! -
Add a
tel:phone link. Add a phone number to your contact section. On a mobile device, tapping this dials the number automatically.<p> Or <a href="tel:+15551234567"> call me at (555) 123-4567 </a>. </p>💾 Save — on a phone this would dial the number directly! -
Add a download link. Create a text file in your project called
resume.txt(or use any file you have). Link to it with thedownloadattribute so clicking triggers a download instead of navigation.<p> <a href="files/resume.pdf" download="Jordan-Resume.pdf"> ⬇ Download My Resume (PDF) </a> </p>💾 Save — clicking this should prompt a file download!
📋 Example: What Your Complete Contact Section Might Look Like
🌟 Bonus Challenges
Ready to go further? Try these advanced link techniques:
1. Make your profile image a clickable link — wrap your <img> in an <a> tag. Remember: the image's alt text becomes the link text for screen readers, so make it descriptive of the destination:
2. Pre-fill an email subject line using a query string in your mailto: link. The %20 encodes spaces in the URL:
3. Style your links with CSS to remove the default underline and add a hover effect:
💾 Remember to save in the Code Skills Lab after each change!
Troubleshooting Tips
-
External link not working? Make sure the URL starts with
https://— not justwww.. A link likehref="www.google.com"will try to find a local file named "www.google.com" and fail. Always use the full URL. -
Anchor link not jumping to the right section? The
href="#name"value must exactly match theid="name"on the target element — same spelling, same case, no spaces. Check both ends carefully. -
mailto: link not opening an email app? This requires a default email client configured on the device. It works on most phones and desktops, but may not work in browser-based email environments like Gmail in a browser. It's still the correct code — the behavior depends on the user's setup.
-
Download link opening the file instead of downloading? The
downloadattribute only works for files on the same domain as your page — it doesn't force downloads from external URLs due to browser security restrictions. Make sure the file is in your own project folder. -
Link text is just "click here" or "read more"? Replace it with a description of the destination. Screen readers read link text out of context — make it meaningful on its own. This is also a WCAG requirement (2.4.4).
Lesson Summary
| Link Type / Attribute | Syntax | Purpose |
|---|---|---|
| External link | href="https://..." | Navigates to another website — always use full URL |
| Internal link | href="page.html" | Navigates to another page within your own site |
| Anchor / jump link | href="#section-id" | Jumps to an element with a matching id on the same page |
| Email link | href="mailto:you@email.com" | Opens the user's email client with your address pre-filled |
| Phone link | href="tel:+15551234567" | On mobile, tapping opens the phone dialer ready to call |
| Download link | href="file.pdf" download | Triggers a file download instead of opening in the browser |
target="_blank" | On <a> tag | Opens link in a new browser tab |
rel="noopener noreferrer" | Always with _blank | Security: prevents the new tab from accessing the original page |
title="text" | On <a> tag | Shows a tooltip on hover — adds helpful context |
Knowledge Check
Read each question carefully and select the best answer. Each question has one correct response.
1. Which href value would you use to create a link that jumps to a section with id="projects" on the same page?
2. Why must rel="noopener noreferrer" always be paired with target="_blank"?
3. Which href value creates a link that opens the user's email app with your address pre-filled?
4. Which link text example follows accessibility best practices?
5. What does the download attribute on an <a> tag do?
Lesson Checklist
- I added a
<nav>with anchor jump links at the top of my page - Each section has a unique
idthat matches a nav link'shref="#id" - I added at least one external link with
target="_blank"andrel="noopener noreferrer" - I added a
mailto:email link in my contact section - I added a
tel:phone link in international format - I added a
downloadlink for a file in my project folder - All my link text is descriptive — no "click here" or "read more"
- I tested every link I added to confirm it works correctly
- I saved my file in the Code Skills Lab after each change
