HTML <button> Element
The <button> tag in HTML is used to create clickable buttons on a webpage. Buttons are used to submit forms, trigger JavaScript functions, and perform various other interactive actions.
Usage
To create a button, simply use the <button> tag with the text or content you want to display on the button inside the opening and closing tags. For example:
<button>Click Me</button>
This will create a button with the text "Click Me".
Main Attributes
Below is a table of the main attributes of the <button> tag and their uses:
| Attribute | Description |
|---|---|
| type | Specifies the type of the button (e.g. "submit", "reset", "button"). |
| name | Specifies the name of the button (used when submitting a form). |
| value | Specifies the initial value of the button. |
| disabled | Specifies whether the button should be disabled or not. |
| onclick | Specifies a JavaScript function to be executed when the button is clicked. |
Examples
Here are some examples of using the <button> tag with different attributes:
<button type="submit" name="submitBtn" value="Submit">Submit</button>
<button type="button" onclick="alert('Hello!')">Click Me</button>
<button disabled>Disabled Button</button>