The href attribute sets the destination URL for a link or linked resource. On <a>, it creates a hyperlink to a page, file, email address, phone number, or same-page section.
It also appears on <area> (image maps), <base> (document base URL), and <link> (stylesheets, icons, and other resource links). Pair navigation links with clear link text and, when needed, target, rel, or download.
Baseline · Widely available.
Not deprecated and not experimental. Core HTML linking support has been stable across modern browsers for a long time.
Use real destinations — not fake buttons.
Avoid href="#" or javascript:void(0) just to attach a click handler. Use a <button> for actions that are not navigation.
Syntax
HTML Syntax
syntax.html
<a href="url">link text</a>
url can be absolute, relative, a fragment (#id), or a scheme such as mailto: or tel:. The same attribute name is used on area, base, and link.
Use a full URL. Include the scheme (https://) and host for external sites.
Write clear text. “Visit Example.com” describes the destination better than “click here”.
Optional extras. Add target or rel only when you need a new tab or link relation.
Example 2 — Relative Path and Fragment
Link within your site, or jump to an element with a matching id.
HTML
<nav>
<a href="/html">HTML tutorial</a>
<a href="#details">Jump to details</a>
</nav>
<section id="details">
<h2>Details</h2>
<p>Fragment links use # plus an element id.</p>
</section>
mailto: Opens a compose window in the default mail client when available.
tel: Starts a call or offers call-related actions on supporting devices.
Show the contact. Put the address or number in the link text so users know what will open.
Desktop differences. Behavior depends on installed apps; always keep a visible contact fallback.
Edge Cases & Pitfalls
Most link bugs are accessibility or misuse of href as a button hook.
a11y
Avoid “click here”
Link text should make sense out of context. Screen reader users often browse a list of links alone.
buttons
Do not fake buttons with href="#"
# and javascript: URLs break open-in-new-tab, copy link, and semantics. Use <button> for in-page actions.
deprecated
Old anchor attributes
On <a>, name, charset, rev, coords, and shape are deprecated. Use id for targets and <area> for image maps.
blank
target="_blank" needs care
Tell users a new tab will open. Modern browsers imply rel="noopener" with _blank; still prefer clear labeling.
base
<base href> changes resolution
A document <base> affects how relative href values resolve. Check it when relative links go to the wrong place.
Compatibility
Browser Support
href is an HTML attribute for links and linked resources in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
href
Widely available everywhere hyperlinks work. Absolute, relative, fragment, mailto, and tel URLs are supported; app handling for mailto/tel varies by device.
98%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Supported
hrefWidely supported
Bottom line: Safe to use as the standard way to create links. Prefer real URLs, strong link text, and buttons for non-navigation actions.
Remember
Key Takeaways
Role: set the destination URL for a, area, base, and link.
Text: describe the destination; avoid “click here”.
Actions: use <button>, not fake href values, for non-links.
One line:href is the destination — give every link a real URL and clear text.
Frequently Asked Questions
It sets the destination URL for a hyperlink or linked resource. On <a>, it creates a clickable link. It also appears on area, base, and link for image maps, the document base URL, and stylesheets or icons.
The main elements are a, area, base, and link. The most common use is <a href="..."> for navigation.
An absolute URL includes the scheme and host (https://example.com/page). A relative URL is resolved from the current page or document base (about.html, /html, ../images/logo.png).
Use href="#section-id" to jump to an element with a matching id on the same page (or on the target page). Prefer id over the deprecated name attribute.
No. Fake links with # or javascript:void(0) break accessibility and browser features. Use a <button> for actions that are not navigation.
No. Without href, <a> is not a hyperlink (it has a generic role). Add href when the element should navigate somewhere.