Skip to content

Button onclick href | work like a link in HTML

  • by

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

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading