Html Button Link - How do i make html button with link

Published October 12, 2022

The HTML button tag is a clickable element which will do click actions. In this example we will see how to use Button on out web pages and how do we make a html button link to navigate to a new page.

We can use button in our web pages in two ways

  • Button Tag
  • Input Type

Button Tag

The html button can be defined as opening <button> tag and closing </button> tag

<form>
    <input type="text">
    <button type="submit">Submit</button>
</form>

 

Html button link - Create a button which will acts as link in html

Input Type

We can use button by Input type elements and pass the the type as "button".

<form >
     <input type="text"/>
    <input type="button" value="Submit"/>
</form>

 

Then what is the difference between input type and <button> tag.

The only difference is using button tag we can add child elements inside button where as input type button can't accept child elements.

 

How do we make a Button link Html?

To make button link in html we have different ways

  • Using form and input type
  • Using JavaScript function

Using form and input type

To make html button href we will ass button inside form and add link url to the form action

example

<form action="https://rrtutors.com/">
    
    <input type="submit" value="View Page"/>
</form>

 

Here we created button as link by adding the type as submit and attached page url to the form action attribute.

When we tap on button, it will open the page.

 

Using JavaScript function

We can also make button as href link using javascript function.

<input type="button" onclick="location.href='https://rrtutors.com';" value="View Page" />

 

There is an other way to make button as link using bootstrap classes.

To use Bootstrap classes inside out page we need to add bootstrap css. To make a button as link we will use below code

<a class="btn btn-primary" href="">Link</a>

 

So here anchor tag acts as button and will open new pages on tap on it.

Html button link - Create a button which will acts as link in html

 

Example code to make button link in html using bootstrap classes

<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">


</head>
<body style="text-align:center;padding:20px;">
<a class="btn btn-primary" href="https://rrtutors.com">Link</a>
<button class="btn btn-primary" type="submit">Button</button>
<input class="btn btn-primary" type="button" value="Input">
<input class="btn btn-primary" type="submit" value="Submit">

</body>

</html>

 

Here are the some of button attributes which will be useful while using the button inside our web pages.

Attribute Value Description
autofocus autofocus specifies that when reading the page, this button receives an auto focus.
disabled disabled specifies that this button is disabled.
shape form_id specifies one or more buttons for forms.
formation URL specifies the URL to which the form information will be sent.
formmethod get
post
specifies the form submission method.
name name  specifies a name for the button.
type button
reset
submit
 specifies a type for the button.
value text  specifies an initial value for the button.

 

Keywords:

html button href

html button with link

how to link a button in html

html button onclick link

html button link to page

Button html link