🔗 HTML <a>
Tag — Creating Hyperlinks
The <a>
tag, also known as the anchor tag, is one of the most important and widely used HTML elements. It defines a hyperlink, which allows users to navigate from one webpage or resource to another by clicking the linked text or object.
📌 What Is the <a>
Tag?
- Defines a hyperlink to another webpage, file, location, email address, or any URL.
- Can link to internal page anchors, external sites, or email addresses.
- Inline element, typically rendered as clickable text with underline and blue color by default.
- Supports many attributes to control behavior and appearance.
✅ Basic Syntax
<a href="https://www.example.com">Visit Example.com</a>
Here, the href
attribute specifies the destination URL.
🧪 Example: Common Use Cases
- Link to an external website
<a href="https://www.wikipedia.org" target="_blank" rel="noopener noreferrer">Wikipedia</a>
target="_blank"
opens the link in a new tab.rel="noopener noreferrer"
improves security and performance.
- Link to an email address
htmlCopyEdit<a href="mailto:info@example.com">Send Email</a>
- Link to a specific part of the page (anchor link)
<a href="#section2">Go to Section 2</a>
<!-- Later in the page -->
<h2 id="section2">Section 2</h2>
🎨 Attributes of <a>
Attribute | Description |
---|---|
href | URL or link destination (required for link) |
target | Where to open the linked document (_self , _blank , etc.) |
rel | Relationship between current and linked document (e.g., nofollow , noopener ) |
title | Additional info shown on hover |
download | Suggests the browser download the target file |
hreflang | Language of the linked resource |
type | MIME type of the linked resource |
⚠️ Best Practices
- Always include meaningful link text — avoid generic phrases like “click here”.
- Use
rel="noopener noreferrer"
withtarget="_blank"
to improve security. - Ensure
href
points to a valid URL or resource. - Use semantic links for accessibility; screen readers rely on link text.
- Avoid empty
href
attributes; use<button>
if no navigation is intended.
🏁 Summary
The <a>
tag is fundamental for web navigation, creating clickable links to resources inside or outside your site. Proper use of attributes and accessible link text ensures a better user experience and SEO.