<button> Tag in HTML

Quick facts

CategoryFlow content, phrasing content, interactive content, palpable content
Content modelPhrasing content, but no interactive descendants (no nested links or other buttons)
Tag omissionNeither the start nor end tag can be omitted
Permitted parentsAny element that accepts phrasing content
DOM interfaceHTMLButtonElement

Syntax

<button type="button">Click me</button>

Live example

Edit the code below and watch the preview update instantly.

index.html
Preview

Attributes

AttributeDescription
typesubmit (default in a form), reset, or button
disabledGreys out the button and blocks clicks
name / valueIncluded in the form submission when this button triggers it
formAssociates the button with a <form> elsewhere in the document by its id

Common examples

A submit button in a form

Inside a form, type="submit" sends the form when clicked or when Enter is pressed in a field.

<form action="/search"> <input type="search" name="q" aria-label="Search"> <button type="submit">Search</button> </form>

A button that runs JavaScript

Use type="button" so it never submits a form by accident.

<button type="button" id="theme">Toggle dark mode</button> <script> document.getElementById("theme").addEventListener("click", () => { document.body.classList.toggle("dark"); }); </script>

An icon button with an accessible name

If a button shows only an icon, give it a text name with aria-label.

<button type="button" aria-label="Close">✕</button>

<button> vs <input type=”submit”>

Both create a button that can submit a form, but <button> is more flexible. Its label is the content between the tags, so it can include icons, images, bold text or other HTML. An <input type="submit"> is a void element whose label is just plain text in its value attribute.

For new pages, <button> is the better default: it is easier to style, can hold an icon, and works outside forms with type="button". The input version still works perfectly well and you will see it in older code and simple forms.

<button><input type=”submit”>
LabelAny HTML between tagsPlain text in value
Icons insideYesNo
Recommended for new codeYesFine, but less flexible

Common mistakes to avoid

  • Forgetting the type inside a form. A button in a form defaults to type="submit", so a “Cancel” or menu button reloads the page unless you add type="button".
  • Using a div or span as a button. It won’t work with the keyboard and screen readers won’t announce it as a button.
  • Icon-only buttons with no name. A screen reader would just say “button”. Add aria-label or visually hidden text.
  • Removing the focus outline. outline: none leaves keyboard users lost. Restyle the focus state instead of deleting it.

Accessibility & SEO tips

  • Use a link when the click goes to another page, and a button when it does something on the current page.
  • Make buttons at least about 44×44 pixels on touch screens and keep good color contrast for the text.
  • Button text should say what happens: “Download PDF” is clearer than “Submit” or “OK”.
  • Avoid using only color to show a button’s state, such as red for “danger”; add a clear word or icon too, so color-blind visitors understand it.

Browser support

Supported in every browser, including Chrome, Edge, Firefox, Safari and their mobile versions — it has been part of HTML since the very first versions.

Related tags

Frequently asked questions

Why did my button submit the form when I didn't want it to?
Inside a <form>, a <button> defaults to type="submit". Set type="button" explicitly if you just want a JavaScript-driven action instead.
Should I use <button> or <a> for a call-to-action?
Use <button> for an action — submit, toggle, open a modal. Use <a> when it navigates to a real URL.
How do I make a button that goes to another page?
Use an <a href="…"> link styled to look like a button. Links are the right element for navigation, and they work with middle-click and "open in new tab".
How do I disable a button?
Add the disabled attribute: <button disabled>Send</button>. It can't be clicked or focused. Remove the attribute with JavaScript (button.disabled = false) to enable it again.
How do I remove the default button styling?
Reset it with CSS, for example button { all: unset; cursor: pointer; }, then add your own styles. Remember to add back a visible :focus-visible style for keyboard users.
How do I put an icon next to the text in a button?
Place the icon inside the button along with the text, for example <button><span aria-hidden="true">⬇</span> Download</button>. Hide the icon from screen readers with aria-hidden="true", since the text already describes the action.