Links & Hyperlinks
Links & Hyperlinks (Connecting the World Wide Web) π
Welcome to Chapter 6: Links in HTML!
Have you ever wondered why the World Wide Web is called a "Web"?
Imagine a spider's web: every thread connects to another thread, creating an interconnected network where you can walk from any point to any other point.
In video games, imagine having a teleportation portalβyou step inside, and WHOOSH! You are instantly transported across oceans to a new world.
In web development, Hyperlinks (or simply links) are those teleportation portals! With one gentle mouse click or screen tap, a link can take you:
- Across the globe to Wikipedia or YouTube.
- To another page on your school website.
- Straight down to an important announcement on the same page.
- Even trigger a direct phone call or email on your smartphone!
Without links, the internet would just be billions of lonely digital documents trapped on isolated computer hard drives. Links tie the entire digital universe together!
The Anchor Element (<a>) β
In HTML, we create links using the <a> tag.
Why did the inventors of HTML pick the letter a? Because a stands for Anchor β!
Think of a big ship throwing its heavy iron anchor into the sea floor. The anchor hooks the ship firmly to a specific location. In the exact same way, the HTML <a> tag anchors a piece of text or an image to a web address!
Anatomy of an Anchor Tag:
Hyperlink & Attribute Anatomy Breakdown
Understanding anchor tags and destination attributes
<aOpening TagDefines a clickable hyperlink.
href="..."Destination AttributeHypertext Reference (URL to open on click).
User-facing anchor text on screen.
</a>Closing TagCloses the hyperlink element.
- 1
<a>(Opening Tag): Tells the browser: "Get ready, a clickable link starts here!" - 2
hrefAttribute: This is the most important attribute.hrefstands for Hypertext Reference. It holds the destination address where the user will land after clicking. - 3Link Text: The readable words between
<a>and</a>. This is what the user sees on their screen (usually styled in blue with an underline). - 4
</a>(Closing Tag): Marks the end of the clickable area.
The 3 Main Types of Links πΊοΈ
Where can a link take you? There are three main destinations:
1. External Links (Visiting Another Website) π
An external link takes the user away from your website to a completely different website on the internet (like visiting Google, Wikipedia, or CBSE).
To create an external link, you must use an Absolute URLβwhich means writing the complete full address starting with https://:
https://! If you write href="google.com" without https://, the browser mistakenly thinks you are looking for a local file named google.com inside your computer folder!2. Internal Links (Walking Around Your Own Website) π«
Imagine your school website has multiple pages:
index.html(The Home Page)about.html(About Our Teachers)courses.html(Available Courses)contact.html(School Office Address)
When a visitor wants to move from the Home page to the About page, you use a Relative URL (pointing to a file inside the same website folder):
Because these files live in the same project directory, you don't need https://βjust the file name!
3. Bookmark / Jump Links (The Page Elevator π)
Have you ever visited a very long webpageβlike a long Wikipedia article or a complete school syllabusβand wanted to jump straight to Chapter 10 without scrolling for 5 minutes?
You can create Jump Links that smoothly scroll directly to a specific section on the same page!
How Jump Links Work in 2 Easy Steps:
Step 1: Give your target heading an id:
Step 2: Link to that id using a hashtag (#):
You can even create a handy "Back to Top" button at the very bottom of your page:
Smart Action Links (Call, Email & WhatsApp) π±
Modern mobile phones, tablets, and laptops can perform smart native actions directly from an HTML link!
1. Click-to-Call (tel:)
When someone taps this link on their smartphone, their phone app opens with the phone number already dialed:
2. Click-to-Email (mailto:)
When clicked, this opens the user's default email app (like Gmail or Apple Mail) with the "To" address and even a pre-written subject line ready to send:
3. Direct WhatsApp Chat Link
You can create a link that opens a WhatsApp conversation with a preset greeting message:
Turning Images & Buttons into Clickable Links πΌοΈ
You don't have to link only plain text! You can put almost any HTML element inside an anchor tagβincluding images!
For example, when visitors click your school logo, you want them to return to the home page:
You can also style an anchor tag with colors and padding so it looks just like a modern rounded button:
Default Link Colors (How Browsers Display Links) π¨
By default, every web browser styles links in three distinct states so users know what is happening:
| Link State | Default Appearance | What It Means |
|---|---|---|
| Unvisited Link | Blue with underline | A link you have not clicked yet. |
| Visited Link | Purple with underline | A page you have already visited in this browser before. |
| Active Link | Red with underline | The exact moment your mouse button is held down over the link. |
Common Beginner Mistakes (And How to Avoid Them) β οΈ
1. β οΈ Forgetting https:// on External Links
2. β οΈ Forgetting the Closing </a> Tag
If you forget to close </a>, the browser thinks everything below it until the end of your document is part of the link! Your entire page will turn blue and clickable!
3. β οΈ Writing Vague Link Text like "Click Here"
Never write just "Click here" or "Read more". For students using screen-reader software (for visually impaired learners), "Click here" gives zero clue where the link goes!
4. β οΈ Confusing href with src
Remember: Images use src (source). Links use href (hypertext reference)!
Quick Summary
- In HTML, hyperlinks are created using the
<a>tag (Anchor tag β). - The
hrefattribute (Hypertext Reference) specifies the destination web address. - External links point to other websites and must always start with
https://(Absolute URL). - Internal links point to other pages inside your own website folder (Relative URL, like
about.html). - Jump links use
#id-nameto zoom directly to a specific section on the same page. - Use
tel:for click-to-call phone numbers andmailto:for click-to-compose emails. - Images can be turned into clickable buttons by wrapping them inside
<a>...</a>. - Always write meaningful, descriptive link text instead of generic words like "Click here".
Practice Quiz
Test your understanding with these multiple-choice questions:
1. What does the letter "a" stand for in the HTML <a> tag?
A. Action B. Address C. Anchor D. Article Answer: C Explanation: The <a> tag stands for Anchor, because it anchors a piece of text or media to a destination URL.
2. Which attribute is used to specify the destination URL of a link?
A. src B. link C. url D. href Answer: D Explanation: href stands for Hypertext Reference and specifies the destination URL where the user will be taken upon clicking.
3. Which of the following is the correct way to link to an external website?
A. <a href="www.google.com">Google</a> B. <a href="https://www.google.com">Google</a> C. <a link="https://www.google.com">Google</a> D. <a src="https://www.google.com">Google</a> Answer: B Explanation: External links require an absolute URL including the protocol https:// so the browser knows to connect to the external web.
4. How do you create an internal jump link that scrolls down to <h2 id="syllabus">?
A. <a href="syllabus">Go to Syllabus</a> B. <a href="#syllabus">Go to Syllabus</a> C. <a target="#syllabus">Go to Syllabus</a> D. <a id="syllabus">Go to Syllabus</a> Answer: B Explanation: An internal bookmark/jump link uses a hashtag (#) followed by the matching element's id.
5. What special prefix is used to create a click-to-call phone link?
A. call: B. phone: C. dial: D. tel: Answer: D Explanation: The tel: protocol (e.g., <a href="tel:+918393042166">) tells smartphones to open the telephone dialer.
Hands-on Practice Challenge π―
Open VS Code and create a file named school-portal.html.
Your Challenge:
Create a mini School Website Home Page with working links:
- 1Top Navigation Bar: Add internal links for
Home,About School,Admissions, andContact Office. - 2Featured Section: Add an external link to Wikipedia's page on Indian Space Research (
https://en.wikipedia.org/wiki/ISRO). - 3Jump Link: Add a link at the top saying "Jump to Principal's Message", which smoothly scrolls down to an
<h3 id="principal">heading. - 4Smart Action Bar: Add a helpline section at the bottom with:
- A
tel:link to your school office phone. - A
mailto:link to the admissions office email.
- 1Open your file in Chrome or Edge and test clicking every single link!
Next Up: In Topic 6.2, we will explore Target Attributes & Hyperlink Securityβhow to open links in brand new browser tabs safely without exposing your website to hackers!
Target Attributes & Security
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| HEX & HSL Color Codes | Target Attributes & Security |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.