- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <a> Tag
HTML Tags
HTML <a> Tag
The a tag makes links: to another page, a file, an email address, or a section of the same page. The text inside is what people click, and the href is where it goes. Everything else is optional.
The many kinds of links are covered with examples in HTML Links. This is the tag reference.
Syntax
html
<a href="URL">Link Text</a>| Attribute | What it does |
|---|---|
| href | The destination: a web address, a file, #id for a section, mailto: or tel:. |
| target | Where it opens. _blank opens a new tab. |
| download | Downloads the file instead of opening it. Works only for files on the same site. |
| rel | The relationship to the target, such as nofollow, noopener or noreferrer. |
| hreflang | The language of the linked page. |
| title | Extra information shown on hover. Not a replacement for clear link text. |
Example
html
<!DOCTYPE html>
<html>
<head>
<title>Anchor Tag Example</title>
<style>
a {
color: #29AB87;
text-decoration: none;
font-weight: bold;
}
a:hover {
color: #1c7a63;
text-decoration: underline;
}
</style>
</head>
<body>
<h1>HTML <a> Tag Example</h1>
<p>
Visit our official website:
<a href="https://html5andcss3.org" target="_blank" title="Visit HTML5 and CSS3 Official Site">
HTML5 and CSS3
</a>
</p>
<p>
Download a sample PDF file:
<a href="https://ik.imagekit.io/html5andcss3/lesson-samples/sample.pdf" download="sample.pdf">Download PDF</a>
</p>
<p>
Send us an email:
<a href="mailto:info@html5andcss3.org">info@html5andcss3.org</a>
</p>
<p>
Jump to a section on this page:
<a href="#about">Go to About Section</a>
</p>
<h2 id="about">About Section</h2>
<p>This section explains the working of the anchor tag in HTML.</p>
</body>
</html>The example shows four kinds of link: one to a website that opens in a new tab, one to a PDF, one email link, and one that jumps down to the "About Section" on the same page.
The PDF is on another domain, so most browsers ignore download and simply open it. For a real download, the file must be on your own site, or the server must send it as an attachment.
About target="_blank"
Opening links in a new tab breaks the back button and can disorient people, so use it only when it really helps, such as a help link in the middle of a form, and say so in the link text. Modern browsers automatically treat target="_blank" as rel="noopener", so the old security warning about it no longer applies, but adding rel="noopener" does no harm.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Good to know
HTML <a> Tag exercises
Link to a page
Add a link that says Docs and goes to /docs
Result
