This chapter describes the input types of the <input> element.
<input type="text"> defines a one-line input field for text input:
This is how the HTML code above will be displayed in a browser:
First name:<input type="password"> defines a password field:
This is how the HTML code above will be displayed in a browser:
First name:
The characters in a password field are masked (shown as asterisks or circles). |
<input type="submit"> defines a button for submitting form input to a form-handler.
The form-handler is typically a server page with a script for processing input data.
The form-handler is specified in the form's action attribute:
This is how the HTML code above will be displayed in a browser:
If you omit the submit button's value attribute, the button will get a
default text:
<input type="radio"> defines a radio button.
Radio buttons let a user select ONLY ONE of a limited number of choices:
This is how the HTML code above will be displayed in a browser:
Male<input type="checkbox"> defines a checkbox.
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
This is how the HTML code above will be displayed in a browser:
I have a bike<input type="button> defines a button:
This is how the HTML code above will be displayed in a browser:
HTML5 added several new input types:
Input types, not supported by old web browsers, will behave as input type text. |
The <input type="number"> is used for input fields that should contain a numeric value.
You can set restrictions on the numbers.
Depending on browser support, the restrictions can apply to the input field.
Here is a list of some common input restrictions (some are new in HTML5):
Attribute | Description |
---|---|
disabled | Specifies that an input field should be disabled |
max | Specifies the maximum value for an input field |
maxlength | Specifies the maximum number of character for an input field |
min | Specifies the minimum value for an input field |
pattern | Specifies a regular expression to check the input value against |
readonly | Specifies that an input field is read only (cannot be changed) |
required | Specifies that an input field is required (must be filled out) |
size | Specifies the width (in characters) of an input field |
step | Specifies the legal number intervals for an input field |
value | Specifies the default value for an input field |
You will learn more about input restrictions in the next chapter.
The <input type="date"> is used for input fields that should contain a date.
Depending on browser support, a date picker can show up in the input field.
You can add restrictions to the input:
The <input type="color"> is used for input fields that should contain a color.
Depending on browser support, a color picker can show up in the input field.
The <input type="range"> is used for input fields that should contain a value within a range.
Depending on browser support, the input field can be displayed as a slider control.
You can use the following attributes to specify restrictions: min, max, step, value.
The <input type="month"> allows the user to select a month and year.
Depending on browser support, a date picker can show up in the input field.
The <input type="week"> allows the user to select a week and year.
Depending on browser support, a date picker can show up in the input field.
The <input type="time"> allows the user to select a time (no time zone).
Depending on browser support, a time picker can show up in the input field.
The <input type="datetime"> allows the user to select a date and time (with time zone).
Depending on browser support, a date picker can show up in the input field.
The <input type="datetime-local"> allows the user to select a date and time (no time zone).
Depending on browser support, a date picker can show up in the input field.
The <input type="email"> is used for input fields that should contain an e-mail address.
Depending on browser support, the e-mail address can be automatically validated when submitted.
Some smartphones recognize the email type, and adds ".com" to the keyboard to match email input.
The <input type="search"> is used for search fields (a search field behaves like a regular text field).
The <input type="tel"> is used for input fields that should contain a telephone number.
The tel type is currently supported only in Safari 8.
The <input type="url"> is used for input fields that should contain a URL address.
Depending on browser support, the url field can be automatically validated when submitted
Some smartphones recognize the url type, and adds ".com" to the keyboard to match url input.