Use location href code inside onclick attribute to create an HTML button that acts as a link.
Inline JavaScript:
<button onclick="window.location='http://www.example.com';">Visit Page Now</button>
Defining a function in JavaScript:
<script>
function visitPage(){
window.location='http://www.example.com';
}
</script>
<button onclick="visitPage();">Visit Page Now</button>
HTML Button href Example
HTML example code
Set the window.location.href JavaScript code. Using a input and button HTML tag.
<html>
<body>
<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />
<button onclick="location.href='http://www.example.com'">
www.example.com</button>
</body>
</html>
Output:
Do comment if you have any doubts and suggestions on this HTML button code.
Note: The All HTML Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version