In this section, we introduce the href attribute and will see its purpose in HTML <a> tag.
What is href Attribute in HTML <a> Tag?
As we know, the HTML <a> tag is used to create links to pages of the same or other websites. Now the question is how can we set the URL of the page that we want to link with?
This is where the `href` attribute comes in. This attribute takes one value and that is the URL of the target page that we want to link with.
HTML href Attribute in <a> Tag Syntax:
<a href="URL-address"> <a href= "mailto:emailAddress">
<a> Tag href Attribute Values
The value we set for the href attribute can be an absolute or relative URL of the target page.
Other than URLs, we can set an email address as the value of the href attribute. This is for when we want to use a link to send emails to an email address.
In this case, the email address needs to be prefixed with “mailto:” value.
Example: <a href=”mailto:[email protected]”> contact John </a>
Example: using href attribute in HTML <a> tag
See the Pen using href attribute in HTML <a> tag by Omid Dehghan (@odchan1) on CodePen.