forms

<button>

Interactive control that triggers an action — submitting a form, opening a dialog, or running JavaScript. Use it for anything that does something; use <a href> for anything that navigates.

<button type="submit">Save</button>

Common attributes

Attribute Purpose
type submit (default in form) | button | reset
name Submitted with the form
value Value sent when this button submits
disabled Blocks clicks and skips submission
form id of a form this button belongs to (when outside it)
formaction Overrides the form's action for this button
autofocus Focus on page load

Examples

<button type="submit">Sign up</button>

Submit button inside a form

<button type="button" onclick="open()">Open menu</button>

Non-submitting button that runs JS

<button type="button" disabled>Loading…</button>

Temporarily disabled control

<button type="submit" formaction="/draft">Save draft</button>

Overrides the form action just for this button

Gotcha

Inside a

, buttons default to type="submit" — set type="button" for JS-only actions or you'll accidentally submit. Never wrap a

Related tags

← All HTML tags · CSS selectors · HTML entities