Button

HTML buttons, created using <button> or <input type="button">, serve as interactive controls that initiate actions or submit forms. They can be customized with text, icons, or images, playing a vital role in user interaction.

Simple Button

The <button> element creates a clickable button in HTML. It can contain text or other HTML elements and is commonly used to perform actions like submitting forms or executing scripts.

index.html
<button type="button">Click Here</button>

Submit Form Button

The <button type="submit"> element is used within a form to send input data to the server when clicked.


index.html
<form>  
  <label for="ename">Enter Name:</label>  
  <input id="ename" type="text" name="ename" /><br />  
  <button type="submit">Submit</button>  
</form>

Reset Form Button

The <button type="reset"> element clears all form fields, returning them to their initial values. It allows users to reset input fields easily.


index.html
<form>  
  <label for="ename">Enter Name:</label>  
  <input id="ename" type="text" name="ename" /><br />  
  <button type="reset">Reset</button>  
</form>

Key Attributes

  • autofocus – Automatically focuses on the button when the page loads.
  • disabled – Disables the button, preventing user interaction.
  • form – Links the button to a specific form.
  • formaction – Defines the URL where form data should be sent.
  • formmethod – Specifies the HTTP method for form submission (GET or POST).
  • formenctype – Determines how form data should be encoded.
  • name – Assigns a name to the button for form processing.
  • type – Specifies the button's function (button, submit, or reset).
  • value – Defines a value associated with the button.

Global & Event Attributes

The <button> element supports all global and event attributes in HTML.

Conclusion

The <button> element in HTML is used to create clickable buttons for various functions, such as triggering actions, submitting forms, or resetting input fields. Different button types include type="button", type="submit", and type="reset", each serving a specific purpose.