The <input> is used to create interactive controls for web-based forms in order to accept data from the user.
To get an idea of how different the various <input> types look, try editing the value of the type attributes in the following editable live example; you'll see the output update as you type. In each case, the initial value (text) produces a basic text input, but you can try other values such as number, color, checkbox, radio, date, file, month, password, range, or time.
| Content categories |
Flow content, listed, submittable, resettable, form-associated element, phrasing content. If the type is not hidden, then labelable element, palpable content. |
|---|---|
| Permitted content | None, it is an empty element. |
| Tag omission | Must have a start tag and must not have an end tag. |
| Permitted parents | Any element that accepts phrasing content. |
| Permitted ARIA roles |
|
| DOM interface | HTMLInputElement |
<input> typesHow an <input> works varies considerably depending on the value of its type attribute, hence the different types are covered in their own separate reference pages. If this attributes is not specified, the default type adopted is text.
The available types are as follows:
button: A push button with no default behavior.checkbox: A check box allowing single values to be selected/deselected.color: HTML5 A control for specifying a color. A color picker's UI has no required features other than accepting simple colors as text (more info).date: HTML5 A control for entering a date (year, month, and day, with no time).datetime-local: HTML5 A control for entering a date and time, with no time zone.email: HTML5 A field for editing an e-mail address.file: A control that lets the user select a file. Use the accept attribute to define the types of files that the control can select.hidden: A control that is not displayed but whose value is submitted to the server.image: A graphical submit button. You must use the src attribute to define the source of the image and the alt attribute to define alternative text. You can use the height and width attributes to define the size of the image in pixels.month: HTML5 A control for entering a month and year, with no time zone.number: HTML5 A control for entering a number.password: A single-line text field whose value is obscured. Use the maxlength and minlength attributes to specify the maximum length of the value that can be entered. radio: A radio button, allowing a single value to be selected out of multiple choices.range: HTML5 A control for entering a number whose exact value is not important.reset: A button that resets the contents of the form to default values.search: HTML5 A single-line text field for entering search strings. Line-breaks are automatically removed from the input value.submit: A button that submits the form.tel: HTML5 A control for entering a telephone number.text: A single-line text field. Line-breaks are automatically removed from the input value.time: HTML5 A control for entering a time value with no time zone.url: HTML5 A field for entering a URL.week: HTML5 A control for entering a date consisting of a week-year number and a week number with no time zone.Some input types are now obsolete:
datetime: HTML5 A control for entering a date and time (hour, minute, second, and fraction of a second) based on UTC time zone. This feature has been removed from WHATWG HTML.
<input> attributesThis section lists the attributes available to all form <input> types. Non-global attributes — and global attributes that behave differently when specified on different <input> types — are listed on those types' individual pages.
Note: This includes the global HTML attributes.
typeacceptfile, then this attribute will indicate the types of files that the server accepts, otherwise it will be ignored. The value must be a comma-separated list of unique content type specifiers: accesskey HTML 4 only, Obsolete since HTML5
autocomplete HTML5
off: The user must explicitly enter a value into this field for every use, or the document provides its own auto-completion method. The browser does not automatically complete the entry.on: The browser is allowed to automatically complete the value based on values that the user has entered during previous uses, however on does not provide any further information about what kind of data the user might be expected to enter.name: Full name.honorific-prefix: Prefix or title (e.g. "Mr.", "Ms.", "Dr.", "Mlle").given-name: First name.additional-name: Middle name.family-name: Last name.honorific-suffix: Suffix (e.g. "Jr.", "B.Sc.", "MBASW", "II").nicknameemailusernamenew-password: A new password (e.g. when creating an account or changing a password).current-passwordorganization-title: Job title (e.g. "Software Engineer", "Senior Vice President", "Deputy Managing Director").organizationstreet-addressaddress-line1, address-line2, address-line3, address-level4, address-level3, address-level2, address-level1
countrycountry-namepostal-codecc-name: Full name as given on the payment instrument.cc-given-namecc-additional-namecc-family-namecc-number: Code identifying the payment instrument (e.g. the credit card number).cc-exp: Expiration date of the payment instrument.cc-exp-monthcc-exp-yearcc-csc: Security code for the payment instrument.cc-type: Type of payment instrument (e.g. Visa).transaction-currencytransaction-amountlanguage: Preferred language; a valid BCP 47 language tag.bday: birthdaybday-daybday-monthbday-yearsex: Gender identity (e.g. Female, Fa'afafine), free-form text, no newlines.tel: full telephone number, including country code tel variants: tel-country-code, tel-national, tel-area-code, tel-local, tel-local-prefix, tel-local-suffix, tel-extension
url: Home page or other Web page corresponding to the company, person, address, or contact information in the other fields associated with this field.photo: Photograph, icon, or other image corresponding to the company, person, address, or contact information in the other fields associated with this field.See the WHATWG Standard for more detailed information.
If the autocomplete attribute is not specified on an input element then the browser uses the autocomplete attribute value of the <input> element's form owner. The form owner is either the form element that this <input> element is a descendant of or the form element whose id is specified by the form attribute of the input element. For more information, see the autocomplete attribute in <form>.
The autocomplete attribute also controls whether Firefox will, unlike other browsers, persist the dynamic disabled state and (if applicable) dynamic checkedness of an <input> across page loads. The persistence feature is enabled by default. Setting the value of the autocomplete attribute to off disables this feature. This works even when the autocomplete attribute would normally not apply to the <input> by virtue of its type. See bug 654072.
For most modern browsers (including Firefox 38+, Google Chrome 34+, IE 11+), setting the autocomplete attribute will not prevent a browser's password manager from asking the user if they want to store login (username and password) fields and, if they agree, from autofilling the login the next time the user visits the page. See the autocomplete attribute and login fields.
autofocus HTML5
hidden (that is, you cannot automatically set focus to a hidden control). Note that the focusing of the control may occur before the firing of the DOMContentLoaded event.
captureWhen the value of the type attribute is file, the presence of this Boolean attribute indicates that capture of media directly from the device's environment using a media capture mechanism is preferred.
checkedWhen the value of the type attribute is radio or checkbox, the presence of this Boolean attribute indicates that the control is selected by default, otherwise it is ignored.
Unlike other browsers, Firefox will by default persist the dynamic checked state of an <input> across page loads. Use the autocomplete attribute to control this feature.
disabledThis Boolean attribute indicates that the form control is not available for interaction. In particular, the click event will not be dispatched on disabled controls. Also, a disabled control's value isn't submitted with the form.
Unlike other browsers, Firefox will by default persist the dynamic disabled state of an <input> across page loads. Use the autocomplete attribute to control this feature.
form HTML5
<form> element in the same document. If this attribute is not specified, this <input> element must be a descendant of a <form> element. This attribute enables you to place <input> elements anywhere within a document, not just as descendants of their form elements. An input can only be associated with one form.formaction HTML5
action attribute of the element's form owner.formenctype HTML5
application/x-www-form-urlencoded: The default value if the attribute is not specified.multipart/form-data: Use this value if you are using an <input> element with the type attribute set to file.text/plainIf this attribute is specified, it overrides the enctype attribute of the element's form owner.
formmethod HTML5
post: The data from the form is included in the body of the form and is sent to the server.get: The data from the form are appended to the form attribute URI, with a '?' as a separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.If specified, this attribute overrides the method attribute of the element's form owner.
formnovalidate HTML5
novalidate attribute of the element's form owner.formtarget HTML5
target attribute of the elements's form owner. The following keywords have special meanings: self: Load the response into the same browsing context as the current one. This value is the default if the attribute is not specified._blank: Load the response into a new unnamed browsing context._parent: Load the response into the parent browsing context of the current one. If there is no parent, this option behaves the same way as _self._top: Load the response into the top-level browsing context (i.e. the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self.height HTML5
image, this attribute defines the height of the image displayed for the button.inputmode HTML5Obsolete since HTML5.2
verbatim: Alphanumeric, non-prose content such as usernames and passwords.latin: Latin-script input in the user's preferred language with typing aids such as text prediction enabled. For human-to-computer communication such as search boxes.latin-name: As latin, but for human names.latin-prose: As latin, but with more aggressive typing aids. For human-to-human communication such as instant messaging or email.full-width-latin: As latin-prose, but for the user's secondary languages.kana: Kana or romaji input, typically hiragana input, using full-width characters, with support for converting to kanji. Intended for Japanese text input.katakana: Katakana input, using full-width characters, with support for converting to kanji. Intended for Japanese text input.numeric: Numeric input, including keys for the digits 0 to 9, the user's preferred thousands separator character, and the character for indicating negative numbers. Intended for numeric codes (e.g. credit card numbers). For actual numbers, prefer using <input type="number">tel: Telephone input, including asterisk and pound key. Use <input type="tel"> if possible instead.email: Email input. Use <input type="email"> if possible instead.url: URL input. Use <input type="url"> if possible instead.list HTML5
<datalist> element in the same document. The browser displays only options that are valid values for this input element. This attribute is ignored when the type attribute's value is hidden, checkbox, radio, file, or a button type.max HTML5
maxlengthtext, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in UTF-16 code units) that the user can enter. For other control types, it is ignored. It can exceed the value of the size attribute. If it is not specified, the user can enter an unlimited number of characters. Specifying a negative number results in the default behavior (i.e. the user can enter an unlimited number of characters). The constraint is evaluated only when the value of the attribute has been changed.min HTML5
minlength HTML5
text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in Unicode code points) that the user can enter. For other control types, it is ignored.multiple HTML5
email or file, otherwise it is ignored.namepattern HTML5
text, search, tel, url, email, or password, otherwise it is ignored. The regular expression language is the same as JavaScript RegExp algorithm, with the 'u' parameter that makes it treat the pattern as a sequence of unicode code points. The pattern is not surrounded by forward slashes.placeholder HTML5
placeholder attribute instead of a <label> element, their purposes are different. The <label> attribute describes the role of the form element (i.e. it indicates what kind of information is expected), and the placeholder attribute is a hint about the format that the content should take. There are cases in which the placeholder attribute is never displayed to the user, so the form must be understandable without it.readonly HTML5
hidden, range, color, checkbox, radio, file, or a button type (such as button or submit).required HTML5
hidden, image, or a button type (submit, reset, or button). The :optional and :required CSS pseudo-classes will be applied to the field as appropriate.selectionDirection HTML5
"forward" if the selection was made from left-to-right in an LTR locale or right-to-left in an RTL locale, or "backward" if the selection was made in the opposite direction. On platforms on which it's possible this value isn't known, the value can be "none"; for example, on macOS, the default direction is "none", then as the user begins to modify the selection using the keyboard, this will change to reflect the direction in which the selection is expanding.selectionEndselectionStartsizetext or password, in which case it is an integer number of characters. Starting in HTML5, this attribute applies only when the type attribute is set to text, search, tel, url, email, or password, otherwise it is ignored. In addition, the size must be greater than zero. If you do not specify a size, a default value of 20 is used. HTML5 simply states "the user agent should ensure that at least that many characters are visible", but different characters can have different widths in certain fonts. In some browsers, a certain string with x characters will not be entirely visible even if size is defined to at least x.spellcheck HTML5
true indicates that the element needs to have its spelling and grammar checked. The value default indicates that the element is to act according to a default behavior, possibly based on the parent element's own spellcheck value. The value false indicates that the element should not be checked.srcimage, this attribute specifies a URI for the location of an image to display on the graphical submit button, otherwise it is ignored.step HTML5
any or a positive floating point number. If this attribute is not set to any, the control accepts only values at multiples of the step value greater than the minimum.tabindex element-specific in HTML 4, global in HTML5
usemap HTML 4 only, Obsolete since HTML5
<map> element to be used as an image map.valueradio or checkbox.width HTML5
image, this attribute defines the width of the image displayed for the button.<input> attributesautocapitalize
none: Completely disables automatic capitalisation.sentences: Automatically capitalise the first letter of sentences.words: Automatically capitalise the first letter of words.characters: Automatically capitalise all characters.on: Deprecated since iOS 5.off: Deprecated since iOS 5.autocapitalize documentation in the Safari HTML Reference.autocorrect
<input>. Possible attribute values are: on: Enable autocorrection.off: Disable autocorrection.autocorrect documentation in the Safari HTML Reference.incremental
search. If the attribute is present, regardless of what its value is, the <input> fires search events as the user edits the text value. The event is only fired after an implementation-defined timeout has elapsed since the most recent keystroke, and new keystrokes reset the timeout. In other words, the event firing is debounced. If the attribute is absent, the search event is only fired when the user explicitly initiates a search (e.g. by pressing the Enter key while within field). incremental documentation in the Safari HTML Reference
mozactionhint
go, done, next, search, and send. These automatically get mapped to the appropriate string and are case-insensitive.results
search. It is used to control the maximum number of entries that should be displayed in the <input>'s native dropdown list of past search queries. Its value should be a nonnegative decimal integer.webkitdirectory
file has to allow for the selection of directories only.x-moz-errormessage
You can style <input> elements using various color-related attributes in particular. One unusual one that is specific to text entry-related elements is the CSS caret-color property, which lets you set the color used to draw the text input caret:
<label for="textInput">Note the red caret:</label> <input id="textInput" class="custom" size="32"/>
input.custom {
caret-color: red;
font: 16px "Helvetica", "Arial", "sans-serif"
}
For more information about adding color to elements in HTML, see Applying color to HTML elements using CSS.
You can find multiple examples of <input> element usage on the pages covering each individual type — see Form <input> types, and also see the Live example at the top of the article.
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of '<input>' in that specification. | Living Standard | |
| HTML Media Capture The definition of '<input capture>' in that specification. | Proposed Recommendation | Adds the capture element |
| HTML5 The definition of '<input>' in that specification. | Recommendation | |
| HTML 4.01 Specification The definition of '<form>' in that specification. | Recommendation |
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 1.0 | (Yes) | 1.0 (1.7 or earlier) | (Yes) | 1.0 | 1.0 |
type="color" | 20 | 14 | 29 (29) | No support | 11.01 | 11 |
type="email", type="number", type="range", type="search", type="tel", type="url"
| (Yes) | (Yes) | (Yes) | 10 | (Yes) | (Yes) |
type="datetime-local", type="month", type="week"
| 20 | 16 | No support | No support | 10.62 | (Yes)[1] |
type="date", type="time"
| 20 | (Yes) | 57 (57) | No support | 10.62 | (Yes)[1] |
type="datetime" | No support[4] | No support | No support[4] | No support[4] | No support[4] | No support[4] |
accept | (Yes) | No support | (Yes) | 10 | ? | No support |
mozactionhint | No support | No support | 4.0 (2.0) | No support | No support | No support |
autocapitalize | 43 | No support | ? | ? | ? | (Yes) [3] |
autofocus, max, min, pattern, placeholder, required, step, list, multiple
| 5.0 | (Yes) | (Yes) | 10 | 9.6 | 5.0 |
| capture | Chrome for Android (0.16) | No support | ? | ? | ? | ? |
| fakepath added to file input values | (Yes) | No support | 53 (53) | (Yes) | (Yes) | (Yes) |
form | 10 | (Yes) | 4 | No support[7] | 9.5 | 5.0 |
formaction, formenctype, formmethod, formnovalidate, formtarget
| 9.0 | (Yes) | 4.0 (2.0) | 10 | 10.62 | 5.1 |
incremental | (Yes) | No support | No support | No support | No support | (Yes) |
inputmode | No support | No support | No support | No support | No support | No support |
minlength | 40.0 | No support | ? | ? | ? | ? |
readonly | 1.0 | (Yes) | 1.0 (1.7 or earlier) | 6[2] | 1.0 | 1.0 |
spellcheck | 10.0 | No support | 3.6 (1.9.2) | 10 | 11.0 | 4.0 |
webkitdirectory | (Yes) | (Yes) | 49.0 (49.0) | ? | (Yes) | (Yes) |
| Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | 4.0 (2.0) | (Yes) | (Yes) | (Yes) |
type="color" | ? | (Yes) | 27.0 (27.0) | ? | (Yes) | ? |
type="email", type="number", type="range", type="search", type="tel", type="url"
| (Yes) | (Yes) | (Yes) | ? | (Yes) | (Yes) |
type="datetime-local", type="month", type="week"
| (Yes) | (Yes) | No support | ? | (Yes) | (Yes) |
type="date", type="time"
| No support | (Yes) | 57 (57) | No support | 10.62 | (Yes)[1] |
type="datetime" | No support[4] | No support | No support[4] | No support[4] | No support[4] | No support[4] |
accept | (Yes) | No support | (Yes) | ? | (Yes) | (Yes) |
autocapitalize | ? | No support | ? | ? | ? | (Yes)[3] |
autofocus, max, min, pattern, placeholder, required, step, list, multiple
| (Yes) | (Yes) | (Yes)[5] | ? | (Yes) | (Yes) |
capture | 3.0 | No support | 10.0 (10.0) | ? | ? | 6.0 |
| fakepath added to file input values | (Yes) | No support | 53.0 (53) | (Yes) | (Yes) | (Yes) |
form, formaction, formenctype, formmethod, formnovalidate, formtarget
| ? | (Yes) | ? | ? | ? | ? |
minlength | ? | No support | No support | ? | 27.0 | ? |
spellcheck | ? | No support | 4.0 (2.0) | ? | 11.0 | ? |
webkitdirectory | (Yes) | (Yes) | 49.0 (49.0) | ? | (Yes) | (Yes) |
[1] It is recognized but there is no UI.
[2] Missing for type="checkbox" and type="radio".
[3] In Safari autocapitalize="words" capitalizes every word's second character.
[4] datetime has been removed from the spec and browsers in favour of datetime-local.
[5] see bug 1355389
[6] Not yet implemented. For progress, see bug 888320 and TPE DOM/Date time input types.
Starting in Gecko 2.0, calling the click() method on an <input> element of type file opens the file picker and lets the user select files. See Using files from web applications for an example and more details.
You cannot set the value of a file picker from a script — doing something like the following has no effect:
var e = getElementById("someFileInputElement");
e.value = "foo";
When a file is chosen using an <input type="file">, the real path to the source file is not shown in the input's value attribute for obvious security reasons. Instead, the filename is shown, with C:\fakepath\ appended to the beginning of it. There are some historical reasons for this quirk, but it is supported across all modern browsers, and in fact is defined in the spec.
If you want Firefox to present a custom error message when a field fails to validate, you can use the x-moz-errormessage attribute to do so:
<input type="email" x-moz-errormessage="Please specify a valid email address.">
Note, however, that this is not standard and will not have an effect on other browsers.
The allowed inputs for certain <input> types depend on the locale. In some locales, 1,000.00 is a valid number, while in other locales the valid way to enter this number is 1.000,00.
Firefox uses the following heuristics to determine the locale to validate the user's input (at least for type="number"):
lang/xml:lang attribute on the element or any of its parents.You can use the mozactionhint attribute to specify the text for the label of the enter key on the virtual keyboard when your form is rendered on Firefox mobile. For example, to have a "Next" label, you can do this:
<input type="text" mozactionhint="next">
The result is:
Note the "Next" key in the lower-right corner of the keyboard.
<form>, <button>, <datalist>, <legend>, <label>, <select>, <optgroup>, <option>, <textarea>, <keygen>, <fieldset>, <output>, <progress> and <meter>.caret-color property
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input