bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/HTML/HTML Foundations
HTML•HTML Foundations

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

Formatted code
<button>Click Me</button>

Live preview

Styling HTML Buttons

Example

Formatted code
<button class="mytestbtn">Green Button</button>

Live preview

Disabled Buttons

Use the disabled attribute to make a button unclickable:

Example

Formatted code
<button disabled>Disabled Button</button>

Live preview

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

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

Live preview

Note

You will learn more about JavaScript in our HTML JavaScript chapter.

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
<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 a later chapter.

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

Example

Formatted code
<form action="/action_page.php">

    First name: <input type="text" name="fname">

  <button type="submit">Submit</button>

  <button type="reset">Reset Form</button>

</form>

Live preview

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.

Previous

HTML id Attribute

Next

HTML Iframes

This chapter

Overview
56

Lessons

191m

Read time

1. HTML Tutorial2. HTML Introduction3. HTML Editors4. HTML Elements5. HTML Attributes6. HTML Headings7. HTML Paragraphs8. HTML Styles9. HTML Text Formatting10. HTML Comments11. HTML Colors12. HTML RGB and RGBA Colors13. HTML HEX Colors14. HTML HSL and HSLA Colors15. HTML Styles - CSS16. HTML Links17. HTML Links - Different Colors18. HTML Links - Create Bookmarks19. HTML Images20. HTML Image Maps21. HTML Background Images22. HTML <picture> Element23. HTML Favicon24. HTML Page Title25. HTML Tables26. HTML Table Borders27. HTML Table Sizes28. HTML Table Headers29. HTML Table Padding & Spacing30. HTML Table Colspan & Rowspan31. HTML Table Styling32. HTML Table Colgroup33. HTML Lists34. HTML Unordered Lists35. HTML Ordered Lists36. HTML Other Lists37. HTML Block and Inline Elements38. HTML Div Element39. HTML class Attribute40. HTML id Attribute41. HTML Buttons42. HTML Iframes43. HTML JavaScript44. HTML File Paths45. HTML - The Head Element46. HTML Layout Elements and Techniques47. HTML Responsive Web Design48. HTML Computer Code Elements49. HTML Semantic Elements50. HTML Style Guide51. HTML Entities52. HTML Symbols53. Using Emojis in HTML54. HTML Encoding (Character Sets)55. HTML Uniform Resource Locators56. HTML Versus XHTML

On this page

HTML ButtonStyling HTML ButtonsDisabled ButtonsButton with JavaScriptButton Types