HTML <button> Tag

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The <button> element is an interactive control users activate with a mouse, keyboard, touch, or assistive technology. It can submit a <form>, reset fields, or run a scripted action.

Set type explicitly: submit, reset, or button. Prefer <button> over <a href="#"> for actions, and over <input type="button"> when you need richer content inside the control.

Baseline · Widely available.

Not deprecated. Core button support has been stable across modern browsers since about July 2015. Some newer attributes (command / popover) have varying support.

Default type can submit.

Inside a form, omitting type means submit. Set type="button" for custom actions that must not send the form.

Newer APIs.

command / commandfor and popovertarget control dialogs and popovers declaratively — useful, but check browser support before relying on them alone.

HTML Syntax

syntax.html
<button type=" button|submit|reset">label</button>

Both start and end tags are required. Put a clear label between them. Do not nest interactive content (links, other buttons, inputs) inside a button.

Attributes

The attributes you will use most often on <button>:

AttributeDescriptionTry it
typesubmit (form default), reset, or button (no default action)Try it
disabledBoolean — cannot press or focus the controlTry it
name / valueSubmitted with form data when this button submits the formTry it
formAssociate the button with a form by that form’s id (even if outside it)Try it
formactionOverride the form’s action URL for this submit buttonTry it
autofocusFocus this button when the page loads (only one per document)Try it

Global Attributes

The <button> tag also supports the Global Attributes in HTML.

Live Preview

Change type and disabled on a real button, then activate it.

A real <button>. Apply settings, then click it (submit is demo-only here).

Button

type="button" — no default form action.

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Custom Action Button

Use type="button" when the control should not submit a form.

HTML
<button type="button" id="save">Save draft</button>

<script>
  document.getElementById("save").addEventListener("click", function () {
    alert("Draft saved (demo).");
  });
</script>
Try It Yourself

How It Works

  1. Set type="button" so nothing submits by default.
  2. Write a clear label that names the action (“Save draft”).
  3. Listen for click (or other events) in JavaScript.
  4. Keep focusable — native buttons work with Enter/Space.

Example 2 — Submit a Form

A submit button sends the form. Name/value can identify which button was used.

HTML
<form action="/search" method="get">
  <label for="q">Search</label>
  <input id="q" name="q" type="search">
  <button type="submit" name="go" value="1">Search</button>
</form>
Try It Yourself

How It Works

  1. Put the button in a <form> (or associate it with form="id").
  2. Use type="submit" (or omit type inside a form).
  3. Optional name / value travel with the submitted data.
  4. Override per button with formaction, formmethod, etc. when needed.

Example 3 — Disabled Button

Disable a control until it is safe or valid to use.

HTML
<button type="button">Send</button>
<button type="button" disabled>Send (disabled)</button>
Try It Yourself

How It Works

  1. Add the disabled attribute (Boolean — no value required).
  2. User cannot activate or focus the disabled control.
  3. It is not successful for form submission.
  4. Toggle in script when your UI rules change (e.g. after validation).

Edge Cases & Pitfalls

Most button bugs are wrong type, fake links, or missing accessible names.

forms

Forgotten type="button"

Inside a form, a bare <button> submits. Set type="button" for non-submit actions.

semantics

Do not fake buttons with <a href="#">

Links navigate. Actions belong on <button> (MDN guidance).

a11y

Icon-only needs a name

Include visible text or an accessible name. Aim for about 44×44 CSS pixels minimum target size.

nesting

No nested interactive content

Do not put links, inputs, or other buttons inside a button.

reset

type="reset" surprises users

Reset clears fields. Use sparingly — people often activate it by mistake.

Browser Support

The <button> element is core HTML in every browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<button>

Widely available since about July 2015. type, disabled, and form association work everywhere. Popover/command features vary by browser.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
<button> Widely supported

Bottom line: Safe for everyday UI. Use type carefully in forms; treat newer command/popover attributes as progressive enhancement.

Key Takeaways

  • Role: <button> is for actions; <a> is for navigation.
  • type: set button, submit, or reset on purpose.
  • Label: visible text (or accessible name) must describe the action.
  • disabled: blocks interaction and focus when the control is not usable.

One line: use <button type="…"> with a clear label for real actions.

Default CSS Settings

Browsers style buttons like platform controls. Modern engines often treat them as a flow-root box that centers content:

default.css
button {
  display: flow-root; /* typical modern UA behavior */
  appearance: auto;   /* platform look */
  /* padding / border / font come from the UA stylesheet */
}

button:disabled {
  opacity: 0.6; /* approximate; exact styles vary */
  cursor: default;
}

You can fully restyle buttons with CSS. Keep focus styles visible for keyboard users.

Frequently Asked Questions

The button element creates an interactive control users activate with a mouse, keyboard, touch, or assistive technology — for example to submit a form, reset fields, or run a scripted action.
Inside a form, the default type is submit. Always set type="button" when the control should not submit the form.
Use a for navigation to a real URL. Use button for actions on the current page. Do not fake buttons with href="#".
disabled prevents pressing and focusing the button. It is not submitted with the form.
Usually yes. button can contain text, icons, and richer HTML, and is easier to style than input.
Yes. Visible text (or an accessible name via aria-label when needed) must describe the action. Icon-only buttons still need a name for screen readers.

Next: canvas

Draw graphics with the HTML canvas element and JavaScript.

canvas tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful