Connecting your pages to the world wide web
(in an overly dramatic tour guide voice) WELCOME, adventurers, to the HYPERLINK HIGHWAY! The most DANGEROUS and THRILLING road in all of cyberspace! Please keep your hands and feet inside the browser at all times!
(confused) Um, we're just teaching them how to make basic links with the anchor tag...
(ignoring him completely) BEHOLD! (slaps whiteboard) The vast interconnected web of DIGITAL DESTINY! One wrong click and you could end up ANYWHERE! Cat videos! Shopping carts! THE DARK WEB! (whispers dramatically) That's where they sell illegal memes, you know.
(entering with coffee) That's not what the dark web is, and you know it. (to the students) Don't listen to him. Links are just a way to connect one webpage to another. They're perfectly safe.
(entering with a plate of link sausages) Did someone say links? I brought breakfast!
(sighs) Not those kinds of links, Fatty. We're teaching HTML hyperlinks. The <a> tag?
(stomping in with a printout) WHO'S responsible for this ABSOLUTE SECURITY NIGHTMARE?! (waves paper frantically)
The anchor tag creates connections between documents. That's it. <a href="destination.html">Link text</a>. Where you've been, where you're going, and what you call it.
Hyperlinks are what make the web a web. They connect pages and resources together, allowing users to navigate between them with a simple click.
Without links, each webpage would be an isolated island. You'd have to manually type in the full address for every page you wanted to visit!
<a> tag (the "anchor" tag)href attribute specifies the destination
You know what links remind me of? Airports. Each webpage is like a city, and hyperlinks are the flights connecting them. Some are direct flights (gestures with imaginary sausage) and some have layovers where you get stuck watching ads for twenty minutes.
THE COSMIC TAPESTRY OF INTERCONNECTED KNOWLEDGE! Just think, with a single line of code, you can transport your users ANYWHERE in the digital universe! It's like being a WIZARD! (waves pointer like a wand) Clickus Linkus Transportus!
Let's learn how to create links using HTML's anchor tag.
<a href="https://www.example.com">Visit Example Website</a>
<a> - The opening anchor taghref="..." - The hypertext reference (destination)</a> - The closing anchor tagHypertext REFerence
It specifies the URL or destination where the link should take the user when clicked.
NEVER forget to include proper link text! "Click here" tells the user NOTHING about where they're going! It's like getting into a taxi and saying "just drive" instead of giving an address!
This is a working link: Visit Example Website
Click it to see how it opens the destination in a new tab.
Include the complete web address:
<a href="https://www.example.com/page.html">Link Text</a>
Reference files relative to the current page:
<a href="about.html">About Us</a>
Use absolute URLs when linking to external sites. Use relative URLs for pages within your own site. It keeps your code portable and easier to maintain.
When linking to other websites, you need to include the full URL:
<a href="https://www.wikipedia.org">Visit Wikipedia</a>
💡 Pro Tip:
When linking to external sites, it's often good practice to add target="_blank" to open the link in a new tab:
<a href="https://www.wikipedia.org" target="_blank">Visit Wikipedia</a>
If using target="_blank", always add rel="noopener noreferrer" for SECURITY! Otherwise, you're potentially exposing your users to CROSS-WINDOW EXPLOITATION ATTACKS!
For links to other pages in your site, you can use relative paths:
<a href="about.html">About Us</a>
<a href="pages/contact.html">Contact</a>
<a href="../index.html">Back to Home</a>
<a href="/images/photo.jpg">View Photo</a>
When I was learning, I got confused about the ../ notation. It means "go up one directory level." Think of it like going up one floor in a building before finding the right room.
You can link to specific sections of a page using IDs:
<h2 id="section2">Section 2</h2>
<a href="#section2">Go to Section 2</a>
Click here to jump to the Activity section of this page.
Controls where the link opens:
<a href="https://example.com" target="_blank">Open in new tab</a>
Common values: _blank (new tab), _self (same window)
Provides a tooltip when hovering:
<a href="contact.html" title="View our contact information">Contact Us</a>
Specifies relationship between linked resources:
<a href="https://example.com" target="_blank" rel="noopener noreferrer">External Link</a>
Common values: noopener (security), noreferrer (privacy), nofollow (SEO)
Always consider accessibility when creating links. Screen readers rely on descriptive link text to help users navigate. "Click here" or "Read more" aren't helpful - use specific text like "Download Annual Report" instead.
target="_blank" for external linksrel="noopener noreferrer" for security
ALWAYS VALIDATE YOUR LINKS! Nothing says "amateur hour" like a website LITTERED with 404 errors! Users who click on broken links don't come back!
💡 Pro Tip:
Use this free tool to check all your links: Dead Link Checker
Remember, brave explorers of the HYPERLINK HIGHWAY! With great linking power comes great responsibility! Don't send your users down a PATH OF DOOM! Unless it's really funny, then maybe consider it.
Now it's time to practice! Let's add some links to the bio page you've been working on. This will make your page interactive and connected to the web.
Open your bio page HTML file
This is the page you created in previous lessons with your name and information.
Add a link to your favorite website
<p>My favorite website is <a href="https://www.example.com" target="_blank">Example Website</a>. Check it out!</p>
Replace "https://www.example.com" with the actual URL of your favorite website.
Add a "Back to Top" link
First, add an ID to your heading:
<h1 id="top">Your Name</h1>
Then, at the bottom of your page, add:
<p><a href="#top">Back to Top</a></p>
Add an email link
<p>Contact me: <a href="mailto:your.email@example.com">your.email@example.com</a></p>
Replace "your.email@example.com" with your actual email address (or a fake one for privacy).
Save and test your page
Open your HTML file in a web browser and test all your links:
Challenge:
Add links to at least three different websites that represent your interests or hobbies. Make sure to give each link descriptive text!
Remember, you're not limited to just words as link text. You can also make images clickable! Just wrap your <img> tag in an <a> tag. Just like putting cheese inside a burger instead of on top... it's all about the wrapper!
Let's look at a complete example that uses all the link types we've learned about:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Bio Page</title> </head> <body> <h1 id="top">Alex Johnson</h1> <img src="profile.jpg" alt="Alex Johnson profile photo"> <h2 id="about">About Me</h2> <p>Hi! I'm Alex, a web development student. I love coding, hiking, and photography.</p> <h2 id="favorites">My Favorite Websites</h2> <ul> <li><a href="https://www.nationalgeographic.com" target="_blank" rel="noopener noreferrer">National Geographic</a> - Amazing nature photography</li> <li><a href="https://www.github.com" target="_blank" rel="noopener noreferrer">GitHub</a> - Where I store my code projects</li> <li><a href="resources.html">Coding Resources</a> - My collection of helpful tutorials</li> </ul> <h2 id="contact">Contact Me</h2> <p>Email me at <a href="mailto:alex@example.com">alex@example.com</a></p> <nav> <p> <a href="#top">Back to Top</a> | <a href="#about">About</a> | <a href="#favorites">Favorites</a> | <a href="#contact">Contact</a> </p> </nav> </body> </html>
This example shows different types of links:
Notice the navigation section at the bottom. This is a common pattern - creating a menu of links to different sections of the same page. As your pages get longer, this becomes increasingly important for usability.
AND THERE YOU HAVE IT, brave explorers! You've conquered the HYPERLINK HIGHWAY! You now possess the MYSTICAL POWER to connect pages across the vast digital universe!
The fundamentals look ACCEPTABLE. Just remember - with linking power comes linking responsibility! Don't create security nightmares!
*enters with tail wagging, inspecting the code*
Woof! Woof! *looks at the code approvingly*
*excited* Snowzie approves! It looks like our lesson on hyperlinks is officially a success!
Congratulations! You now know how to create links between webpages!
<a> taghref attribute specifies where the link goesmailto:target and relNow that you can create links, try:
In the next lesson, we'll learn about creating lists to organize information!
Remember, links are like a good sandwich - they need a strong structure, clear contents, and they should take you somewhere worth going!