Button with href | Adding Href to Button example code

If JavaScript is allowed, set the window.location.href to create Button with href.

<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />

Instead of <input type="button"> in above example, you can also use <button>. The only difference is that the <button> element allows children.

The plain HTML way is to put it in a <form> wherein you specify the desired target URL in the action attribute.

<form action="https://google.com">
    <input type="submit" value="Go to Google" />
</form>

HTML Button with href Example code

HTML example code

<html>
<body>

	<input type=button onClick="location.href='index.html'"
	value='click here'>
	
</body>

</html>

Output:

Button with href

Do comment if you have any doubts and suggestion on this HTML button tutorial.

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.