Input elements of type button
are rendered as simple push buttons, which can then be programmed to control functions on a webpage. The element is implemented using the DOM HTMLButtonElement
interface. A button
can be used for many things, such as sending or receiving data. They make the web page much more functional for the user.
formaction
set, but without an associated form does nothing. You have to set a form owner, either by wrapping it in a <form>
or set the attribute form
to the id of the form.
<button>
elements are much easier to style than <input>
elements. You can add inner HTML content (think <i>
, <br>
, or even <img>
), and use ::after
and ::before
pseudo-elements for complex rendering.
If your buttons are not for submitting form data to a server, be sure to set their type
attribute to button
.
Otherwise they will try to submit form data and to load the
(nonexistent) response, possibly destroying the current state of the
document.
While <button type="button">
has no default
behavior, event handlers can be scripted to trigger behaviors. An
activated button can perform programmable actions using JavaScript, such as removing an item from a list.