<button> Tag in HTML
The <button> tag is used to create a clickable button in an HTML document. This tag can be used within forms, as well as in standalone places to trigger actions such as submitting forms or triggering JavaScript functions.
Key Points on <button> Tag:
- The
<button>
tag represents a clickable button used to trigger actions in web pages. - It can contain text or HTML elements like images.
- It can be used in both
form
elements and as a standalone button to execute JavaScript code or other actions. - The button can have different types:
submit
,reset
, orbutton
.
Syntax of <button> Tag:
Syntax Example
<button>Button Text</button>
Example of <button> Tag in HTML:
This example demonstrates how to use the <button>
tag to create a button with a click action.
Code Example
<button type="button" onclick="alert('Button clicked!')">Click Me</button>
Output
Button Types:
type="submit"
– Used to submit a form.type="reset"
– Used to reset all form fields to their default values.type="button"
– Used to trigger JavaScript actions when clicked.
The <button>
tag is a powerful and flexible element. It allows you to easily create buttons in forms or in standalone contexts that can trigger specific actions like JavaScript functions, form submissions, or resets.