HTML: button

The <button> element creates a control that performs an action when the user activates it.

What you will learn

Button types

<button type="button">Open details</button>
<button type="submit">Send form</button>
<button type="reset">Clear form</button>

Inside a form, explicitly set type="button" for a button that should not submit. Otherwise the default type can behave like a submit button.

Submit a form

<form action="/search" method="get">
  <label for="query">Search</label>
  <input id="query" name="q">
  <button type="submit">Search</button>
</form>

Button or link?

Use a button for an action on the current page, such as opening a dialog or changing a setting. Use <a href> when the user should navigate to another URL.

Common mistakes