HTML Link Tag — The Anchor Element
Links are what make the web a web. The HTML anchor tag
<a> is one of the most powerful and most-used elements in
all of HTML. In this chapter you'll learn every type of link, every key attribute, and the
best practices that professional developers follow.
<a> tag
and what every part meanshref, target, rel, title, downloadtarget="_blank"What is the HTML Anchor Tag?
The <a> tag — short for
anchor — creates a hyperlink. It can link to another webpage, a section on the same page,
an email address, a phone number, or a downloadable file. Without the <a> tag there would be no navigation on the web.
The most important attribute is href (Hypertext
Reference), which specifies the destination of the link. The visible, clickable text placed between the
opening and closing tags is called the link text or anchor text.
Key Attributes of the <a> Tag
The anchor tag supports several important attributes. Here is a complete reference:
| Attribute | Purpose | Example Value |
|---|---|---|
| href | The destination URL or target — the only required attribute for a working link | "https://k2infocom.com" |
| target | Where to open the link — same tab (_self, default) or new tab
(_blank) |
"_blank" |
| rel | Relationship between the page and the link destination — used for SEO and security | "noopener noreferrer" |
| title | Tooltip text shown on hover — provides extra context about the link | "Go to K2infocom homepage" |
| download | Prompts the browser to download the linked file instead of navigating to it | "cheatsheet.pdf" |
| href="#id" | Links to an element with that id on the same page — called an
anchor link |
"#contact" |
Types of HTML Links
The anchor tag can create many different kinds of links depending on what you put in
the href attribute:
https://. Add target="_blank" to open in a new tab, and always
include rel="noopener noreferrer" for security.mailto: scheme in the
href.
tel: scheme. Always include the country code for
international numbers.download attribute — optionally give it a value to set the default filename the user
sees.id attribute — also
called an in-page anchor link. Commonly used in navigation menus, "Back to top"
buttons, and table-of-contents links.The target Attribute & Security with
rel
The target attribute controls where the linked
page opens. The most used value is _blank — but it must always be paired
with rel="noopener noreferrer" for security.
target is omitted. Use for all internal page links.rel="noopener noreferrer" to prevent a security vulnerability called
tab-napping.window.opener — blocking a type of phishing attack.
noreferrer hides the referring URL from the destination site. Together they are the
security standard for any target="_blank" link.
target="_blank", you must also add
rel="noopener noreferrer". Without it, the opened page can use
JavaScript to redirect your page — a real security vulnerability known as reverse tab-napping.
Code Examples — All Link Types Together
Here are all link types shown in a single working HTML block:
<!-- 1. External link — opens in new tab -->
<a href="https://k2infocom.com"
target="_blank"
rel="noopener noreferrer"
title="Visit K2infocom">
Visit K2infocom
</a>
<!-- 2. Internal link — same site, relative path -->
<a href="/courses.html">Our Courses</a>
<!-- 3. Email link -->
<a href="mailto:hello@k2infocom.com">Email Us</a>
<!-- 4. Phone link -->
<a href="tel:+919876543210">Call Us</a>
<!-- 5. Download link -->
<a href="/files/cheatsheet.pdf"
download="HTML-CheatSheet.pdf">
Download Cheat Sheet
</a>
<!-- 6. Anchor / jump link -->
<a href="#contact">Jump to Contact</a>
<!-- Target section (anywhere on page) -->
<section id="contact">
<h2>Contact Us</h2>
</section>
Using an Image as a Link
You can make any element clickable by wrapping it inside an <a> tag. One very common use case is wrapping an image to make it a
clickable link:
<!-- Clickable logo that links to the homepage -->
<a href="/index.html" title="Go to homepage">
<img
src="/images/logo.png"
alt="K2infocom Logo"
width="180"
>
</a>
alt attribute on <img> serves as the link's accessible label for screen readers. Always
write a descriptive alt text that describes where the link goes — e.g.
alt="K2infocom Homepage".
Common Mistakes — Do's & Don'ts
Here are the most frequent link mistakes beginners make:
<!-- Descriptive anchor text -->
<a href="/courses.html">
View all courses
</a>
<!-- _blank always with rel -->
<a href="https://..."
target="_blank"
rel="noopener noreferrer">
Docs
</a>
<!-- Vague anchor text — bad for SEO -->
<a href="/courses.html">
click here
</a>
<!-- _blank without rel — security risk -->
<a href="https://..."
target="_blank">
Docs
</a>
Complete Example — Navigation with All Link Types
Here is a realistic HTML page demonstrating all link types working together in a typical website layout:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>K2infocom</title>
</head>
<body>
<!-- Navigation with internal links -->
<nav>
<a href="/index.html">Home</a>
<a href="/courses.html">Courses</a>
<a href="#contact">Contact</a>
</nav>
<!-- External link -->
<p>
Read the official
<a href="https://developer.mozilla.org"
target="_blank"
rel="noopener noreferrer">
MDN Web Docs
</a>
</p>
<!-- Download link -->
<a href="/files/html-cheatsheet.pdf"
download="HTML-CheatSheet.pdf">
Download HTML Cheat Sheet
</a>
<!-- Contact section (anchor target) -->
<section id="contact">
<h2>Contact Us</h2>
<a href="mailto:hello@k2infocom.com">
hello@k2infocom.com
</a>
<a href="tel:+919876543210">
+91 98765 43210
</a>
</section>
</body>
</html>
Try It Yourself
Edit the links below and click Open in Editor to test them live in full screen.
<section id="bottom"> element. This is the anchor / jump link
behaviour in action, with no JavaScript required.
Quick Check — Chapter 6
Expand each question to check your understanding before moving on to the multiple choice quiz.
href stands for Hypertext Reference. It is the
attribute that specifies the destination of the link — where the browser should
navigate to when the user clicks it. Without href, the <a> tag renders as text with no clickable behaviour. The value can
be a full URL (https://...), a relative path (/about.html), an email (mailto:...),
a phone number (tel:...), or a page section (#id).
rel="noopener noreferrer", a page opened with target="_blank" can access your page through window.opener in JavaScript. A malicious site could use this to
redirect your page to a phishing site while the user is looking at the new tab — this
attack is called reverse tab-napping. noopener cuts
the window.opener reference, and noreferrer also hides your page URL from the destination site. Together
they are the security standard for any external link that opens in a new tab.
https://. An internal
link points to another page on the same website — it uses a relative path (e.g.
/about.html or ../courses/index.html). Internal links use relative paths so the site
still works correctly if the domain changes. External links should include target="_blank" and rel="noopener noreferrer" while internal links typically open in the
same tab.
href value that starts with # followed by an ID — for example href="#contact". When clicked, the browser scrolls directly to
the element on the page that has the matching id
attribute — e.g. <section id="contact">. The id attribute must be unique on the page — no two
elements should share the same id. Jump links are used in
table-of-contents navigation, "Back to Top" buttons, and long single-page layouts.
mailto: scheme in the
href attribute: <a href="mailto:hello@example.com">Email Us</a>. Clicking it
opens the user's default email client with the address pre-filled. You can also add a subject: mailto:email@example.com?subject=Hello. For a phone
link, use the tel: scheme: <a href="tel:+919876543210">Call Us</a>. On mobile this
dials the number directly; on desktop it may open a VoIP application.
target opens a link in a new
browser tab?href scheme is used to create a link
that opens the user's email client?target="_blank" for security?- The
<a>(anchor) tag creates hyperlinks. Thehrefattribute is required — it sets the link destination. - External links use a full URL (
https://...). Internal links use relative paths (/page.html). - Use
target="_blank"to open links in a new tab. Always pair it withrel="noopener noreferrer"to prevent reverse tab-napping. mailto:opens the email client.tel:opens the phone dialler. Both are fully supported on all modern browsers and mobile devices.- The
downloadattribute triggers a file download instead of navigation. Give it a value to set the suggested filename. - Anchor links (
href="#id") scroll the page to the element with a matchingid— no JavaScript needed. - Always write descriptive link text — never "click here". Good anchor text improves SEO and accessibility for screen reader users.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions, and stay updated with new tutorials.