There are different button types of HTML, which provide users with the flexibility to create interactive buttons with higher levels of customization. Different button type html is used based on the functionality, which also helps create a better and more intuitive user experience on the web page.
All the different button types in HTML are defined using the “type” attribute. In this article, we will know different button html types and their uses.
What is the use of Different Button types in HTML?
Buttons are clickable elements in a web page which is used to execute a predefined function. It can be customized using the CSS properties and Javascript frameworks. Different types of HTML buttons help developers customize buttons as per the use case.
For example, in HTML forms, we use submit button types to submit data or information being provided in the form. We can create buttons with links to get redirected to a specific website, image buttons, file upload buttons, reset buttons, and more. Let us check some major button types HTML used frequently in web development.
Also, check List of HTML Editors you can use for Web Development
6 Major Button Type HTML
Let us check some major button types used in the HTML below.
1. Submit Button
This button type HTML is used to submit a form of data or information which is sent to the server for further processing. The syntax for this type of button tag is given below.
<button type = “submit”>Submit </button> |
When the button is clicked the form action URL is triggered and the data is sent using the GET or POST method.
<form action=”/submit-form” method=”post”>
<input type=”text” name=”username” placeholder = ‘Type your Name’ /> <button type=”submit”>Submit</button> </form> |
2. Reset Button
This type of button tag element is used to clear the input field to the default values. Use this button when you have to clear the field and provide any other information.
<form>
<input type=”text” name=”username” placeholder=’username’/> <input type=”email” name=”email” placeholder = ’email’ /> <button type=”reset”>Reset</button> </form> |
3. Button type
This is used as a default button type in html. Most frequently used with javascript to trigger functions and events. You can add event listeners like “onclick”, “onhover”, etc to define their behvaiour.
<button type=”button” onclick=”alert(‘Button clicked!’)”>Click Me</button> |
4. Image Button
This button is used to submit or redirect a user on the relevant page. It displays an image instead of a standard button.
It is frequently used in place of submit buttons, everything is similar only images are used in place of text. When the image is clicked the form get submitted.
<form action=”/submit-form”>
<input type=”image” src=”submit-icon.png” alt=”Submit”> </form> |
5. Link Button
The link buttons create a clickable button with a link attached to it. When you click on the button you will be redirected to the web page whose link is provided in the button tag.
It is enclosed within the anchor (<a>) and behaves like a button. It is used when a button-like element triggers a link in HTML forms or web pages. It is most frequently used to slide to the next page in web pages.
<a href=”/next-page” class=”btn”>Go to Next Page</a> |
You can style this link button using the CSS style attribute. Check how we are going to make it look like a button.
.btn {
display: inline-block; padding: 10px 20px; background-color: #007BFF; color: white; text-align: center; border-radius: 5px; text-decoration: none; } .btn:hover { background-color: #0056b3; } |
Also, check, Importance of CSS in Web Development
6. File Upload Button
This button is used to help users in uploading any file using the file upload button. It provides a button-like user interface for selecting files from your local storage. It is used when users want to upload files such as images, documents, etc through a form.
<form action=”/upload-file” method=”post” enctype=”multipart/form-data”>
<input type=”file” name=”file” /> <button type=”submit”>Upload File</button> </form> |
Form Buttons in Button Type HTML
Buttons used in forms can use different attributes to enhance their functionalities, such as formaction, formmethod, formtarget, etc. Let us check a simple example below.
<form action=”/default-action” method=”post”>
<button type=”submit” formaction=”/alternate-action”>Submit to Alternate</button> </form> |
When users click on the “submit” button the form action trigger the specific site and sends the data to the server for processing.
Let us take a detailed example to understand the uses of button type html in a form.
<!DOCTYPE html>
<html lang=”en”> <head> <meta charset=”UTF-8″ /> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″ /> <link rel=”stylesheet” href=”style.css” /> <style> .btn { display: inline-block; padding: 10px 20px; background-color: #007BFF; color: white; text-align: center; border-radius: 5px; text-decoration: none; } .btn:hover { background-color: #0056b3; } </style> </head> <body> <form action=”#” method=”get”> <label for=”fname”>Username:</label>
<input type=”text” id=”fname” name=”fname” placeholder=”Enter Your Name” /><br>
<label for=”lname”>Password:</label> <input type=”text” id=”lname” name=”lname” placeholder=”Enter your password” /><br> <br>
<input type=”submit” value=”Submit” class=”btn” /> <input type=”reset” value=”Reset” class = “btn”> </form> <script src=”script.js”></script> </body> </html> |
Learn Full Stack Web Development with PW Skills
Become a certified web developer with our Full Stack Development Course. Learn popular frameworks like Github, React, HTML, CSS, Javascript, MySQL, MongoDb, etc. Master in-depth fundamentals and knowledge of web development and prepare yourself for interviews in big tech firms.
Get to work on capstone projects, practice exercises, doubt clearing sessions, and more. You can also access a free PW lab for coding. The complete syllabus is covered as per the industry curriculum. After you complete the course we will also help you find numerous interview opportunities. Hurry! Enrol now only at pwskills.com
Recommended Course
- Generative AI Course
- Python DSA Course
- DevOps Course
- UI UX Course
- Digital Marketing Course
- Product Management Course
Button Type HTML FAQs
Q1. What are different button type html?
Ans: Buttons can be used in different situations with different functionalities. Some of the common button types are submit, reset, file upload, button, link buttons, etc.
Q2. How to use button input type in html?
Ans: Button input type can simply be used <input type= “button”... when you specify the type button the input tag will behave as a button.
Q3. What is the reset button type in html?
Ans: The reset button type html is used to clear any previous feeds in the input field and convert it into default state.
Q4. How to add a link in the button?
Ans: You can use the anchor tag to attach a link in the button. When you click the button you will be redirected to the desired page given in the link src.