HTML href Attribute

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

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.

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.

Attribute Values

Common href value forms:

ValueDescriptionTry it
Absolute URLFull address, e.g. https://example.comTry it
Relative URLPath from the current page or site root, e.g. /htmlTry it
FragmentSame-page jump, e.g. #detailsTry it
mailto: / tel:Open email or phone apps with a contact addressTry it
On <link>Resource URL for CSS, icons, and similarTry it

Live Preview

Change the href value on a real link. Hover or inspect the link to confirm the destination.

A real <a>. Apply a destination, then open or inspect the link.

Link

Sample link

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

HTML Examples

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

Example 1 — Absolute URL

Point to a full web address with the protocol included.

HTML
<p>
  <a href="https://www.example.com">Visit Example.com</a>
</p>
Try It Yourself

How It Works

  1. Add href. Without it, <a> is not a hyperlink.
  2. Use a full URL. Include the scheme (https://) and host for external sites.
  3. Write clear text. “Visit Example.com” describes the destination better than “click here”.
  4. 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>
Try It Yourself

How It Works

  1. Relative path. /html starts from the site root and stays portable on your domain.
  2. Fragment. #details scrolls to the element whose id is details.
  3. Match the id. The target must use id, not the deprecated name attribute on anchors.
  4. Same page or other page. You can also write page.html#details to open another file at a section.

Example 3 — mailto: and tel:

Special URL schemes open the user’s mail or phone app when supported.

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

How It Works

  1. mailto: Opens a compose window in the default mail client when available.
  2. tel: Starts a call or offers call-related actions on supporting devices.
  3. Show the contact. Put the address or number in the link text so users know what will open.
  4. 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.

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 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
href Widely 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.

Key Takeaways

  • Role: set the destination URL for a, area, base, and link.
  • Forms: absolute, relative, #fragment, mailto:, tel:.
  • 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.

Next: hreflang

Hint the human language of a linked URL.

hreflang 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.

8 people found this page helpful