Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

<button>

A button: submits a form or triggers an action.

Syntax

<button type="button">Text</button>

Attributes

ParameterTypeDescription
typesubmit | button | resetWhat the button does. Inside a form the default is `submit`.
disabled—Optional. The button is disabled.
popovertargetidOptional. Open or close the popover with this `id`.

Examples

Form buttons:

<form>
  <input name="q" placeholder="Search">
  <button type="submit">Find</button>
  <button type="reset">Clear</button>
</form>

A button that triggers an action:

<button type="button" onclick="this.textContent = 'Thanks!'">Click me</button>
<button disabled>Not available</button>

Notes

Inside a form a button without type submits the form — a common cause of unexpected reloads. For buttons that do not submit, write type="button". Unlike <input type="submit">, a <button> can contain an icon or other markup.

See also

  • <form> — A form: collects data from its fields and sends it to the server.
  • <input> — An input field; its kind is set by the `type` attribute.
  • <a> — A link to another page, a file or a place on the page.
  • disabled — Disables a form control: it cannot be used, and its value is not submitted.

Related recipes

In the tutorial

  • Buttons — The button tag and its submit, reset and button types, a button with an icon, a disabled button and the difference between a button and a link.

Thanks for reading!

Donate to the site — we work hard for you.