Bhylu

HTML Buttons

A button performs an action. Native buttons provide keyboard operation and accessibility semantics that you would otherwise have to rebuild on a generic element.

How it works

  • Use type="button" for a scripted action and type="submit" when the control should submit its form. Specify the type deliberately.
  • A visible text label should explain the action. An icon-only button needs a reliable accessible name such as an aria-label.
  • The disabled attribute makes a button unavailable. Explain why a necessary action is unavailable instead of relying only on faded styling.

A practical example

HTML

<form action="/subscribe" method="post">
  <label for="subscriber">Email</label>
  <input id="subscriber" name="email" type="email" required>
  <button type="submit">Subscribe to updates</button>
  <button type="button">Preview preferences</button>
</form>

The first button is intended to submit to an application endpoint. The second is a non-submit control and needs your application’s own handler before it performs an action.