HTML: button
The <button> element creates a control that performs an action when the user activates it.
What you will learn
- How to choose a button type
- How submit buttons work in forms
- When to use a link instead of a button
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
- Always choose a type when the button is inside a form.
- Give icon-only buttons an accessible name with visible text or a suitable
aria-label. - Do not use a button as a link when normal browser navigation is the goal.