The <a> href attribute is used to set the link i.e. the URL of the page.
Syntax
Following is the syntax −
<a href="URL">
Above, URL is the url you need to mention, which can be a relative link, absolute link, script, protocol, etc.
Example
Let us now see an example to implement the href attribute of the <a> element −
<!DOCTYPE html> <html> <body> <h2>Learning is Fun</h2> <p> Learn the concepts of <a href="https://tutorialspoint.com/java">Java!</a> Also try JavaScript from our website: <a href="/javascript">JavaScript!</a> </a> </p><br> </body> </html>
Output
This will produce the following output −
Example
Let us see another example wherein we can set the email-id of a user with a href −
<!DOCTYPE html> <html> <body> <h2>Learning is Fun</h2> <p> Learn the concepts of <a href="https://tutorialspoint.com/java">Java!</a> Also try JavaScript from our website: <a href="/javascript">JavaScript!</a> <p>For more tutorials, kindly <a href="mailto:[email protected][email protected]&subject=DEMO EMAIL">EMAIL</a></p> </a> </p><br> </body> </html>
Output
This will produce the following output −
If you will run the above on a system and click the EMAIL, then it will open the following application for email, which is set as default. Here, we have set the default email application as OUTLOOK −