HTML Anchor Tag (a): A Complete Guide for Beginners

The HTML Anchor Tag is one of the most important tags in HTML.

It is used to create links (hyperlinks) between web pages.

Without the anchor tag, the internet would not work the way it does today.

In this beginner-friendly guide, you will learn:

  • What the HTML anchor tag is

  • How to create links

  • Important attributes

  • Internal and external links

  • Real examples

  • Common mistakes

  • Best practices

Let’s start learning step by step.

What Is the HTML Anchor Tag?

The HTML anchor tag <a> is used to create hyperlinks.

Hyperlinks allow users to:

  • Go to another webpage

  • Open a file

  • Jump to another section

  • Send an email

  • Make a phone call

In simple words, the anchor tag connects pages together.

Basic Syntax of HTML Anchor Tag

<a href="URL">Link Text</a>

Explanation:

  • <a> → Opening anchor tag

  • href → Specifies the link destination

  • Link Text → Clickable text

  • </a> → Closing tag

Simple Example

<a href="https://www.google.com">Visit Google</a>

When clicked, it opens Google.

Types of Links in HTML

External Links

Links that go to another website.

<a href="https://www.wikipedia.org">Visit Wikipedia</a>

Internal Links

Links within your own website.

<a href=”mailto:example@email.com”>Send Email</a>
 

Clicking opens email software.

<a href="about.html">About Us</a>

This connects to another page in the same folder.

Anchor Links (Jump Links)

Used to jump to a section on the same page.

Step 1: Add ID to Section

<h2 id="contact">Contact Us</h2>

Step 2: Link to That Section

<a href="#contact">Go to Contact Section</a>

Email Links

<a href=”mailto:example@email.com”>Send Email</a>
 

Clicking opens email software.

Phone Links

<a href=”tel:+911234567890″>Call Us</a>
Works on mobile devices.

Important Attributes of Anchor Tag

href (Required)

Defines the destination URL.

<a href=”https://example.com”>Visit</a>
 

target Attribute

Defines where to open the link.

<a href=”https://example.com” target=”_blank”>Open in New Tab</a>
 

Common Values:

  • _self → Same tab (default)

  • _blank → New tab

  • _parent

  • _top

title Attribute

Shows tooltip text on hover.

<a href=”about.html” title=”Learn more about us”>About</a>
 

rel Attribute (Security & SEO)

Used with _blank.

<a href=”https://example.com” target=”_blank” rel=”noopener noreferrer”>
Visit Website
</a>
Improves security and performance.
<!DOCTYPE html>
<html>
<head>
    <title>Anchor Tag Example</title>
</head>
<body>

<h2>HTML Anchor Tag Example</h2>

<p>
<a href="https://www.google.com" target="_blank">
Visit Google
</a>
</p>

<p>
<a href="#bottom">Go to Bottom</a>
</p>

<h3 id="bottom">You reached the bottom!</h3>

</body>
</html>

Anchor Tag vs Button (Comparison Table)

FeatureAnchor Tag <a>Button <button>
Used for navigation✅ Yes❌ No
Used for actions (forms)❌ No✅ Yes
Requires href✅ Yes❌ No
Redirects to another page✅ YesWith JS

Use anchor tag for navigation and button for actions.

Step-by-Step Guide to Create a Link

Step 1: Open HTML File

Use VS Code, Notepad, or any editor.

Step 2: Write Anchor Tag

 
 
<a href=”https://example.com”>Visit Site</a>
 

Step 3: Save File

Save with .html extension.

Step 4: Open in Browser

Click the link to test.

Real-World Use Cases

The HTML anchor tag is used in:

  • Navigation menus
  •  Footer links
  •  Blog post links
  •  Download buttons
  •  Social media icons
  •  Internal linking for SEO

Common Beginner Mistakes

  • Forgetting the href attribute
  •  Using “click here” everywhere
  •  Opening all links in new tabs
  •  Using links for buttons incorrectly
  •  Putting block elements incorrectly (old HTML)

Example (Navigation Menu):

<nav>
    <a href="index.html">Home</a>
    <a href="about.html">About</a>
    <a href="contact.html">Contact</a>
</nav>

Common Mistakes Beginners Make

1. Missing href Attribute

Wrong:

<a>Click Here</a>
 

Correct:

<a href=”#”>Click Here</a>
 

 2. Forgetting Quotes

Wrong:

 
<a href=https://example.com>Visit</a>
 

Correct:

<a href=”https://example.com”>Visit</a>
 

 3. Using Button Instead of Anchor

Navigation should use <a>, not <button>.

4. Not Using rel with _blank

Always add:

 
rel=”noopener noreferrer”

Best Practices for HTML Anchor Tag

  • Use descriptive link text (not “Click Here”)
  •  Use target=”_blank” for external links
  •  Add rel attribute for security
  •  Keep URLs clean
  •  Use internal links for better SEO
  •  Avoid broken links

Good Example:

<a href=”html-headings.html”>Learn HTML Headings</a>
 

Bad Example:

<a href=”page1.html”>Click Here</a>
 

Descriptive text improves SEO.

SEO Benefits of Anchor Tag

Anchor tags are essential for:

  • Internal linking

  • Page authority distribution

  • Better crawling by search engines

  • Improved user experience

Internal links help search engines understand website structure.

FAQs: HTML Anchor Tag

What is the HTML anchor tag used for?

To create hyperlinks.

Is the <a> tag inline or block?

Inline by default (can be styled as block).

Can an anchor wrap block elements?

Yes, in HTML5.

Does anchor tag affect SEO?

Yes, through link text and structure.

Can I style anchor tags with CSS?

Yes, fully customizable.

Read More

How to Create Database in MySQL

  • By admin
  • November 27, 2021
  • 44 views
How to Create Database in MySQL

How to create table in MySQL

  • By admin
  • November 6, 2021
  • 40 views
How to create table in MySQL

MySQL commands with examples

  • By admin
  • September 11, 2021
  • 95 views
MySQL commands with examples

MySQL use database

  • By admin
  • May 28, 2021
  • 40 views
MySQL use database

System Software

  • By admin
  • May 20, 2021
  • 49 views

Introduction to software

  • By admin
  • May 13, 2021
  • 44 views
Introduction to software