
HTML Button Type
The HTML type
attribute is used to define the type of a button element. Here are some common values for the type
attribute:
1 Submit Button:
<button type="submit">Submit</button>
The submit
type is used to create a button that submits a form when clicked. This is typically used when you have a form that you want to submit to a server.
2 Reset Button:
<button type="reset">Reset</button>
The reset
type is used to create a button that resets the form fields to their initial values when clicked. It clears any user input and sets the form back to its default state.
3 Button Button:
<button type="button">Click Me</button>
The button
type is used to create a regular button that performs a custom action when clicked. It doesn’t have any predefined behavior like submitting or resetting a form.
4 Image Button:
<input type="image" src="button-image.png" alt="Submit">
The image
type is used to create a button with an image instead of text. It behaves like a submit button and submits the form when clicked. The src
attribute specifies the image URL, and the alt
attribute provides alternative text for accessibility.
These are the most commonly used button types in HTML. By specifying the appropriate type
attribute, you can create buttons with different behaviors and functionalities.