HTML Links: Anchor Tags, URLs and Page Fragments
Learn how to create HTML links with anchor elements, relative and absolute URLs, email and phone links, and page fragments.
Create a link
The <a> element creates a link. Its href attribute gives the destination. Use link text that makes the destination clear.
<a href="html-images.htm">Learn about HTML images</a>
Use different URL forms
An absolute URL includes the scheme and domain, such as https://example.com/guide/. A relative URL is resolved from the current page, such as html-images.htm. A root-relative URL begins at the website root, such as /about-us/.
Link to a section
Give a destination element a unique id, then add that ID as a fragment to the link.
<a href="#contact-details">Jump to contact details</a>
<h2 id="contact-details">Contact details</h2>
Email, phone and new-tab links
Use mailto: for an email link and tel: for a phone number. When a link opens a new tab with target="_blank", tell users and add rel="noopener".
<a href="mailto:hello@example.com">Email us</a>
<a href="tel:+15551234567">Call us</a>
<a href="https://example.com/" target="_blank" rel="noopener">
Visit Example (opens in a new tab)
</a>
Choose the element by its purpose: use an anchor to navigate to another URL or page section, and use a <button> for an action on the current page, such as opening a dialog or submitting a form. Descriptive link text helps people understand a destination without guessing from “click here.”
Common link mistakes
- Check that every
hrefpoints to a real destination; an empty or misspelled path can create a broken link. - Give each fragment target a matching, unique
id. The fragment is case-sensitive in practice when matching the identifier. - Do not use
href="#"as a substitute for a button. It can jump the page to the top and does not describe an action. - If a new tab would surprise the visitor, keep the link in the same tab. Explain the behavior when you do open a new tab.
Modern browsers implicitly apply noopener behavior to target="_blank"; stating it in the markup still makes the intent clear. Add noreferrer only when you also want to omit referrer information from the request.
Examples
- View the link basics example (opens in a new tab)
- View the fragment link example (opens in a new tab)
See MDN's anchor element reference for more link attributes and behaviors.