logo Learn HTML
  • Home
  • Tutorials
  • Practice
  • Quiz
  • Projects
  • About
  • Contact

HTML Course

  • HTML HOME
  • HTML Introduction
  • HTML Basic
  • HTML Element
  • HTML Attributes
  • HTML Headings
  • HTML Paragrapha
  • HTML Style
  • HTML Formattin
  • HTML Quotations
  • HTML Colors
  • HTML Css
  • HTML Links
  • HTML Image
  • HTML Favicon
  • Page Tittle
  • HTML Tables
  • HTML Lists
  • Block & Inline
  • HTML Div
  • HTML Classes
  • HTML Id
  • HTML Buttons
  • HTML Iframes
  • HTML File Paths
  • HTML Head
  • HTML Layout
  • HTML Symbols
  • HTML Emojis
  • HTML URL Encode
  • HTML VS XHTML
  • HTML FROM
  • HTML Form
  • Form Attributes
  • Form Elements
  • HTML Input Types
  • HTML Input Attributes
  • Input Form Attributes
  • HTML Graphics
  • HTML Canvas
  • HTML SVG
  • HTML Media
  • HTML Media
  • HTML Video
  • HTML Audio
  • HTML Plug-ins
  • HTML Youtube
  • HTML APIS
  • HTML Web APIS
  • HTML Geolocation
  • HTML Drag & Drop
  • Web Storage
  • Web Workers
  • HTML SSE
  • HTML Examples
  • HTML Examples
  • HTML Editor
  • HTML Quiz
  • HTML Exercises
  • HTML References
  • HTML Tag List
  • HTML Attributes
  • HTML Global Attributes
  • HTML Brower Support
  • HTML Events
  • HTML Colors
  • HTML Canvas
  • HTML Audio & Video
  • HTML Doctypes
  • HTML Character Sets
  • HTML URL Encode
  • Language Codes
  • HTTP Messages
  • HTTP Methods
  • PX to EM Converter
  • keyboard Shortcuts

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 </button>


Styling HTML Buttons

Buttons are often styled with CSS:

Example

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


Disabled Buttons

Use the disabled attribute to make a button unclickable:

Example

<button disabled> Disabled Button </button>


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>


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>

<button type="reset"> reset Button </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

<form action="/action_page.php">

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

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

<button type="resetgt; reset </button>

</form>


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.

Try It Your Self

Sign Up For New
Update

HTML Basic
  1. HTML Basic
  2. HTML Element
  3. HTML Attributes
  4. HTML Headings
  5. HTML Paragrapha
  6. HTML Tables
  7. HTML Lists
HTML Advance
  1. HTML Div
  2. HTML Classes
  3. HTML Id
  4. HTML Buttons
  5. HTML Iframes
  6. HTML Symbols
  7. HTML Emojis