Button onclick href | work like a link in HTML

There are several methods to create an HTML button that acts as a link and using href in onclick event is one of them.

If JavaScript is allowed, set the window.location.href.

<button onclick="window.location.href='page.html'">page</button>

Button onclick href Example

HTML example code:-

The onclick event attribute works when the user click on the button.

<html>
<body>
	<button onclick="location.href='http://www.example.com'">
	www.example.com</button>
</body>
</html>

Output:

Button onclick href

Do comment if you have any doubts and suggestion on this HTML tag topic.

Note: The All HTML Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.