Skip to content

HTML Button href | Adding Href to Button Example code

  • by

Use location href code inside onclick attribute to create an HTML button that acts as a link.

Inline JavaScript:

<button onclick="window.location='';">Visit Page Now</button>

Defining a function in JavaScript:

    function visitPage(){
<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.

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

	<button onclick="location.href=''"></button>



HTML Button href

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

Leave a Reply

Your email address will not be published. Required fields are marked *