Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Web Development - HTML Buttons


HTML Buttons

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


HTML Button

The HTML <button> element defines a clickable button.

By itself, the button does nothing until you add an action to it.

Example

<button>Click Me</button>
Try it Yourself »

Styling HTML Buttons

Buttons are often styled with CSS:

Example

<button class="mytestbtn">Green Button</button>
Try it Yourself »

Disabled Buttons

Use the disabled attribute to make a button unclickable:

Example

<button disabled>Disabled Button</button>
Try it Yourself »

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


Button with JavaScript

You can run JavaScript when the user clicks a button using the onclick attribute:

Example

<button onclick="alert('Hello!')">Click Me</button>
Try it Yourself »

Button Types

The type attribute defines what a button does when clicked. There are three button types:

  • type="button" - A normal clickable button (does nothing by default)
  • type="submit" - Submits a form
  • type="reset" - Resets all form fields

Example

Three different button types:

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

Buttons are often used inside forms, which you will learn more about in the next chapter.

For now, just know that a submit button sends the form data to the server, while a reset button clears the form:

Example

<form action="/action_page.php">
  First name: <input type="text" name="fname">
  <button type="submit">Submit</button>
  <button type="reset">Reset Form</button>
</form>
Try it Yourself »

Note: You should always specify the type attribute. Inside a form, the default type is submit, and browsers may behave differently if the type is omitted.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.