Links are one of the most important features of the internet. They allow users to move from one webpage to another with a single click.
Without links, websites would behave like isolated pages instead of a connected web.
In this article, we will learn:
What HTML links are
Anchor tag
Internal and external links
Image links
Email links
Bookmark links
Target attribute
Navigation menus
Practical examples
What are HTML Links?
HTML links are clickable elements that connect:
One webpage to another
One website to another
One section of a page to another
Files, images, videos, and documents
Links are also called Hyperlinks.
HTML uses the <a> tag to create links.
Anchor Tag
The anchor tag syntax:
<a href="URL">Link Text</a>
Where:
<a>→ Anchor taghref→ Hyperlink referenceURL→ Destination address
Example of a Simple Link
<a href="https://www.google.com">
Visit Google
</a>
This creates a clickable link to Google.
Complete Program Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Links</title>
</head>
<body>
<h1>Welcome</h1>
<a href="https://www.google.com">
Visit Google
</a>
</body>
</html>
How Links Work
When a user clicks a link:
Browser reads the
hrefvalueBrowser opens the destination
Requested webpage loads
Types of Links in HTML
HTML mainly supports:
| Type | Purpose |
|---|---|
| External Links | Connect other websites |
| Internal Links | Connect pages within same website |
| Bookmark Links | Jump to sections |
| Email Links | Open email application |
| Image Links | Use images as links |
1. External Links
External links connect to another website.
Example:
<a href="https://www.wikipedia.org">
Visit Wikipedia
</a>
This connects to Wikipedia.
2. Internal Links
Internal links connect webpages inside the same website.
Example:
<a href="about.html">
About Us
</a>
Suppose website files are:
index.html
about.html
contact.html
Internal links connect these pages together.
Example Website Structure
Website Folder
│
├── index.html
├── about.html
├── contact.html
└── services.html
Internal Navigation Example
index.html
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<a href="about.html">About Us</a>
</body>
</html>
about.html
<!DOCTYPE html>
<html>
<head>
<title>About Page</title>
</head>
<body>
<h1>About Us</h1>
<p>This is the about page.</p>
</body>
</html>
3. Target Attribute
The target attribute controls where the link opens.
| Value | Description |
|---|---|
_self | Opens in same tab |
_blank | Opens in new tab |
Example
<a href="https://www.google.com" target="_blank">
Open Google in New Tab
</a>
4. Image as a Link
Images can also be clickable.
Example:
<a href="https://www.youtube.com">
<img src="youtube.png" width="200">
</a>
This creates a clickable image linking to YouTube.
5. Email Links
HTML can open email applications directly.
Syntax:
<a href="mailto:example@gmail.com">
Send Email
</a>
When clicked:
Default email application opens
Receiver address fills automatically
Email Link with Subject
<a href="mailto:test@gmail.com?subject=Hello">
Contact Us
</a>
6. Telephone Links
Used mostly in mobile websites.
Example:
<a href="tel:+919999999999">
Call Now
</a>
Clicking starts a phone call on supported devices.
7. Bookmark Links
Bookmark links jump to a specific section of the same webpage.
Useful for:
Long webpages
Documentation
Tutorials
FAQs
Step 1: Create Target Section
<h2 id="chapter3">Chapter 3</h2>
Step 2: Create Bookmark Link
<a href="#chapter3">
Go to Chapter 3
</a>
Complete Bookmark Example
<!DOCTYPE html>
<html>
<head>
<title>Bookmarks</title>
</head>
<body>
<a href="#bottom">Go to Bottom</a>
<h1>HTML Tutorial</h1>
<p>Lots of content here...</p>
<h2 id="bottom">Bottom Section</h2>
</body>
</html>
Download Links
HTML can provide downloadable files.
Example:
<a href="notes.pdf" download>
Download Notes
</a>
Absolute and Relative URLs
Absolute URL
Full web address.
Example:
https://www.google.com
Relative URL
Local file path.
Example:
about.html
Navigation Menu Using Links
Navigation bars are built using lists and links.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Navigation Menu</title>
</head>
<body>
<h1>My Website</h1>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</body>
</html>
Output Structure
• Home
• About
• Services
• Contact
Styling Navigation Menus
Later, CSS can make menus look professional.
Modern websites like Amazon and Netflix use advanced navigation systems.
Link Colors in HTML
Browsers use default colors:
Blue → Unvisited link
Purple → Visited link
Red → Active link
CSS can customize these colors later.
Complete Practical Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Links Demo</title>
</head>
<body>
<h1>HTML Links Example</h1>
<h2>External Link</h2>
<a href="https://www.google.com">
Visit Google
</a>
<br><br>
<h2>Email Link</h2>
<a href="mailto:test@gmail.com">
Send Email
</a>
<br><br>
<h2>Phone Link</h2>
<a href="tel:+911234567890">
Call Us
</a>
<br><br>
<h2>Bookmark Link</h2>
<a href="#bottom">
Jump to Bottom
</a>
<br><br><br><br><br><br><br><br>
<h2 id="bottom">Bottom Section</h2>
</body>
</html>
Common Mistakes Beginners Make
1. Forgetting href
Wrong:
<a>Google</a>
Correct:
<a href="https://www.google.com">
Google
</a>
2. Wrong File Path
Wrong:
<a href="abot.html">
Correct:
<a href="about.html">
3. Missing Closing Tag
Wrong:
<a href="page.html">Home
Correct:
<a href="page.html">Home</a>
Advantages of HTML Links
Connect webpages
Improve navigation
Enhance user experience
Help SEO
Make websites interactive
Real-World Applications
Links are used in:
Menus
Buttons
Online shopping
Social media
Documentation
Educational websites
Platforms like Facebook, Instagram, and YouTube heavily rely on hyperlinks for navigation.
Conclusion
HTML links are the foundation of website navigation. They connect webpages, websites, documents, and sections together, making the internet a connected system.
Comments
Post a Comment