Hyperlinks

Back

Loading concept...

🔗 HTML Hyperlinks: The Magic Doors of the Internet

Imagine the internet as a giant city with millions of buildings. How do you get from one building to another? You use DOORS! In HTML, these magical doors are called hyperlinks—and today, you’ll learn how to build them!


🚪 What is a Hyperlink?

Think of a hyperlink like a magic portal in a video game. You click it, and WHOOSH!—you’re transported somewhere new!

Every time you click blue text on a website and go somewhere else? That’s a hyperlink doing its job.


🏷️ The Anchor Element: <a>

The anchor element is your portal-building tool. It’s written as <a> and it anchors one place to another.

<a>Click Me!</a>

But wait! This portal has no destination yet. It’s like a door that opens to a brick wall. 🧱

To make it work, we need to tell it WHERE to go!


🎯 The href Attribute: Where Should I Go?

The href attribute is like writing an address on your portal. It tells the link exactly where to take you.

href = Hypertext REFerence (fancy way to say “the address”)

<a href="https://google.com">
  Go to Google
</a>

What happens:

  • User sees: “Go to Google” (clickable blue text)
  • User clicks it → Browser opens Google!
graph TD A["User Clicks Link"] --> B["Browser Reads href"] B --> C["Browser Goes to Address"] C --> D["New Page Loads! 🎉"]

🗺️ Absolute vs Relative URLs

Here’s where it gets interesting! There are two ways to write addresses.

🌍 Absolute URLs: The Full Address

Like writing a complete home address on a letter:

<a href="https://www.example.com/about.html">
  About Page
</a>

Use absolute URLs when:

  • Linking to OTHER websites
  • You need the complete path

🏠 Relative URLs: Directions from Here

Like saying “go to the room next door”:

<a href="about.html">About</a>
<a href="pages/contact.html">Contact</a>
<a href="../home.html">Go Back</a>
Symbol Meaning Example
(none) Same folder page.html
./ Current folder ./page.html
../ Go up one folder ../page.html

Think of it like directions:

  • Absolute = “Go to 123 Main Street, New York, USA”
  • Relative = “Turn left, third door”

📍 Fragment Identifiers: Jump to a Spot

What if you don’t want to go to a whole new page—just jump to a specific part of a page?

Use the # symbol! It’s like a bookmark inside a book.

Step 1: Mark the Spot

<h2 id="tips">Helpful Tips</h2>

Step 2: Link to It

<a href="#tips">Jump to Tips</a>

Click → You scroll right to that section!

Link to Another Page’s Section

<a href="guide.html#chapter3">
  Go to Chapter 3
</a>
graph TD A["&#35;tips"] --> B["Find element with id=&&#35;39;tips&&#35;39;"] B --> C["Scroll page to that spot"] C --> D["User sees that section! 📍"]

🪟 The target Attribute: Same Window or New?

By default, links open in the same window. But sometimes you want a new window (or tab).

Same Window (Default)

<a href="page.html">
  Opens Here
</a>

New Tab/Window

<a href="page.html" target="_blank">
  Opens in New Tab
</a>

Target Options

Value What It Does
_self Same window (default)
_blank New tab/window
_parent Parent frame
_top Full body of window

⚠️ Safety Tip for _blank

When opening external links in new tabs, add security:

<a href="https://external.com"
   target="_blank"
   rel="noopener noreferrer">
  Safe External Link
</a>

This prevents the new page from accessing your page’s data!


📧 Email Links: Open Mail App

Want to let users send you an email with one click? Use mailto:

<a href="mailto:hello@example.com">
  Email Us
</a>

Click → User’s email app opens with your address filled in!

Add Subject & Body

<a href="mailto:hello@example.com?subject=Hi&body=I love your site!">
  Send Feedback
</a>
Part What It Does
mailto: Opens email app
?subject= Pre-fills subject line
&body= Pre-fills message

📞 Phone Links: Tap to Call

On mobile, you can make phone numbers clickable:

<a href="tel:+1234567890">
  Call Us: +1 234 567 890
</a>

Tap on mobile → Phone app opens, ready to dial!

SMS/Text Message Links

<a href="sms:+1234567890">
  Text Us
</a>

📥 Download Links: Get Files

Want visitors to download a file instead of viewing it?

Use the download attribute:

<a href="report.pdf" download>
  Download Report
</a>

Custom Filename

<a href="file123.pdf" download="My-Report.pdf">
  Download Report
</a>

The user’s file will be named “My-Report.pdf” even though the original was “file123.pdf”!

graph TD A["User Clicks Download Link"] --> B{download attribute?} B -->|No| C["Browser tries to open file"] B -->|Yes| D["Browser downloads file"] D --> E["File saved to device! 📥"]

🎯 Quick Reference

Link Type Code
Basic <a href="url">Text</a>
New Tab <a href="url" target="_blank">
Jump to ID <a href="#section">
Email <a href="mailto:email">
Phone <a href="tel:number">
Download <a href="file" download>

🌟 You Did It!

You now know how to create every type of hyperlink in HTML:

✅ The anchor <a> element ✅ The href attribute for destinations ✅ Absolute vs relative URLs ✅ Fragment identifiers with # ✅ The target attribute for new tabs ✅ Email and phone links ✅ Download links

You’re now a portal master! 🚀

Every website you visit uses these exact same techniques. Now YOU can build the doors that connect the internet!


Remember: Links are the threads that weave the web together. Without them, every page would be an island. Now go connect the world! 🌐

Loading story...

Story - Premium Content

Please sign in to view this story and start learning.

Upgrade to Premium to unlock full access to all stories.

Stay Tuned!

Story is coming soon.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.