- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <button> Tag
The HTML <button> element is an interactive element that is used to create a button in HTML. It is activated by a user with the mouse, keyboard, finger, voice, command, etc.
Once the button is activated, then it performs different actions submitting form data, deleting data, opening a pop-up dialog box, etc. By default, HTML buttons are rendered in a style that matches the platform the user is running on, but you can change button styles such as color, width, height, etc, using CSS.
Syntax
Following is the syntax for HTML <button> tag −
<button>button name</button>
Specific Attributes
The HTML <button> tag also supports the following additional attributes −
S.No. | Attribute & Description |
---|---|
1 | autofocus Specifies that the button should have input focus when the page loads. |
2 | disabled Specifies the button is disabled. |
3 | form Specifies the forms to which button belongs. |
4 | formaction Specifies the link where the form submits. |
5 | formenctype Specifies how the form data is encoded before sending it to server. |
6 | formmethod Specifies how to send form data. |
7 | formnovalidate Specifies that the form data should not be validated. |
8 | formtarget Specifies where the response should be validated. |
9 | name Specifies the button name. |
10 | type Specifies the button type. |
11 | value Specifies button's initial value. |
Example
In the following program, we are using the HTML <button> tag to create a button with the name "click" in HTML.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Button</title> </head> <body> <!--create a button--> <h1>HTML button</h1> <button>click</button> </body> </html>
When we run the above code, it will generate an output consisting of the text along with a click button on the webpage.
Example
Following is another example of an HTML <button> tag. Here, we are creating an HTML button named "ClickMe!" Using the <button> tag, and, we are using CSS to style the button we have created.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Button</title> <style> button { width: 100px; height: 30px; background-color: green; color: white; cursor: pointer; } </style> </head> <body> <!--create a button--> <h1>HTML button</h1> <button>ClickMe!</button> </body> </html>
On running the above code, the output window will pop up displaying the click button along with a CSS applied to it on the webpage.
Example
In this example, we are creating multiple buttons in HTML using the <button> tag. Then, we are using CSS to give different styles to each created button.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Button</title> <style> button:nth-child(2) { background-color: aqua; width: 100px; height: 30px; border-radius: 10%; } button:nth-child(3) { background-color: green; width: 130px; height: 30px; color: white; } button:nth-child(4) { background-color: blueviolet; width: 90px; height: 30px; color: white; border-radius: 10px; } button:nth-child(5) { background-color: red; width: 80px; height: 30px; cursor: pointer; border-radius: 5px; } button:nth-child(3):hover { background-color: transparent; color: black; cursor: pointer; } </style> </head> <body> <!--create a button--> <h1>HTML buttons</h1> <button>Click</button> <button>Hover me!</button> <button>Submit</button> <button>Danger</button> <button>Default</button> </body> </html>
When we run the above code, it will generate an output consisting of the buttons applied with different CSS properties applied to it on the webpage.
Example
In this program, we are creating an HTML button using the <button> tag. Then, we are using the "disabled" attribute to disable the created button..
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Button</title> </head> <body> <!--create a button--> <h1>HTML button</h1> <button disabled>Submit</button> </body> </html>
On running the above code, the output window will pop up displaying the text along with click button that is disabled on the webpage.
To Continue Learning Please Login
Login with Google