Last Updated : 14 Nov, 2024
Buttons in HTML are interactive elements that users can click to trigger certain actions, such as submitting forms, navigating to different pages, or executing JavaScript functions. We can use either the <button> tag or <input type="button"> tag to create a button.
1. Using <button> ElementThe <button> element is the standard HTML tag specifically designed to create the clickable buttons. It can contain plain text or any other HTML elements such as images or icons.
Syntax
<button> Button Text </button>HTML
<button type="button" onclick="alert('Button clicked!')">
Click Me!
</button>
Output:
using button element 2. Using <input> ElementThe <input> element with type "button" creates a button using the value attribute to set the label text. This approach can be commonly used within the forms.
Syntax
<input type="button" value="Button Text">HTML
<input type="button" value="click me!" onclick="alert('button clicked')">
Output
using input typeRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4