HTML <a> Tag

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

Definition and Usage

The <a> (anchor) element creates a hyperlink. With href, it points to a page, file, email address, phone number, or a place in the same document.

Put clear destination text inside the tag. Use target, rel, and download when you need a new tab, link relationship, or file save. For actions that are not navigation, use <button> instead.

Baseline · Widely available.

Not deprecated. Core hyperlink support has been stable across browsers since about July 2015 (and much earlier in practice).

Deprecated attributes.

Do not use charset, coords, name, rev, or shape on <a>. Prefer id for in-page targets and <area> for image maps.

Experimental extras.

attributionsrc (Attribution Reporting) and interestfor (interest invokers) are newer and have limited support — skip them until you need those APIs.

HTML Syntax

syntax.html
<a href=" url">link text</a>

Both start and end tags are required. Nested interactive content (another <a>, buttons, etc.) is not allowed. Without href, the element is not a link.

Attributes

The attributes you will use most often on <a>:

AttributeDescriptionTry it
hrefDestination URL: absolute, relative, #id, mailto:, tel:, and moreTry it
targetWhere to open the URL: _self (default), _blank, _parent, _topTry it
relLink relationship tokens, e.g. noopener, noreferrer, nofollowTry it
downloadHint to save the resource; optional filename. Best for same-origin filesTry it
hreflangHint for the language of the linked document (no built-in browser UI)Try it
typeAdvisory MIME type of the linked resource (hint only)Try it
referrerpolicyHow much referrer data to send when following the linkTry it
pingSpace-separated URLs that receive a PING POST when the link is followed (tracking)See edge cases

Global Attributes

The <a> tag also supports the Global Attributes in HTML.

Live Preview

Change href and target on a real link, then open or inspect it.

A real <a>. Apply values, then follow or inspect the link.

Link

Sample link

href="https://www.example.com" target="_self"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic Hyperlink

Create a normal link with descriptive text and an absolute href.

HTML
<p>
  Learn more on the
  <a href="https://www.example.com/docs">HTML documentation</a>.
</p>
Try It Yourself

How It Works

  1. Open with <a>. The destination goes in href.
  2. Write useful link text. Prefer “HTML documentation” over “click here”.
  3. Close the tag. Both start and end tags are required.
  4. Activate. Click, tap, or press Enter when focused to follow the URL.

Example 2 — Open in a New Tab

Use target="_blank" and tell the user a new tab will open.

HTML
<p>
  <a
    href="https://www.wikipedia.org"
    target="_blank"
    rel="noopener noreferrer"
  >
    Wikipedia (opens in new tab)
  </a>
</p>
Try It Yourself

How It Works

  1. Set the URL. href is still the destination.
  2. Choose a context. target="_blank" opens a new tab or window.
  3. Add rel. noopener (and often noreferrer) is a safe habit; modern browsers also treat _blank as implicitly noopener.
  4. Warn in the text. Unexpected new tabs confuse many users (MDN accessibility guidance).

Example 3 — Same-Page Section Jump

Link to an element id with a fragment identifier.

HTML
<p><a href="#pricing">Jump to pricing</a></p>

<h2 id="pricing">Pricing</h2>
<p>Plans start at $0 for learning projects.</p>
Try It Yourself

How It Works

  1. Give the target an id. Example: id="pricing" on a heading or section.
  2. Point href at that id. Use #pricing (hash + id value).
  3. Activate the link. The browser scrolls to that element.
  4. Top of page. href="#top" or href="#" jumps to the top of the current page.

Example 4 — Email and Phone Links

Use URL schemes so devices can open mail or dialer apps.

HTML
<ul>
  <li><a href="mailto:[email protected]">Email us</a></li>
  <li><a href="tel:+18005551234">Call +1 (800) 555-1234</a></li>
</ul>
Try It Yourself

How It Works

  1. Email: mailto: plus an address opens the default mail app.
  2. Phone: tel: plus a number (often with country code) starts a call on capable devices.
  3. Show the value in the text when helpful, especially for phone numbers.
  4. Optional extras: mailto: can include ?subject= and &body= query parts.

Example 5 — Suggest a File Download

Use download so the browser prefers saving the file instead of navigating to it.

HTML
<p>
  <a href="/images/codetofun-logo.png" download="codetofun-logo.png">
    Download logo PNG
  </a>
</p>
Try It Yourself

How It Works

  1. Point href at a file the browser can fetch (image, PDF, etc.).
  2. Add download. Alone, the browser picks a name; with a value, that name is suggested.
  3. Same-origin first. Cross-origin URLs often ignore download and navigate instead.
  4. Say what happens. Link text like “Download logo PNG” sets clear expectations.

Edge Cases & Pitfalls

Most link bugs come from weak text, fake buttons, or surprising new tabs.

a11y

Avoid “click here”

Screen reader users often browse a list of links. Text must make sense out of context.

semantics

Do not fake buttons with href="#"

Copying, middle-click, and no-JS all break. Use <button> for actions.

security

target="_blank" needs care

Warn in link text. Prefer explicit rel="noopener" (modern browsers also apply it implicitly for _blank).

nesting

No nested links

An <a> cannot contain another interactive control or nested <a>.

privacy

ping sends tracking POSTs

Space-separated URLs get a PING body when the link is followed. Support and user controls vary; do not rely on it alone.

Browser Support

The <a> element is core HTML in every browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<a>

Widely available since about July 2015 (and long before as HTML anchors). Chrome, Firefox, Safari, Edge, and Opera all support hyperlinks fully. Some attributes such as ping or download on cross-origin URLs vary.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
<a> Widely supported

Bottom line: Safe to use everywhere for navigation. Treat download cross-origin behavior, ping, and experimental attributes as progressive extras.

Key Takeaways

  • Role: <a href="…"> creates real navigation — not a stand-in for buttons.
  • Text: describe the destination; avoid empty or “click here” links.
  • Schemes: pages, #id, mailto:, tel:, and downloads are all valid destinations.
  • New tabs: warn users; pair target="_blank" with clear rel.

One line: a good <a> has a real href and link text that names the destination.

Default CSS Settings

Browsers style links in the user-agent stylesheet. Exact colors use system keywords such as LinkText today; the classic idea looks like this:

default.css
a:link {
  color: blue;
  text-decoration: underline;
  cursor: auto;
}

a:visited {
  color: purple;
  text-decoration: underline;
  cursor: auto;
}

a:link:active,
a:visited:active {
  color: red;
}

Override carefully: keep a clear visited/unvisited difference when it helps, and never remove focus styles for keyboard users.

Frequently Asked Questions

The a (anchor) element creates a hyperlink to a web page, file, email address, phone number, or a section on the same page when you set the href attribute.
For a real, activatable link, yes — include href. Without href, the element is not a link (its implicit ARIA role becomes generic). Prefer a button for actions that are not navigation.
Use target="_blank". Modern browsers treat that as implicitly noopener. Adding rel="noopener noreferrer" is still a clear, portable habit, and warn users in the link text that a new tab opens.
Set href to a fragment that matches an element id, for example href="#pricing" jumps to <section id="pricing">. href="#top" or href="#" jumps to the top of the page.
Use href="mailto:[email protected]" for email and href="tel:+18005551234" for phone numbers. On capable devices, the OS opens the mail or dialer app.
No. It works reliably for same-origin URLs, blob:, and data: URLs. Cross-origin links often ignore download and navigate normally unless the server sends Content-Disposition.

Next: abbr

Mark abbreviations and expand them with the title attribute.

abbr tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful