Using the <button> Element
Notes
A submit button with the attributeformaction
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.