The HTML href attribute
The HTML href attribute specifies the URL the link points to. It is used on the <a>, <area>, <link> and <base> elements.
Overview
The href (hypertext reference) attribute specifies the URL a hyperlink points to. On an <a> it is what makes the element an actual link — an <a> with no href is just a placeholder, not focusable or operable as a link. It is also used on <link> (to reference stylesheets and other resources), <area> and <base>.
It accepts several URL forms: absolute (https://example.com/page), root-relative (/about/), document-relative (page.html), fragment links (#section, which scroll to an element on the same page), and special schemes such as mailto: for email, tel: for phone numbers and sms: for text messages.
For accessibility and SEO, write descriptive link text rather than "click here" — screen-reader users often browse a list of links out of context. And reserve <a> for navigation: for a control that runs JavaScript, use a real <button> instead of an <a href="#">.
Syntax
<a href="https://example.com">Visit</a>
Values
| Value |
|---|
A URL — absolute, relative, or a special scheme such as mailto:, tel: or a #fragment. |
Example
<a href="https://codeshack.io/">Visit the CodeShack homepage</a>
Best practices
Frequently asked questions
What does the href attribute do?
What is an <a> without href?
href to make it a real link.How do I make an email or phone link?
href="mailto:name@example.com" for email or href="tel:+15551234" for phone.How do I link to a section on the same page?
href="#id", pointing at the id of the target element.