Home 〉 HTML Tutorials 〉 HTML Anchor Tag ('<a>') - Syntax, Attributes, and Examples for Beginners
HTML Anchor Tag ('<a>') - Syntax, Attributes, and Examples for Beginners !
What is the HTML anchor tag and how is it used in web development?
The HTML anchor tag '<a>' is used to create hyperlinks that link to other pages, files, or sections of a page. This blog post explains the syntax, type, and attributes of the anchor tag with real-world examples and CSS styling tips. We also explored related topics, SEO linking practices, and FAQs. The complete blog post on HTML anchor tag is as follows.
Want to create links on your webpage? The HTML anchor tag ('<a>') is the most commonly used element to create clickable links in a web document. Whether you're linking to another page, an external site, a document, or even a specific section within a page — the anchor tag makes it possible.
This guide will help you understand the anchor tag syntax, its attributes, use cases, and how to style links with CSS.
The '<a>' tag (anchor tag) is used to define a hyperlink. It connects one page to another or to different parts of the same page.
Syntax ✍
<a href="URL">Link Text</a>
It is an inline-level element, meaning it does not start on a new line and only takes up as much width as necessary.
Here are the most important and frequently used attributes of the '<a>' tag:
Specifies the destination URL.
<!DOCTYPE html>
<html>
<body>
<a href="https://www.google.com">Visit Google</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Clicking the link redirects the user to Google.
Specifies where to open the linked document.
<!DOCTYPE html>
<html>
<body>
<a href="https://example.com" target="_blank">Open in New Tab</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Provides additional information on hover.
<!DOCTYPE html>
<html>
<body>
<a href="https://example.com" title="Click to visit Example">Example Site</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Shows a tooltip when hovering over the link.
Prompts file download when clicking the link.
<!DOCTYPE html>
<html>
<body>
<a href="image.jpg" download>Download Image File</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Triggers file download instead of opening the file.
Specifies the relationship between the current and linked document.
<!DOCTYPE html>
<html>
<body>
<a href="https://external.com" rel="nofollow">External Link</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Tells search engines not to pass link equity.
Specifies the MIME type of the linked document (used with 'download' or scripts).
<!DOCTYPE html>
<html>
<body>
<a href="audio.mp3" type="audio/mpeg" download>Download Audio</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Helps browsers identify the content type.
<!DOCTYPE html>
<html>
<body>
<a href="https://example.com" style="color: white; background-color: #007BFF; padding: 10px; border-radius: 5px; text-align: center; display: inline-block; font-size: 16px;">
Visit Example
</a>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The anchor ('<a>') tag is a fundamental part of HTML and is used to create all types of links on a webpage. Understanding its attributes, syntax, and styling options allows you to make your content interactive and user-friendly. It's a small tag with powerful functionality, essential for both navigation and user engagement.
It is used to create hyperlinks to other web pages, files, or locations within the same document.
Yes, you can use attributes like 'href', 'target', 'title', and 'download' together.
It is an inline element by default.
Use CSS inline styling or class-based styling with properties like padding, background-color, border-radius, etc.
It opens the linked page in a new browser tab.