Open In App

How to specify the type of button using HTML5 ?

Last Updated : 16 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to set the button type using HTML. The <button> tag in HTML is used to create a clickable button within form on your webpage. The button type attribute specifies the type of button (You Should Always Declare the type of button). 

The <button> tag defines a clickable button and used to submit forms or anywhere in a document for accessible, standard button functionality. 

Syntax:

<button type=" ">

Example 1: This example creates a simple button using type as button.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <h2>Welcome To GFG</h2>
    <button name="button" type="button">
         Click Here
    </button>
</body>
  
</html>


Output:

Example 2: This example creates a submit form on button click.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <h2>Welcome To GFG</h2>
    <form> Enter Name:
        <input type="text" name="name" />
        <br/>
        <button type="submit" onclick=
            "alert('Welcome to GeeksforGeeks')">
           Submit
        </button>
    </form>
</body>
  
</html>


Output:

  • Before clicking the button:
  • After clicking the button:

Example 3: This example creates a reset form button.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <h2>Welcome To GFG</h2>
    <form> Enter Name:
        <input type="text" name="name" />
        <br/>
        <button type="reset">Reset</button>
    </form>
</body>
  
</html>


Output:

  • Before clicking the button:
  • After clicking the button:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads