Skip to main content

HTML Buttons

Buttons let users interact with a page. They can submit forms, run JavaScript, or trigger other actions when clicked.


HTML Button

The <button> element makes a clickable button. On its own it does nothing until you give it an action.

Example

A plain button.

Prompt
A page with a single button element reading "Click Me" that does nothing on its own.
Output: complete HTML page

Styling HTML Buttons

Buttons are often styled with CSS.

Example

A green button styled with CSS.

Prompt
A page with a button styled green using a CSS class (green background, white text, padding, no border), reading "Green Button".
Output: complete HTML page

Disabled Buttons

Use the disabled attribute to make a button unclickable.

Tip: Disabled buttons cannot be clicked and usually look faded.

Example

A disabled button.

Prompt
A page with a button that has the disabled attribute, so it cannot be clicked and appears faded, reading "Disabled Button".
Output: complete HTML page

Button with JavaScript

You can run JavaScript when a button is clicked using the onclick attribute.

Note: You will learn more about JavaScript in the HTML JavaScript chapter.

Example

A button that shows an alert when clicked.

Prompt
A page with a button that shows an alert saying "Hello!" when clicked, using the onclick attribute, reading "Click Me".
Output: complete HTML page

Button Types

The type attribute sets what a button does. There are three types: type="button" is a normal button that does nothing by default, type="submit" submits a form, and type="reset" clears all form fields.

Buttons are often used inside forms: a submit button sends the form data to the server, and a reset button clears the form.

Note: Always set the type attribute. Inside a form the default type is submit, and browsers may behave differently if it is left out.

Example

Submit and reset buttons inside a form.

Prompt
A form (action /action_page.php) with a First name text field, a submit button reading "Submit", and a reset button reading "Reset Form".
Output: complete HTML page

The three button types

A normal, a submit, and a reset button.

index.html
<button type="button">Normal Button</button>
<button type="submit">Submit</button>
<button type="reset">Reset</button>