What is the use of the <a> tag?

LowEasyHtml
Preparing for interviews?

Use guided tracks for structured prep, then practice company-specific question sets when you want targeted interview coverage.

Quick Answer

The <a> (anchor) tag in HTML is used to create hyperlinks that allow users to navigate from one page or resource to another. It is one of the most essential tags for connecting documents and enabling web navigation.

Answer

Definition and Purpose

The <a> tag, also known as the anchor element, is used to define hyperlinks — clickable links that connect one web page, document, or section to another. It can link to external websites, internal pages, specific sections within the same page, email addresses, files for download, or even trigger scripts.

Without <a> tags, the web would be a collection of isolated documents without any way to navigate between them.

Basic Syntax

`html
<a href="https://www.example.com">Visit Example</a>

  • href` (Hypertext Reference): The most important attribute, defining the URL or target destination of the link.
  • Link Text: The visible text between the opening <a> and closing </a> tags becomes the clickable portion.

Common Attributes

The <a> tag supports several attributes to control link behavior:

  • href – Specifies the destination URL or path (can be absolute or relative).
  • target – Determines how to open the link (e.g., _blank for a new tab, _self for the same tab).
  • title – Provides additional information shown as a tooltip on hover.
  • download – Prompts a download instead of navigation.
  • rel – Defines the relationship between the current document and the linked resource (e.g., noopener, nofollow, external).

Attribute

Description

Example

href

Specifies the link destination

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

target

Controls where to open the link

<a target='_blank'> opens in a new tab

title

Displays tooltip text on hover

<a title='Learn more'>

download

Forces file download instead of opening

<a href='file.pdf' download>

rel

Defines link relationship (security, SEO)

<a rel='noopener noreferrer'>

Common attributes of the `<a>` tag and their uses.

Examples of Usage

External link:
`html
<a href="https://developer.mozilla.org/">MDN Web Docs</a>

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

Anchor link (within same page):
html
<a href="#contact">Go to Contact Section</a>

Email link:
html
<a href="mailto:info@example.com">Send us an email</a>

File download:
html
<a href="/files/report.pdf" download>Download Report</a>
`

Accessibility and Best Practices

  • Always use descriptive link text (e.g., 'Read our Privacy Policy' instead of 'Click here').
  • Avoid nesting block-level elements inside <a> unless necessary (HTML5 allows limited use for accessibility).
  • Use the rel attribute (like noopener noreferrer) when opening links in new tabs to prevent security risks.
  • For navigation menus, combine <a> with semantic containers like <nav> for better structure and screen reader support.

Visual Behavior

By default, browsers style hyperlinks as blue and underlined when unvisited, purple when visited, and red when active. These colors can be customized using CSS (e.g., a { color: #007bff; text-decoration: none; }).

Still so complicated?

Think of <a> as a bridge between destinations. The href attribute is the address of where that bridge leads. Without it, the link is just text — but with it, it becomes a doorway to another page, file, or even a specific section of the same document.

Summary

The <a> tag defines hyperlinks that enable navigation across the web. It is one of the core building blocks of HTML that transforms static pages into a connected web of resources. Using attributes like href, target, and rel, developers can control how and where users navigate while maintaining accessibility, security, and usability.

Similar questions
Guides
27 / 27