Codectionary / Developer documentation / HTML

<button>

The <button> element creates a clickable button that can trigger actions like submitting a form, resetting a form, or running custom JavaScript. Unlike <input type="button">, <button> can contain other HTML content such as icons or styled text, not just plain text. Its type attribute determines its default behavior within a form.

Syntax

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

Examples

Basic Button

A standalone button with a click handler.

<button type="button" onclick="alert('Hello!')">Click Me</button>

Form Submit Button

A button that submits its enclosing form.

<form>
  <input type="text" placeholder="Your name" required>
  <button type="submit">Submit</button>
</form>

Button with Icon Content

Buttons can contain more than just text.

<button type="button" style="display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 8px; background: #3b82f6; color: white; border: none;">
  <span>⬇</span>
  <span>Download</span>
</button>

Attributes

  • type (submit | reset | button): Determines default behavior; submit sends the form, reset clears it, button does nothing by default
  • disabled (boolean): Disables the button, preventing interaction
  • form (string): Associates the button with a form by its id, even if not nested inside it

Best practices

  • Always specify a type attribute — inside a <form>, a button defaults to type="submit", which can cause accidental form submissions
  • Use <button> instead of a styled <div> or <span> for clickable actions, so it is keyboard-accessible and works with assistive technology out of the box
  • Disable buttons during async actions (e.g., form submission) to prevent duplicate clicks
  • Give icon-only buttons an aria-label describing their action for screen reader users

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation