Example
A clickable button is marked up as follows:
Click Me!
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The tag defines a clickable button.
Inside a element you can put text [and tags like
,
,
,
, , etc.]. That is not possible with a button created with the
element!
Tip: Always specify the type
attribute for a element, to tell browsers what type of button it is.
Tip: You can easily style buttons with CSS! Look at the examples below or visit our CSS Buttons tutorial.
Browser Support
Yes | Yes | Yes | Yes | Yes |
Attributes
autofocus | autofocus | Specifies that a button should automatically get focus when the page loads |
disabled | disabled | Specifies that a button should be disabled |
form | form_id | Specifies which form the button belongs to |
formaction | URL | Specifies where to send the form-data when a form is submitted. Only for type="submit" |
formenctype | application/x-www-form-urlencoded multipart/form-data text/plain | Specifies how form-data should be encoded before sending it to a server. Only for type="submit" |
formmethod | get post | Specifies how to send the form-data [which HTTP method to use]. Only for type="submit" |
formnovalidate | formnovalidate | Specifies that the form-data should not be validated on submission. Only for type="submit" |
formtarget | _blank _self _parent _top framename | Specifies where to display the response after submitting the form. Only for type="submit" |
name | name | Specifies a name for the button |
type | button reset submit | Specifies the type of button |
value | text | Specifies an initial value for the button |
Global Attributes
The tag also supports the Global Attributes in HTML.
Event Attributes
The tag also supports the Event Attributes in HTML.
More Examples
Example
Use CSS to style buttons:
.button
{
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button1 {background-color: #4CAF50;} /* Green */
.button2 {background-color: #008CBA;} /* Blue */
Green
Blue
Try it Yourself »
Example
Use CSS to style buttons [with hover effect]:
.button {
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
transition-duration: 0.4s;
cursor: pointer;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #4CAF50;
}
.button1:hover {
background-color: #4CAF50;
color: white;
}
.button2 {
background-color: white;
color: black;
border: 2px solid
#008CBA;
}
.button2:hover {
background-color: #008CBA;
color: white;
}
Green
Blue
Try it Yourself »
Related Pages
HTML DOM reference: Button Object
CSS Tutorial: Styling Buttons
Default CSS Settings
None.
An HTML form is used to collect user input. The user input is most often sent to a server for processing.
The Element
The HTML element is used to create an HTML form for user input:
.
form elements
.
The element is a container for different types of input elements, such as: text fields, checkboxes, radio buttons, submit buttons, etc.
All the different form elements are covered in this chapter: HTML Form Elements.
The Element
The HTML element is the most used form element.
An element can be displayed in many ways, depending on the
type
attribute.
Here are some examples:
Displays a single-line text input field | |
Displays a radio button [for selecting one of many choices] | |
Displays a checkbox [for selecting zero or more of many choices] | |
Displays a submit button [for submitting the form] | |
Displays a clickable button |
All the different input types are covered in this chapter: HTML Input Types.
Text Fields
The defines a single-line input field for text input.
Example
A form with input fields for text:
First name:
Last name:
Try it Yourself »
This is how the HTML code above will be displayed in a browser:
Note: The form itself is not visible. Also note that the default width of an input field is 20 characters.
The Element
Notice
the use of the element in the example above.
The tag defines a label for many form elements.
The element is useful for screen-reader users, because the screen-reader will read out loud the label when the user focus on the input element.
The element also help users who have difficulty clicking on very small regions [such as radio buttons or checkboxes] - because when the user clicks the text within the
element, it toggles the radio
button/checkbox.
The for
attribute of the tag should be equal to the
id
attribute of the element to bind them together.
Radio Buttons
The defines a radio button.
Radio buttons let a user select ONE of a limited number of choices.
Example
A form with radio buttons:
Choose your favorite Web language:
HTML
CSS
JavaScript
Try it Yourself »
This is how the HTML code above will be displayed in a browser:
Choose your favorite Web language:
HTML
CSS
JavaScript
Checkboxes
The defines a checkbox.
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example
A form with checkboxes:
I have a bike
I have a car
I have a boat
Try it Yourself »
This is how the HTML code above will be displayed in a browser:
I have a bike
I have a car
I have a boat
The Submit Button
The defines a button for
submitting the form data to a form-handler.
The form-handler is typically a file on the server with a script for processing input data.
The form-handler is specified in the form's action
attribute.
Example
A form with a submit button:
First name:
Last name:
Try it Yourself »
This is how the HTML code above will be displayed in a browser:
The Name Attribute for
Notice that each input field
must have a name
attribute to be submitted.
If the name
attribute is omitted, the value of the input field will not be sent at all.
Example
This example will not submit the value of the "First name" input field:
First name:
Try it Yourself »
HTML Exercises
Test Yourself With Exercises
Exercise:
In the form below, add an input field with the type "button" and the value "OK".
Start the Exercise