<input>: The Input (Form Input) element

The HTML <input> element is used to create interactive controls for web-based forms in order to accept data from the user; a wide variety of types of input data and control widgets are available, depending on the device and user agent.

Form <input> types

How 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 attribute is not specified, the default type adopted is text.

The available types are as follows:

type description Basic Examples Spec
button A push button with no default behavior displaying the value of the value attribute, empty by default.
checkbox A check box allowing single values to be selected/deselected.
color A control for specifying a color; opening a color picker when active in supporting browsers. HTML5
date A control for entering a date (year, month, and day, with no time) opening a date picker or numeric  wheels for month, hour, etc.,  when active in supporting browsers..   HTML5
datetime-local A control for entering a date and time, with no time zone; opening a date picker or numeric wheels for month, day, and year,  when active in supporting browsers. HTML5
email A field for editing an e-mail address. Looks like a text input, but has validation parameters and relevant keyboard in supporting browsers and devices with dynamic keyboards. HTML5
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. There is an example in the next column, but it's hidden!
image A graphical submit button -- displaying an image defined with the src attribute. The alt attribute displays if the image src is missing.
month A control for entering a month and year, with no time zone. HTML5
number A control for entering a number; displays a spinner and adds default validation when supported. Displays a numeric keypad in some devices with dynamic keypads. HTML5
password A single-line text field whose value is obscured. Will alert user if site is not secure
radio A radio button, allowing a single value to be selected out of multiple choices with the same name value.
range A control for entering a number whose exact value is not important; displays as a range widget defaulting to the middle value. Used in conjunction min  and max to define the range of acceptable values.   HTML5
reset A button that resets the contents of the form to default values. Not recommended.
search A single-line text field for entering search strings. Line-breaks are automatically removed from the input value. May include a delete icon in supporting browsers that can be used to clear the field. Displays a search icon instead of enter key on some devices with dynamic keypads. HTML5
submit A button that submits the form.
tel A control for entering a telephone number. Displays a telephone keypad in some devices with dynamic keypads. HTML5
text The default value. A single-line text field. Line-breaks are automatically removed from the input value.
time A control for entering a time value with no time zone. HTML5
url A field for entering a URL. Looks like a text input, but has validation parameters and relevant keyboard in supporting browsers and devices with dynamic keyboards. HTML5
week A control for entering a date consisting of a week-year number and a week number with no time zone. HTML5
Obsolete values
datetime A control for entering a date and time (hour, minute, second, and fraction of a second) based on UTC time zone. HTML5

Attributes

The <input> element is one of the most powerful and complex in all of HTML due to the sheer number of combinations of input types and attributes. Since every <input> element, regardless of type, is based on the HTMLInputElement interface, they technically all share the exact same set of attributes. However, in reality, many attributes only function on specific input types, and some input types support very few of these attributes. In addition, some input types handle certain attributes in special ways.

Here, you'll find information about the individual attributes which are common to all <input> element types, as well as a few non-standard attributes that may be worth knowing about.

Attributes common to one or more input types

This section lists the attributes which are used by form <input> types. Those that are common to most or all input types are defined in greater detail below. Attributes that are unique to particular input types—or attributes which are common to all input types but have special behaviors when used on a given input type—are instead documented on those types' pages.

Note: This includes the global HTML attributes.

Attributes for the <input> element include global HTML attributes and:
Attribute types Description
accept file Hint for expected file type in file upload controls
alt image alt attribute for the image type. Required for accessibiltiy
autocomplete all Hint for form autofill feature
autofocus all Automatically focus the form control when the page is loaded
capture file Media capture input method in file upload controls
checked radio, checkbox Whether the command or control is checked
dirname text, search Name of form field to use for sending the element's directionality in form submission
disabled all Whether the form control is disabled
form all Associates the control with a form element
formaction image, submit URL to use for form submission
formenctype image, submit Form data set encoding type to use for form submission
formmethod image, submit HTTP method to use for form submission
formnovalidate image, submit Bypass form control validation for form submission
formtarget image, submit Browsing context for form submission
height image Same as height attribute for <img>; vertical dimension
inputmode Hint for selecting an input modality, such as the number keypad on dynamic keyboards.
list almost all Value of the id attribute of the <datalist> of autocomplete options
max numeric types Maximum value
maxlength password, search, tel, text, url Maximum length (number of characters) of value
min numeric types Minimum value
minlength password, search, tel, text, url Minimum length (number of characters) of value
multiple email, file Boolean. Whether to allow multiple values
name all Name of the input form control. Submitted with the form as part of a name/value pair.
pattern password, text, tel Pattern the value must match to be valid
placeholder password, search, tel, text, url content to be appear in the form control when the form control is empty
readonly almost all Boolean. The value is not editable
required almost all Boolean. A value is required or must be check for the form to be submittable
size Size of the control
src image Same as src attribute for <img>; address of image resource
step numeric types Incremental values that are valid.
type all Type of input form control
value all Current value of the form control. Submitted with the form as part of a name/value pair.
width image Same as width attribute for <img>

accept

Valid for the file input type only, the accept property defines which file types are selectable in a file upload control. See the file input type.

alt

Valid for the image button only, the alt attribute provides alternative text for the image, displaying the value of the attribute if the image src is missing or otherwise fails to load. See the image input type.

autocomplete

Not a Boolean attribute, the autocomplete attribute takes as it's value a space separated string that describes what, if any, type of autocomplete functionality the input should provide. A typical implementation of autocomplete simply recalls previous values entered in the same input field, but more complex forms of autocomplete can exist. For instance, a browser could integrate with a device's contacts list to autocomplete email addresses in an email input field. See Values in The HTML autocomplete attribute for permitted values.

The autocomplete attribute is valid on hidden, text, search, url, tel, email, date, month, week, time, datetime-local, number, range, color and password. This attribute has no effect on input types that do not return numeric or text data, being valid for all input types except checkbox, radio, file, or any of the button types. See The HTML autocomplete attribute for additional information, including information on password security and how autocomplete is slightly different for hidden than for other input types.

autofocus

A Boolean attribute which, if present, indicates that the input should automatically have focus when the page has finished loading (or when the <dialog> containing the element has been displayed).

Note: An element with the autofocus attribute may gain focus before the DOMContentLoaded event is fired.

No more than one element in the document may have the autofocus attribute, and autofocus cannot be used on inputs of type hidden, because hidden inputs can't be focused. If put on more than one element, the first one with the attribute receives focus .

Warning: Automatically focusing a form control can confuse visually-impaired people using screen-reading technology and people with cognitive impairments. When autofocus is assigned, screen-readers "teleport" their user to the form control without warning them beforehand.

For better usability, avoid using autofocus. Automatically focusing on a form control can cause the page to scroll on load. The focus can also cause dynamic keyboards to display on some touch devices. While a screen reader will announce the label of the form control receiving focus, the screen reader  will not announce anything before the label, and the sighted user on a small device will equally miss the context created by the preceding content. 

capture

Valid for the file input type only, the capture attribute defines which media - microphone, video, or camera - should be used to capture a new file for upload with file upload control in supporting scenarios. See the file input type.

checked

Valid for both radio and checkbox types, checked is a Boolean attribute. If present on a radio type, it indicates that that radio button is the currently selected one in the group of same-named radio buttons. If present on a checkbox type, it indicates that the checkbox is checked by default (when the page loads). It does not indicate whether this checkbox is currently checked: if the checkbox’s state is changed, this content attribute does not reflect the change. (Only the HTMLInputElement’s checked IDL attribute is updated.)

Note: Unlike other input controls, a checkboxes and radio buttons value are only included in the submitted data if they are currently checked. If they are, the name and the value(s) of the checked controls are submitted.

For example, if a checkbox whose name is fruit has a value of cherry, and the checkbox is checked, the form data submitted will include fruit=cherry. If the checkbox isn't active, it isn't listed in the form data at all. The default value for checkboxes and radio buttons is on.

dirname

Valid for text and search input types only, the dirname attribute enables the submission of the directionality of the element. When included, the form control will submit with two name/value pairs: the first being the name and value, the second being the value of the dirname as the name with the value of ltr or rtl being set by the browser.

<form action="page.html" method="post">
  <label>Fruit: <input type="text" name="fruit" dirname="fruit.dir" value="cherry"></label>
  <input type="submit"/>
</form>
<!-- page.html?fruit=cherry&fruit.dir=ltr -->

When the form above is submitted, the input cause both the name / value pair of fruit=cherry and the dirname / direction pair of fruit.dir=ltr to be sent.

disabled

A Boolean attribute which, if present, indicates that the user should not be able to interact with the input. Disabled inputs are typically rendered with a dimmer color or using some other form of indication that the field is not available for use.

Specifically, disabled inputs do not receive the click event, and disabled inputs are not submitted with the form.

Note: Although not required by the specification, Firefox will by default persist the dynamic disabled state of an <input> across page loads. Use the autocomplete attribute to control this feature.

form

A string specifying the <form> element with which the input is associated (that is, its form owner). This string's value, if present, must match the id of a <form> element in the same document. If this attribute isn't specified, the <input> element is associated with the nearest containing form, if any.

The form attribute lets you place an input anywhere in the document but have it included with a form elsewhere in the document.

Note: An input can only be associated with one form.

formaction

Valid for the image and submit input types only. See the submit input type for more information.

formenctype

Valid for the image and submit input types only. See the submit input type for more information.

formmethod

Valid for the image and submit input types only. See the submit input type for more information.

formnovalidate

Valid for the image and submit input types only. See the submit input type for more information.

formtarget

Valid for the image and submit input types only. See the submit input type for more information.

height

Valid for the image input button only, the height is the height of the image file to display to represent the graphical submit button. See the image input type.

list

The values of the list attribute is the id of a <datalist> element located in the same document. The <datalist>  provides a list of predefined values to suggest to the user for this input. Any values in the list that are not compatible with the type are not included in the suggested options.  The values provided are suggestions, not requirements: users can select from this predefined list or provide a different value.

It is valid on text, search, url, tel, email, date, month, week, time, datetime-local, number, range, and color.Per the specifications, the list attribute is not supported by the hidden, password, checkbox, radio, file, or any of the button types.

Depending on the browser, the user may see a custom color palette suggested, tic marks along a range, or even a input that opens like a select but allows for non-listed values. Check out the browser compatibility table for the other input types.

See the <datalist> element.

max

Valid for date, month, week, time, datetime-local, number, and range, it defines the greatest value in the range of permitted values. If the value entered into the element exceeds this, the element fails constraint validation. If the value of the max attribute isn't a number, then the element has no maximum value.

This value must be greater than or equal to the value of the min attribute.

maxlength

Valid for text, search, url, tel, email, and password, it defines the maximum number of characters (as UTF-16 code units) the user can enter into the field. This must be an integer value 0 or higher. If no maxlength is specified, or an invalid value is specified, the field has no maximum length. This value must also be greater than or equal to the value of minlength.

The input will fail constraint validation if the length of the text entered into the field is greater than maxlength UTF-16 code units long.

min

Valid for date, month, week, time, datetime-local, number, and range, it defines the most negative value in the range of permitted values. If the value entered into the element is less than this this, the element fails constraint validation. If the value of the min attribute isn't a number, then the element has no minimum value.

This value must be less than or equal to the value of the max attribute.

minlength

Valid for text, search, url, tel, email, and password, it defines the minimum number of characters (as UTF-16 code units) the user can enter into the entry field. This must be an non-negative integer value smaller than or equal to the value specified by maxlength. If no minlength is specified, or an invalid value is specified, the input has no minimum length.

The input will fail constraint validation if the length of the text entered into the field is fewer than minlength UTF-16 code units long.

multiple

The Boolean multiple attribute, if set, means the user can enter comma separated email addresses in the email widget or can choose more than one file with the file input. See the email and file input type.

name

A string specifying a name for the input control. This name is submitted along with the control's value when the form data is submitted.

What's in a name

Consider the name a required attribute (even though it's now). If an input has no name  specified, or name is empty, the input's value is not submitted with the form. (Disabled controls, unchecked radio buttons and checkboxes, and reset buttons are also not sent.)

There are two special cases:

  1.  _charset_ : If used as the name of an <input> element of type hidden, the input's value is automatically set by the user agent to the character encoding being used to submit the form.
  2. isindex: For historical reasons, the name isindex is not allowed.
HTMLFormElement.elements

When an input element is given a name, that name becomes a property of the owning form element's HTMLFormElement.elements property. If you have an input whose name is set to guest and another whose name is hat-size, the following code can be used:

let form = document.querySelector("form");

let guestName = form.elements.guest;
let hatSize = form.elements["hat-size"];

When this code has run, guestName will be the HTMLInputElement for the guest field, and hatSize the object for the hat-size field.

Warning: You should avoid giving form elements a name that corresponds to a built-in property of the form, since you would then override the predefined property or method with this reference to the corresponding input.

pattern

The pattern attribute, when specified, is a regular expression that the input's value must match in order for the value to pass constraint validation. It must be a valid JavaScript regular expression, as used by the RegExp type, and as documented in our guide on regular expressions; the 'u' flag is specified when compiling the regular expression, so that the pattern is treated as a sequence of Unicode code points, instead of as ASCII. No forward slashes should be specified around the pattern text.

If the pattern attribute is present by is not specified or is invalid, no regular expression is applied and this attribute is ignored completely.

Tip: If using the pattern attribute, inform the user about the expected format by including explanatory text nearby. You can also include a title attribute to explain what the requirements are to match the pattern; most browsers will display this title as as a tooltip The visible explanation is required for accessibilty. The tooltip is an enhancement.

See validation for more information.

placeholder

The placeholder attribute is a string that provides a brief hint to the user as to what kind of information is expected in the field. It should be a word or short phrase that demonstrates the expected type of data, rather than an explanatory message. The text must not include carriage returns or line feeds.

Note: The placeholder attribute is not as semantically useful as other ways to explain your form, and can cause unexpected technical issues with your content. See Labels and placeholders in <input>: The Input (Form Input) element for more information.

readonly

A Boolean attribute which, if present, indicates that the user should not be able to edit the value of the input.

The difference between disabled and readonly is that read-only controls can still function, whereas disabled controls are not submitted with the form and generally do not function as controls until they are enabled.

Note: The required attribute is not permitted on inputs with the readonly attribute specified.

Note: Only text controls can be made read-only, since for other controls (such as checkboxes and buttons) there is no useful distinction between being read-only and being disabled, so the readonly attribute does not apply.

required

required is a Boolean attribute which, if present, indicates that the user must specify a value for the input before the owning form can be submitted. The required attribute is supported  text, search, url, tel, email, date, month, week, time, datetime-local, number, password, checkbox, radio, and file. It is not supported by the hidden, range, and color.or any of the button types, including image. by all input types except the following:

Note color and range don't support required, but type color defaults to #00000, and range defaults to the midpoint between min and max -- with min and max defaulting to 0 and 100 respectively in most browsers if not declared -- so always has a value.

When an input has the required attribute, the :required pseudo-class also applies to it. Conversely, inputs without the required attribute (except the elements that don't support it) have the :optional pseudo-class applied.

Note: Because a read-only field cannot have a value, required does not have any effect on inputs with the readonly attribute also specified.

src

Valid for the image input button only, the src is string specifying the URL of the image file to display to represent the graphical submit button. See the image input type.

step

Valid for the numeric input types, including number, date/time input types, and range, the step attribute is a number that specifies the granularity that the value must adhere to.

If not explicitly included, step defaults to 1 for number and range, and 1 unit type (second, week, month, day) for the date/time input types. The value can must be a positive number - integer or float -- or the special value any, which means no stepping is implied, and any value is allowed (barring other constraints, such as min and max).

If any is not explicity set, valid values for the number, date/time input types, and range input types are equal to the basis for stepping - the min value and increments of the step value, up to the max value, if specified. For example, if we have <input type="number" min="10" step="2"> any even integer, 10 or great, is valid. If omitted, <input type="number">, any integer is valid, but floats, like 4.2, are not valid, as step defaults to 1. For 4.2 to be valid, step would have had to be set to any, 0.1, 0.2, or any the min value would have had to be a number ending in .2, such as <input type="number" min="-5.2">

Note: When the data entered by the user doesn't adhere to the stepping configuration, the value is considered invalid in contraint validation and will match the :invalid pseudoclass

The default stepping value for number inputs is 1, allowing only integers to be entered, unless the stepping base is not an integer. The default stepping value for time is 1 second, with 900 being equal to 15 minutes.

type

A string specifying the type of control to render. For example, to create a checkbox, a value of checkbox is used. If omitted (or an unknown value is specified), the input type text is used, creating a plaintext input field.

Permitted values are listed in Form <input> types above.

value

The input control's value. When specified in the HTML, this is the initial value, and from then on it can be altered or retrieved at any time using JavaScript to access the respective HTMLInputElement object's value property. The value attribute is always optional, though should be considered mandatory for checkbox, radio, and hidden.

width

Valid for the image input button only, the width is the width of the image file to display to represent the graphical submit button. See the image input type.

Methods

The following methods are provided by the HTMLInputElement interface which represents <input> elements in the DOM. Also available are those methods specified by the parent interfaces, HTMLElement, Element, Node, and EventTarget.

checkValidity()
Immediately runs the validity check on the element, triggering the document to fire the invalid event at the element if the value isn't valid.
reportValidity()
Returns true if the element's value passes validity checks; otherwise, returns false.
select()
Selects the entire content of the <input> element, if the element's content is selectable. For elements with no selectable text content (such as a visual color picker or calendar date input), this method does nothing.
setCustomValidity()
Sets a custom message to display if the input element's value isn't valid.
setRangeText()
Sets the contents of the specified range of characters in the input element to a given string. A selectMode parameter is available to allow controlling how the existing content is affected.
setSelectionRange()
Selects the specified range of characters within a textual input element. Does nothing for inputs which aren't presented as text input fields.
stepDown()
Decrements the value of a numeric input by one, by default, or by the specified number of units.
stepUp()
Increments the value of a numeric input by one or by the specified number of units.

Styling input elements

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:

HTML

<label for="textInput">Note the red caret:</label>
<input id="textInput" class="custom" size="32">

CSS

input.custom {
  caret-color: red;
  font: 16px "Helvetica", "Arial", "sans-serif"
}

Result

For more information about adding color to elements in HTML, see Applying color to HTML elements using CSS.

Labels and placeholders

TL;DR: To save you time, here's the key point: don't use the placeholder attribute if you can avoid it. If you need to label an <input> element, use the <label> element.

There are three seemingly similar ways to associate assistive text with an <input>. However, they are actually quite different, and only one of them is always a good choice. Here we will look at each of them and learn best practices for providing the user with guidance when entering data into a form.

The <label> element

The <label> element is the only way to provide explanatory information about a form field that is always appropriate (aside from any layout concerns you have). It's never a bad idea to use a <label> to explain what should be entered into an <input> or <textarea>.

The placeholder attribute

The placeholder attribute lets you specify a text that appears within the <input> element's content area itself when empty. It's intended to be used to show an example input, rather than an explanation or prompt, but tends to be badly misused.

Here are two inputs that take a password, each with a placeholder:

Example of correct and incorrect placeholder usage

The first one uses a placeholder string MyGr8P@sswrd, demonstrating what a password might look like. And no, that's not really a great password.

The second one uses a prompt string, Enter your password as a placeholder. The first, and most obvious, problem with doing this is that as soon as the user types their first character, they no longer have a prompt explaining what that field is for.

That's why, instead, you should use the <label> element. The placeholder should never be required in order to understand your forms. While some people are able to remember what a given empty box is meant for after its only identifying text vanishes, others cannot.

If the user can't understand your form if the placeholders are missing (say, in a browser that doesn't support placeholder, or in the case above where the user starts typing then gets confused), you're not using placeholders properly.

In addition, browsers with automatic page translation features may skip over attributes when translating. That means the placeholder may not get translated, resulting in important information not being translated.

If you feel like you need to use a placeholder, it's possible to use both a placeholder and a label:

Unadorned text adjacent to the <input> element

You can also just have plain text adjacent to the <input> element, like this:

<p>Enter your name: <input id="name" type="text" size="30"></p>

Please don't do this. This doesn't create a relationship between the prompt and the <input> element, which is important for reasons we'll get into in the next section.

Why you should use labels

In addition to the information provided above, there are a number of other reasons why <label> is the best way to explain <input>s:

  • The semantic pairing of <input> and <label> elements is useful for assistive technologies such as screen readers. By pairing them using the <label>'s for attribute, you bond the label to the input in a way that lets screen readers describe inputs to users more precisely.
  • By pairing a <label> with an <input>, clicking on either one will focus the <input>. If you use plaintext to "label" your input, this won't happen. Having the prompt part of the activation area for the input is helpful for people with motor control conditions.
  • As web developers, it's important that we never assume that people will know all the things that we know. The diversity of people using the web—and by extension your web site—practically guarantees that some of your site's visitors will have some variation in thought processes and/or circumstances that leads them to interpret your forms very differently from you without clear and properly-presented labels.

Examples

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.

Technical summary

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

Specifications

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.
Recommendation Adds the capture attribute
HTML5
The definition of '<input>' in that specification.
Recommendation
HTML 4.01 Specification
The definition of '<form>' in that specification.
Recommendation

Accessibility concerns

Labels

When including inputs, it is recommended to add labels along side. This is so those who use assistive technologies can tell what the input is for. For more information about labels in general see Labels and placeholders .

The following is an example of how to associate the <label> with an <input> element in the above style. You need to give the <input> an id attribute. The <label> then needs a for attribute whose value is the same as the input's id.

<label for="peas">Do you like peas?</label>
<input type="checkbox" name="peas" id="peas">

Size

Interactive elements such as form input should provide an area large enough that it is easy to activate them. This helps a variety of people, including people with motor control issues and people using non-precise forms of input such as a stylus or fingers. A minimum interactive size of 44 by 44 CSS pixels is recommended.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
inputChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support 1WebView Android Full support 1Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support 1Samsung Internet Android ?
type="button"Chrome Full support 1Edge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support 1WebView Android Full support YesChrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="checkbox"Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="color"Chrome Full support 20Edge Full support 14Firefox Full support 29
Notes
Full support 29
Notes
Notes Firefox doesn't yet support inputs of type color on Windows Touch.
IE No support NoOpera Full support 12Safari Full support 12.1WebView Android Full support 4.4Chrome Android Full support 25Firefox Android Full support 27Opera Android Full support 12Safari iOS Full support 12.2Samsung Internet Android ?
type="date"Chrome Full support 20Edge Full support 12Firefox Full support 57IE No support NoOpera Full support 11Safari No support No
Notes
No support No
Notes
Notes The input type is recognized, but there is no date-specific control. See bug 119175.
WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 57Opera Android Full support 11Safari iOS Full support 5Samsung Internet Android ?
type="datetime-local"Chrome Full support 20Edge Full support 12Firefox No support No
Notes
No support No
Notes
Notes See bug 888320 and TPE DOM/Date time input types.
IE No support NoOpera Full support 11Safari No support No
Notes
No support No
Notes
Notes The input type is recognized, but there is no date-specific control. See bug 200416.
WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support 11Safari iOS Full support YesSamsung Internet Android ?
type="email"Chrome Full support 5Edge ? Firefox Full support YesIE Full support 10Opera Full support 11Safari Full support YesWebView Android ? Chrome Android ? Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support 3.1
Notes
Full support 3.1
Notes
Notes Doesn't do validation, but instead offers a custom 'email' keyboard, which is designed to make entering email addresses easier.
Notes The custom 'email' keyboard does not provide a comma key, so users cannot enter multiple email addresses.
Notes Automatically applies a default style of opacity: 0.4 to disable textual <input> elements, including those of type 'email'. Other major browsers don't currently share this particular default style.
Samsung Internet Android ?
type="file"Chrome Full support 1Edge ? Firefox Full support 1
Notes
Full support 1
Notes
Notes You can set as well as get the value of HTMLInputElement.files in all modern browsers; this was most recently added to Firefox, in version 57 (see bug 1384030).
IE Full support YesOpera Full support 11Safari Full support 1WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support 11Safari iOS Full support YesSamsung Internet Android ?
type="hidden"Chrome Full support 1Edge Full support YesFirefox Full support 1IE Full support YesOpera Full support 2Safari Full support 1WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="image"Chrome Full support YesEdge ? Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android ? Firefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
x-moz-errormessage attribute
ExperimentalDeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support ? — 66IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support ? — 66Opera Android No support NoSafari iOS No support NoSamsung Internet Android ?
type="month"Chrome Full support 20Edge Full support 12Firefox No support No
Notes
No support No
Notes
Notes See bug 888320.
IE No support NoOpera Full support 11Safari No support No
Notes
No support No
Notes
Notes The input type is recognized, but there is no month-specific control. See bug 200416.
WebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="number"Chrome Full support YesEdge Full support 12Firefox Full support YesIE Full support 10Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="password"Chrome Full support 1Edge ? Firefox Full support 1IE Full support 2Opera Full support 2Safari Full support 1WebView Android ? Chrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="radio"Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="range"Chrome Full support 4Edge Full support 12Firefox Full support 23IE Full support 10Opera Full support 11Safari Full support 3.1WebView Android Full support 4.4
Full support 4.4
No support 2 — 4.4
Notes
Notes Pre-Chromium Android WebView recognizes the range type, but doesn't implement a range-specific control.
Chrome Android Full support 57Firefox Android Full support 52Opera Android Full support YesSafari iOS Full support 5.1Samsung Internet Android ?
type="reset"Chrome Full support 1Edge ? Firefox Full support 1
Notes
Full support 1
Notes
Notes Unlike other browsers, Firefox by default persists the dynamic disabled state of a &ltbutton&gt across page loads. Use the autocomplete attribute to control this feature.
IE Full support YesOpera Full support YesSafari Full support 1WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4
Notes
Full support 4
Notes
Notes Unlike other browsers, Firefox by default persists the dynamic disabled state of a &ltbutton&gt across page loads. Use the autocomplete attribute to control this feature.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="search"Chrome Full support 5Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 10.6Safari Full support 5WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="submit"Chrome Full support 1Edge Full support YesFirefox Full support 1
Notes
Full support 1
Notes
Notes Unlike other browsers, Firefox by default persists the dynamic disabled state of a <button> across page loads. Use the autocomplete attribute to control this feature.</button>
IE Full support YesOpera Full support YesSafari Full support 1WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4
Notes
Full support 4
Notes
Notes Unlike other browsers, Firefox by default persists the dynamic disabled state of a <button> across page loads. Use the autocomplete attribute to control this feature.</button>
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="tel"Chrome Full support YesEdge Full support YesFirefox Full support YesIE Full support 10Opera Full support 11Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="text"Chrome Full support 1Edge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support 1WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="time"Chrome Full support 20Edge Full support 12Firefox Full support 57IE No support NoOpera Full support 10Safari No support No
Notes
No support No
Notes
Notes See bug 200416.
WebView Android Full support YesChrome Android Full support 25Firefox Android Full support 57Opera Android Full support YesSafari iOS No support NoSamsung Internet Android ?
type="url"Chrome Full support 1Edge Full support YesFirefox Full support YesIE Full support 10Opera Full support 11Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
type="week"Chrome Full support 20Edge Full support 12Firefox No support No
Notes
No support No
Notes
Notes See bug 888320.
IE No support NoOpera Full support 11Safari No support No
Notes
No support No
Notes
Notes See bug 200416.
WebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.

[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.

Notes

Custom error messages

If you want to present a custom error message when a field fails to validate, you need to use the Constraint validation features available on <input> (and related) elements. Take the following form:

<form>
  <label for="name">Enter username (upper and lowercase letters): </label>
  <input type="text" name="name" id="name" required pattern="[A-Za-z]+">
  <button>Submit</button>
</form>

The basic HTML form validation features will cause this to produce a default error message if you try to submit the form with either no valid filled in, or a value that does not match the pattern.

If you wanted to instead display custom error messages, you could use JavaScript like the following:

const nameInput = document.querySelector('input');
const form = document.querySelector('form');

nameInput.addEventListener('input', () => {
  nameInput.setCustomValidity('');
  nameInput.checkValidity();
});

nameInput.addEventListener('invalid', () => {
  if(nameInput.value === '') {
    nameInput.setCustomValidity('Enter your username!');
  } else {
    nameInput.setCustomValidity('Usernames can only contain upper and lowercase letters. Try again!');
  }
});

The example renders like so:

In brief:

  • We check the valid state of the input element every time its value is changed by running the checkValidity() method via the input event handler.
  • If the value is invalid, an invalid event is raised, and the invalid event handler function is run. Inside this function we work out whether the value is invalid because it is empty, or because it doesn't match the pattern, using an if() block, and set a custom validity error message.
  • As a result, if the input value is invalid when the submit button is pressed, one of the custom error messages will be shown.
  • If it is valid, it will submit as you'd expect. For this to happen, the custom validity has to be cancelled, by invoking setCustomValidity() with an empty string value. We therefore do this every time the input event is raised. If you don't do this, and a custom validity was previously set, the input will register as invalid, even if it current contains a valid value on submission.

Note: Firefox supported a proprietary error attribute — x-moz-errormessage — for many versions, which allowed you set custom error messages in a similar way. This has been removed as of version 66 (see bug 1513890).

Localization

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"):

  • Try the language specified by a lang/xml:lang attribute on the element or any of its parents.
  • Try the language specified by any Content-Language HTTP header or
  • If none specified, use the browser's locale.

Using mozactionhint on Firefox mobile

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.

See also