HTML Links <a>
HTML Living Standard
An anchor with href gives the browser a destination. The visible label tells people where following the link takes them.
On this page
What is a link?
A link gives the reader a way to open a destination. The a element, also called an anchor, creates a link when href supplies its destination address. The words between the tags are what the reader sees and activates.
How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.
<a href="https://developer.mozilla.org/">Read MDN Web Docs</a>
What to expect Click the link to open MDN. Use the browser’s Back button to return to your file.
How a link opens a URL
The browser resolves href against the current page URL. An absolute URL includes the protocol and host. A path such as catalog.html is relative to the current directory. A path beginning with / starts at the website root. A link with href is normally reachable with Tab and activated with Enter.
How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.
<a href="https://developer.mozilla.org/">Read MDN Web Docs</a>
<a href="catalog.html">Open the product catalog</a>
<a href="/resources">Learning resources</a>
What to expect If the page URL is https://example.com/shop/index.html, catalog.html resolves to /shop/catalog.html and /resources resolves to https://example.com/resources.
Jump to a section with #id
A fragment starts with #. The browser finds the element whose id matches the fragment and brings it into view. Each id in one document should be unique. Give the link a label that names the destination so it makes sense even when read by itself.
How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.
<a href="#contact">Jump to contact details</a>
<h2 id="contact">Contact</h2>
<p>Visit us on Market Street.</p>
What to expect Activate the link. The address ends with #contact and the browser scrolls to the heading if needed.