From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- files/uk/web/html/element/input/index.html | 753 +++++++++++++++++++++++++++++ 1 file changed, 753 insertions(+) create mode 100644 files/uk/web/html/element/input/index.html (limited to 'files/uk/web/html/element/input/index.html') diff --git a/files/uk/web/html/element/input/index.html b/files/uk/web/html/element/input/index.html new file mode 100644 index 0000000000..3c0f2289b3 --- /dev/null +++ b/files/uk/web/html/element/input/index.html @@ -0,0 +1,753 @@ +--- +title: ': The Input (Form Input) element' +slug: Web/HTML/Element/input +tags: + - Data entry + - Element + - Forms + - HTML + - HTML forms + - HTML input tag + - Input + - MakeBrowserAgnostic + - NeedsBrowserCompatibility + - NeedsMobileBrowserCompatibility + - NeedsTranslation + - Reference + - TopicStub + - Web +translation_of: Web/HTML/Element/input +--- +
{{HTMLRef}}
+ +

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 {{Glossary("user agent")}}.

+ +
{{EmbedInteractiveExample("pages/tabbed/input-input.html", "tabbed-standard")}}
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Content categoriesFlow content, listed, submittable, resettable, form-associated element, phrasing content. If the {{htmlattrxref("type", "input")}} is not hidden, then labelable element, palpable content.
Permitted contentNone, it is an {{Glossary("empty element")}}.
Tag omissionMust have a start tag and must not have an end tag.
Permitted parentsAny element that accepts phrasing content.
Permitted ARIA roles +
    +
  • type=button: {{ARIARole("link")}}, {{ARIARole("menuitem")}}, {{ARIARole("menuitemcheckbox")}}, {{ARIARole("menuitemradio")}}, {{ARIARole("radio")}}, {{ARIARole("switch")}}, {{ARIARole("tab")}}
  • +
  • type=checkbox: {{ARIARole("button")}}, {{ARIARole("menuitemcheckbox")}}, {{ARIARole("option")}}, {{ARIARole("switch")}}
  • +
  • type=image: {{ARIARole("link")}}, {{ARIARole("menuitem")}}, {{ARIARole("menuitemcheckbox")}}, {{ARIARole("menuitemradio")}}, {{ARIARole("radio")}}, {{ARIARole("switch")}}
  • +
  • type=radio: {{ARIARole("menuitemradio")}}
  • +
  • type=color|date|datetime|datetime-local|email|file: None
  • +
  • type=hidden|month|number|password|range|reset: None
  • +
  • type=search|submit|tel|text|url|week: None
  • +
+
DOM interface{{domxref("HTMLInputElement")}}
+ +

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

+ +

The available types are as follows:

+ + + +

Some input types are now obsolete:

+ + + +

Attributes

+ +

Global <input> attributes

+ +

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

+
+ +
+
{{htmlattrdef("type")}}
+
The type of control to render. See {{anch("Form <input> types")}} for the individual types, with links to more information about each.
+
{{htmlattrdef("accept")}}
+
If the value of the type attribute is file, this attribute indicates the types of files that the server accepts — otherwise it's ignored. The value must be comma-separated unique “content type specifiers”: +
    +
  • A case-insensitive file extension starting with the STOP character (U+002E). (e.g. .jpg, .png, .doc).
  • +
  • A valid MIME type with no extensions.
  • +
  • audio/* representing sound files. {{HTMLVersionInline("5")}}
  • +
  • video/* representing video files. {{HTMLVersionInline("5")}}
  • +
  • image/* representing image files. {{HTMLVersionInline("5")}}
  • +
+
+
{{htmlattrdef("accesskey")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline", "HTML5")}}
+
Sets a keyboard key that the user can press to focus the control. This attribute is global in HTML5 — see the accesskey page for more info.
+
{{htmlattrdef("autocomplete")}} {{HTMLVersionInline("5")}}
+
This attribute indicates if the input can be automatically completed by the browser, usually by remembering previous values the user has entered. {{page("/en-US/docs/Web/HTML/Attributes/autocomplete", "Values")}}
+
See The HTML autocomplete attribute for additional information.
+
{{htmlattrdef("autofocus")}} {{HTMLVersionInline("5")}}
+
This Boolean attribute specifies that the input should have focus when the page loads, unless the user overrides it (e.g. by typing in a different control). Only one element in a document can have the autofocus attribute. It cannot be applied if the type attribute is hidden, because hidden inputs cannot be focused. Note that the input may be focused before the DOMContentLoaded event fires. +
Warning: Automatically focusing a form control can confuse visually-impaired people who using screen-reading technology. When autofocus is assigned, screen-readers "teleport" their user to the form control without warning them beforehand.
+
+
{{htmlattrdef("capture")}}
+
+

If the value of the type attribute is file, this Boolean attribute indicates that capture of media directly from the device's sensors using a media capture mechanism is preferred, such as a webcam or microphone.

+
+
{{htmlattrdef("checked")}}
+
+

If the value of the type attribute is radio or checkbox, this Boolean attribute pre-checks the control before the user interacts with it.

+ +

Unlike other browsers, Firefox by default persists the dynamic checked state of an <input> across page loads. Use the {{htmlattrxref("autocomplete","input")}} attribute to control this feature.

+
+
{{htmlattrdef("disabled")}}
+
+

This Boolean attribute prevents the user from interacting with the input. In particular, the click event is not dispatched on disabled controls, and disabled controls aren't submitted with their form.

+ +

Unlike other browsers, Firefox will by default persist the dynamic disabled state of an <input> across page loads. Use the {{htmlattrxref("autocomplete","input")}} attribute to control this feature.

+
+
{{htmlattrdef("form")}} {{HTMLVersionInline("5")}}
+
The form element that the input element is associated with (its form owner). The value of the attribute must be an id of a {{HTMLElement("form")}} element in the same document. If this attribute isn't used, the <input> element is associated with its nearest ancestor {{HTMLElement("form")}} element, if any. This attribute lets you to place <input> elements anywhere within a document, not just as descendants of form elements. An input can be associated with at most one form.
+
{{htmlattrdef("formaction")}} {{HTMLVersionInline("5")}}
+
The URL that processes the data submitted by the input element, if it is a submit button or image. This attribute overrides the {{htmlattrxref("action","form")}} attribute of the element's form owner.
+
{{htmlattrdef("formenctype")}} {{HTMLVersionInline("5")}}
+
If the input element is a submit button or image, this attribute specifies the content encoding that is used to submit the form data to the server. Possible values: +
    +
  • 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 {{htmlattrxref("type","input")}} attribute set to file.
  • +
  • text/plain: This encoding is mostly for debugging.
  • +
+ +

This attribute overrides the {{htmlattrxref("enctype","form")}} attribute of the element's form owner.

+
+
{{htmlattrdef("formmethod")}} {{HTMLVersionInline("5")}}
+
If the input element is a submit button or image, this attribute specifies the HTTP method that the browser uses to submit the form. Possible values: +
    +
  • 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 URL, with a '?' as a separator, and the resulting URL is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.
  • +
+ +

This attribute overrides the {{htmlattrxref("method","form")}} attribute of the element's form owner.

+
+
{{htmlattrdef("formnovalidate")}} {{HTMLVersionInline("5")}}
+
If the input element is a submit button or image, this Boolean attribute specifies that the form shouldn't be validated before submission. This attribute overrides the {{htmlattrxref("novalidate","form")}} attribute of the element's form owner.
+
{{htmlattrdef("formtarget")}} {{HTMLVersionInline("5")}}
+
If the input element is a submit button or image, this attribute is a name or keyword indicating where to display the response that is received by submitting the form. This is a name of, or keyword for, a browsing context (e.g. tab, window, or inline frame). This attribute overrides the {{htmlattrxref("target", "form")}} 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 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.
  • +
+
+
{{htmlattrdef("height")}} {{HTMLVersionInline("5")}}
+
If the value of the type attribute is image, defines the height of the image displayed for the button in pixels.
+
{{htmlattrdef("inputmode")}} {{HTMLVersionInline("5")}}
+
A hint to browsers for which virtual keyboard to display. This attribute applies when the the type attribute is text, password, email, or url. Possible values: +
    +
  • none: No virtual keyboard should be displayed.
  • +
  • text: Text input in the user's locale.
  • +
  • decimal: Fractional numeric input.
  • +
  • numeric: Numeric input.
  • +
  • tel: Telephone input, including asterisk and pound key. Prefer <input type="tel">.
  • +
  • search: A virtual keyboard optimized for search input.
  • +
  • email: Email input. Prefer <input type="email">.
  • +
  • url: URL input. Prefer <input type="url">.
  • +
+ +
+
Spec conflict: The WHATWG spec lists inputmode, and modern browsers are working towards supporting it. The W3C HTML 5.2 spec however no longer lists it (i.e. marks it as obsolete). You should consider the WHATWG definition as correct, until a consensus is reached.
+
+
+
{{htmlattrdef("list")}} {{HTMLVersionInline("5")}}
+
Points to a {{HTMLElement("datalist")}} of predefined options to suggest to the user. The value must be the id of a <datalist> element in the same document. Browsers display only valid options for the input. This attribute is ignored when the type attribute is hidden, checkbox, radio, file, or a button type.
+
{{htmlattrdef("max")}} {{HTMLVersionInline("5")}}
+
The maximum (numeric or date-time) value for the input. Must not be less than its minimum (min attribute) value.
+
{{htmlattrdef("maxlength")}}
+
If the value of the type attribute is text, 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.
+
{{htmlattrdef("min")}} {{HTMLVersionInline("5")}}
+
The minimum (numeric or date-time) value for this input, which must not be greater than its maximum (max attribute) value.
+
{{htmlattrdef("minlength")}} {{HTMLVersionInline("5")}}
+
If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the minimum number of characters (in UTF-16 code points) that the user can enter. For other control types, it is ignored.
+
{{htmlattrdef("multiple")}} {{HTMLVersionInline("5")}}
+
This Boolean attribute indicates whether the user can enter more than one value. This attribute only applies when the type attribute is set to email or file.
+
{{htmlattrdef("name")}}
+
The name of the control, which is submitted with the control's value as part of the form data. If no name is specified or it is empty, the control's value is not submitted with the form.
+
{{htmlattrdef("pattern")}} {{HTMLVersionInline("5")}}
+
A regular expression that the control's value is checked against. The pattern must match the entire value. Use the title attribute to describe the pattern to help the user. This attribute only applies when the value of the type attribute is text, search, tel, url, email, or password. The regular expression language is the same as the JavaScript {{jsxref("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.
+
{{htmlattrdef("placeholder")}} {{HTMLVersionInline("5")}}
+
A hint to the user of what can be entered in the control, typically in the form of an example of the type of information that should be entered. The placeholder text must not contain carriage returns or line-feeds. +
Note: Before using placeholder, please see the section {{anch("Labels and placeholders")}} to ensure that you use them correctly if at all. Placeholders can be confusing and can disrupt certain operations in unexpected ways.
+
+
{{htmlattrdef("readonly")}} {{HTMLVersionInline("5")}}
+
This Boolean attribute prevents the user from modifying the value of the input. It is ignored if the value of the type attribute is hidden, range, color, checkbox, radio, file, or a button type (such as button or submit).
+
{{htmlattrdef("required")}} {{HTMLVersionInline("5")}}
+
This attribute specifies that the user must fill in a value before submitting a form. It cannot be used when the type attribute is hidden, image, or a button type (submit, reset, or button). The {{cssxref(":optional")}} and {{cssxref(":required")}} CSS pseudo-classes will be applied to the field as appropriate.
+
{{htmlattrdef("size")}}
+
The initial size of the control. 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. The size must be an integer greater than zero. The default value is 20.
+
HTML5 states "the user agent should ensure that at least that many characters are visible", but different characters 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 as x.
+
{{htmlattrdef("spellcheck")}} {{HTMLVersionInline("5")}}
+
Setting the value of this attribute to 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.
+
{{htmlattrdef("src")}}
+
If the value of the type attribute is image, this attribute specifies the URL of the image file to display on the graphical submit button.
+
{{htmlattrdef("step")}} {{HTMLVersionInline("5")}}
+
Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set. It can be the string 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.
+
{{htmlattrdef("tabindex")}} element-specific in {{HTMLVersionInline(4)}}, global in {{HTMLVersionInline("5")}}
+
The position of the element in the tabbing navigation order for the current document.
+
{{htmlattrdef("usemap")}} {{HTMLVersionInline(4)}} only, {{obsoleteGeneric("inline", "HTML5")}}
+
The name of a {{HTMLElement("map")}} element to be used as an image map.
+
{{htmlattrdef("value")}}
+
The initial value of the control. This attribute is optional except when the value of the type attribute is radio or checkbox.
+
When reloading the page, Firefox and IE will ignore the value specified in the HTML source, if the value was changed before the reload.
+
{{htmlattrdef("width")}} {{HTMLVersionInline("5")}}
+
If the value of the type attribute is image, this attribute defines the width of the image displayed for the button in pixels.
+
+ +

Non-standard <input> attributes

+ +
+
{{htmlattrdef("autocorrect")}} {{non-standard_inline}}
+
This is a non-standard attribute supported by Safari that is used to control whether autocorrection should be enabled when the user is entering/editing the text value of the <input>. Possible attribute values are: +
    +
  • on: Enable autocorrection.
  • +
  • off: Disable autocorrection.
  • +
+ autocorrect documentation in the Safari HTML Reference.
+
{{htmlattrdef("incremental")}} {{non-standard_inline}}
+
This is a nonstandard attribute supported by WebKit (Safari) and Blink (Chrome) that only applies when the type is 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
+
{{htmlattrdef("mozactionhint")}} {{non-standard_inline}}
+
Specifies an "action hint" used to determine how to label the enter key on mobile devices with virtual keyboards. Supported values are go, done, next, search, and send. These automatically get mapped to the appropriate string and are case-insensitive.
+
{{htmlattrdef("results")}} {{non-standard_inline}}
+
This is a nonstandard attribute supported by Safari that only applies when the type is 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.
+
{{htmlattrdef("webkitdirectory")}} {{non-standard_inline}}
+
This Boolean attribute indicates if the selector used when the type attribute is file has to allow for the selection of directories only.
+
{{htmlattrdef("x-moz-errormessage")}} {{non-standard_inline}}
+
This Mozilla extension allows you to specify the error message to display when a field doesn't successfully validate.
+
+ +

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 {{cssxref("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

+ +

{{EmbedLiveSample('Styling_input_elements', 500, 80)}}

+ +

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 {{htmlattrxref("placeholder", "input")}} attribute if you can avoid it. If you need to label an <input> element, use the {{HTMLElement("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 {{HTMLElement("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 {{HTMLElement("textarea")}}.

+ +

The placeholder attribute

+ +

The {{htmlattrxref("placeholder", "input")}} attribute lets you specify a prompt 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 {{HTMLElement("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:

+ + + +

Examples

+ +

You can find multiple examples of <input> element usage on the pages covering each individual type — see {{anch("Form <input> types")}}, and also see the {{anch("Live example")}} at the top of the article.

+ + + +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', 'forms.html#the-input-element', '<input>')}}{{Spec2('HTML WHATWG')}} 
{{SpecName('HTML Media Capture', '#the-capture-attribute','<input capture>')}}{{Spec2('HTML Media Capture')}}Adds the capture element
{{SpecName('HTML5 W3C', 'forms.html#the-input-element', '<input>')}}{{Spec2('HTML5 W3C')}} 
{{SpecName('HTML4.01', 'interact/forms.html#h-17.4', '<form>')}}{{Spec2('HTML4.01')}} 
+ +

Browser compatibility

+ + + +

{{Compat("html.elements.input")}}

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support1.0{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.7")}}{{CompatVersionUnknown}}1.01.0
type="time"20{{CompatVersionUnknown}}{{CompatGeckoDesktop(57)}}{{CompatNo}}10.62{{CompatNo}}[1]
accept{{CompatVersionUnknown}}{{CompatNo}}{{CompatVersionUnknown}}10{{CompatUnknown}}{{CompatNo}}
mozactionhint{{CompatNo}}{{CompatNo}}{{CompatGeckoDesktop("2.0")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
autocapitalize43{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}} [3]
autofocus, max, min, pattern, placeholder, required, step, list, multiple5.0{{CompatVersionUnknown}}{{CompatVersionUnknown}}109.65.0
captureChrome for Android (0.16){{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
fakepath added to file input values{{CompatVersionUnknown}}{{CompatNo}}{{CompatGeckoDesktop("53")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
form10{{CompatVersionUnknown}}4{{CompatNo}}[7]9.55.0
formaction, formenctype, formmethod, formnovalidate, formtarget9.0{{CompatVersionUnknown}}{{CompatGeckoDesktop("2.0")}}1010.625.1
incremental{{CompatVersionUnknown}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}{{CompatVersionUnknown}}
inputmode{{CompatVersionUnknown}}{{CompatNo}}{{CompatGeckoDesktop("17")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
minlength40.0{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
readonly1.0{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.7")}}6[2] 1.01.0
spellcheck10.0{{CompatNo}}{{CompatGeckoDesktop("1.9.2")}}1011.04.0
webkitdirectory{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoDesktop("49.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("2.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
type="time"{{CompatNo}}{{CompatVersionUnknown}}{{CompatGeckoDesktop(57)}}{{CompatNo}}10.62{{CompatVersionUnknown}}[1]
accept{{CompatVersionUnknown}}{{CompatNo}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
autocapitalize{{CompatUnknown}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}[3]
autofocus, max, min, pattern, placeholder, required, step, list, multiple{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}[5]{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
capture3.0{{CompatNo}}{{CompatGeckoMobile("10.0")}}{{CompatUnknown}}{{CompatUnknown}}6.0
fakepath added to file input values{{CompatVersionUnknown}}{{CompatNo}}{{CompatGeckoMobile("53")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
form, formaction, formenctype, formmethod, formnovalidate, formtarget{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
minlength{{CompatUnknown}}{{CompatNo}}{{CompatNo}}{{CompatUnknown}}27.0{{CompatUnknown}}
spellcheck{{CompatUnknown}}{{CompatNo}}{{CompatGeckoMobile("2.0")}}{{CompatUnknown}}11.0{{CompatUnknown}}
webkitdirectory{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("49.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

[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

+ +

File inputs

+ +
    +
  1. +

    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.

    +
  2. +
  3. +

    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";
    +
    +
  4. +
  5. +

    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.

    +
  6. +
+ +

Error messages

+ +

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.

+ +

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

+ + + +

Using mozactionhint on Firefox mobile

+ +

You can use the {{htmlattrxref("mozactionhint", "input")}} 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

+ + -- cgit v1.2.3-54-g00ecf