In HTML, you can use the href
attribute on an anchor <a>
tag to redirect the user to another page when they click on the link. The href
attribute can contain a URL or a relative path to the destination page.
<a href="https://www.example.com">Go to Example.com</a>
When the user clicks on the link, they will be redirected to the URL specified in the href
attribute (in this case, https://www.example.com
). Additionally, you can use the target
attribute to open the link in a new window or tab.
<a href="/about">About Us</a>
You can also use relative URLs in the href
attribute to redirect the user to another page within your website.
Note: if you want the link to open in a new window or tab, you can use the target
attribute with the value _blank
, like this:
<a href="https://www.example.com" target="_blank">Go to Example.com</a>
Redirect to another page in HTML using the href example
Simple example code that demonstrates how to use href
to redirect the user to a specific section of a page:
<!DOCTYPE html>
<html>
<head>
<title>Redirect Example</title>
</head>
<body>
<h1>Redirect Example Page</h1>
<p>Click the button below to redirect to another page.</p>
<a href="https://www.google.com">Go to Google</a>
</body>
</html>
Output:
Do comment if you have any doubts or suggestions on this HTML webpage topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version