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/zh-tw/web/html/element/input/index.html | 750 ++++++++++++++++++++++++++ 1 file changed, 750 insertions(+) create mode 100644 files/zh-tw/web/html/element/input/index.html (limited to 'files/zh-tw/web/html/element/input/index.html') diff --git a/files/zh-tw/web/html/element/input/index.html b/files/zh-tw/web/html/element/input/index.html new file mode 100644 index 0000000000..6a3a936339 --- /dev/null +++ b/files/zh-tw/web/html/element/input/index.html @@ -0,0 +1,750 @@ +--- +title: +slug: Web/HTML/Element/input +tags: + - Element + - Forms + - HTML + - HTML forms + - HTML input tag + - MakeBrowserAgnostic + - NeedsBrowserCompatibility + - NeedsMobileBrowserCompatibility + - NeedsTranslation + - Reference + - TopicStub + - Web +translation_of: Web/HTML/Element/input +--- +
{{draft}}{{HTMLRef}}
+ +

The HTML <input> element is used to create interactive controls for web-based forms in order to accept data from the user.

+ +

Live example

+ +

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.

+ +

{{EmbedGHLiveSample("learning-area/html/forms/editable-input-example/editable_input.html", '100%', 230)}}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Content categoriesFlow content, listed, submittable, resettable, form-associated element, phrasing content. If the {{htmlattrxref("type", "input")}} is not hidden, then labellable 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|research: 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 type 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, 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: +
    +
  • A 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")}}
+
A single-character that the user can press to switch input focus to the control. This attribute is global in HTML5.
+
{{htmlattrdef("autocomplete")}} {{HTMLVersionInline("5")}}
+
This attribute indicates whether the value of the control can be automatically completed by the browser.
+
Possible values are: +
    +
  • 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").
  • +
  • nickname
  • +
  • email
  • +
  • username
  • +
  • new-password: A new password (e.g. when creating an account or changing a password).
  • +
  • current-password
  • +
  • organization-title: Job title (e.g. "Software Engineer", "Senior Vice President", "Deputy Managing Director").
  • +
  • organization
  • +
  • street-address
  • +
  • address-line1address-line2address-line3address-level4address-level3address-level2address-level1
  • +
  • country
  • +
  • country-name
  • +
  • postal-code
  • +
  • cc-name: Full name as given on the payment instrument.
  • +
  • cc-given-name
  • +
  • cc-additional-name
  • +
  • cc-family-name
  • +
  • cc-number: Code identifying the payment instrument (e.g. the credit card number).
  • +
  • cc-exp: Expiration date of the payment instrument.
  • +
  • cc-exp-month
  • +
  • cc-exp-year
  • +
  • cc-csc: Security code for the payment instrument.
  • +
  • cc-type: Type of payment instrument (e.g. Visa).
  • +
  • transaction-currency
  • +
  • transaction-amount
  • +
  • language: Preferred language; a valid BCP 47 language tag.
  • +
  • bday: birthday
  • +
  • bday-day
  • +
  • bday-month
  • +
  • bday-year
  • +
  • sex: Gender identity (e.g. Female, Fa'afafine), free-form text, no newlines.
  • +
  • tel: full telephone number, including country code +
      +
    • additional 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 {{htmlattrxref("autocomplete", "form")}} attribute in {{HTMLElement("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.

+
+
{{htmlattrdef("autofocus")}} {{HTMLVersionInline("5")}}
+
This Boolean attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it (e.g. by typing in a different control). Only one form element in a document can have the autofocus attribute, which is a Boolean. It cannot be applied if the type attribute is set to 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.
+
{{htmlattrdef("capture")}}
+
+

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

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

When 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 {{htmlattrxref("autocomplete","input")}} attribute to control this feature.

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

This 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 {{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 is not specified, this <input> element must be a descendant of a {{HTMLElement("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.
+
{{htmlattrdef("formaction")}} {{HTMLVersionInline("5")}}
+
The URI of a program that processes the information submitted by the input element, if it is a submit button or image. If specified, it 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 type of content that is used to submit the form to the server. Possible values are: +
    +
  • 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
  • +
+ +

If this attribute is specified, it 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 are: +
    +
  • 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 {{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 is not to be validated when it is submitted. If this attribute is specified, it 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 after submitting the form. This is a name of, or keyword for, a browsing context (e.g. tab, window, or inline frame). If this attribute is specified, it 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 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.
  • +
+
+
{{htmlattrdef("height")}} {{HTMLVersionInline("5")}}
+
If the value of the type attribute is image, this attribute defines the height of the image displayed for the button.
+
{{htmlattrdef("inputmode")}} {{HTMLVersionInline("5")}}
+
A hint to the browser for which keyboard to display. This attribute applies when the value of the type attribute is text, password, email, or url. Possible values are: +
    +
  • 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.
  • +
+
+
{{htmlattrdef("list")}} {{HTMLVersionInline("5")}}
+
Identifies a list of pre-defined options to suggest to the user. The value must be the id of a {{HTMLElement("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.
+
{{htmlattrdef("max")}} {{HTMLVersionInline("5")}}
+
The maximum (numeric or date-time) value for this item, which 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. 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.
+
{{htmlattrdef("min")}} {{HTMLVersionInline("5")}}
+
The minimum (numeric or date-time) value for this item, 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 Unicode 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 applies when the type attribute is set to email or file, otherwise it is ignored.
+
{{htmlattrdef("name")}}
+
The name of the control, which is submitted with the form data.
+
{{htmlattrdef("pattern")}} {{HTMLVersionInline("5")}}
+
A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url, email, or password, otherwise it is ignored. The regular expression language is the same as 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 . The placeholder text must not contain carriage returns or line-feeds. +
Note: Do not use the placeholder attribute instead of a {{HTMLElement("label")}} element, their purposes are different. The {{HTMLElement("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.
+
+
{{htmlattrdef("readonly")}} {{HTMLVersionInline("5")}}
+
This attribute indicates that the user cannot modify the value of the control. The value of the attribute is irrelevant. If you need read-write access to the input value, do not add the "readonly" attribute. 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("selectionDirection")}} {{HTMLVersionInline("5")}}
+
The direction in which selection occurred. This is "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.
+
{{htmlattrdef("selectionEnd")}}
+
The offset into the element's text content of the last selected character. If there's no selection, this value indicates the offset to the character following the current text input cursor position (that is, the position the next character typed would occupy).
+
{{htmlattrdef("selectionStart")}}
+
The offset into the element's text content of the first selected character. If there's no selection, this value indicates the offset to the character following the current text input cursor position (that is, the position the next character typed would occupy).
+
{{htmlattrdef("size")}}
+
The initial size of the control. This value is in pixels unless the value of the type attribute is text 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.
+
{{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 a URI for the location of an image to display on the graphical submit button, otherwise it is ignored.
+
{{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.
+ Note that when reloading the page, Gecko 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.
+
+ +

Non-standard <input> attributes

+ +
+
{{htmlattrdef("autocapitalize")}} {{non-standard_inline}}
+
This is a nonstandard attribute used by Chrome and iOS Safari Mobile, which controls whether and how the text value should be automatically capitalized as it is entered/edited by the user. The non-deprecated values are available in iOS 5 and later. Possible values are: +
    +
  • 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_inline}} Deprecated since iOS 5.
  • +
  • off: {{deprecated_inline}} Deprecated since iOS 5.
  • +
+ autocapitalize documentation in the Safari HTML Reference.
+
{{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.
+
+ +

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

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support1.0{{CompatGeckoDesktop("1.7")}}{{CompatVersionUnknown}}1.01.0
type="color"21.0{{CompatGeckoDesktop("29.0")}}{{CompatNo}}11.01{{CompatNo}}
type="email", type="number", type="range", type="search", type="tel", type="url"{{CompatVersionUnknown}}{{CompatVersionUnknown}}10{{CompatVersionUnknown}}{{CompatVersionUnknown}}
type="datetime-local", type="month", type="week"20{{CompatNo}}{{CompatNo}}10.62{{CompatVersionUnknown}}[2]
type="date", type="time"20{{CompatNo}}[1]{{CompatNo}}10.62{{CompatVersionUnknown}}[2]
type="datetime"{{CompatNo}}[5]{{CompatNo}}[5]{{CompatNo}}[5]{{CompatNo}}[5]{{CompatNo}}[5]
accept{{CompatVersionUnknown}}{{CompatVersionUnknown}}10{{CompatUnknown}}{{CompatNo}}
mozactionhint{{CompatNo}}{{CompatGeckoDesktop("2.0")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
autocapitalize43{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}} [4]
autofocus, max, min, pattern, placeholder, required, step, list, multiple5.0{{CompatVersionUnknown}}109.65.0
captureChrome for Android (0.16){{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
fakepath added to file input values{{CompatVersionUnknown}}{{CompatGeckoDesktop("53")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
form, formaction, formenctype, formmethod, formnovalidate, formtarget9.0{{CompatGeckoDesktop("2.0")}}1010.62{{CompatUnknown}}
incremental{{CompatVersionUnknown}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatVersionUnknown}}
inputmode{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
minlength40.0{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
readonly1.0{{CompatGeckoDesktop("1.7")}}6[3] 1.01.0
spellcheck10.0{{CompatGeckoDesktop("1.9.2")}}1011.04.0
webkitdirectory{{CompatVersionUnknown}}{{CompatGeckoDesktop("49.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatGeckoMobile("2.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
type="color"{{CompatUnknown}}{{CompatGeckoDesktop("27.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
type="email", type="number", type="range", type="search", type="tel", type="url"{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
type="date", type="datetime-local", type="month", type="time", type="week'{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
type="datetime"{{CompatNo}}[5]{{CompatNo}}[5]{{CompatNo}}[5]{{CompatNo}}[5]{{CompatNo}}[5]
accept{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
autocapitalize{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}[4]
autofocus, max, min, pattern, placeholder, required, step, list, multiple{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
capture3.0{{CompatGeckoMobile("10.0")}}{{CompatUnknown}}{{CompatUnknown}}6.0
fakepath added to file input values{{CompatVersionUnknown}}{{CompatGeckoMobile("53")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
form, formaction, formenctype, formmethod, formnovalidate, formtarget{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
minlength{{CompatUnknown}}{{CompatNo}}{{CompatUnknown}}27.0{{CompatUnknown}}
spellcheck{{CompatUnknown}}{{CompatGeckoMobile("2.0")}}{{CompatUnknown}}11.0{{CompatUnknown}}
webkitdirectory{{CompatVersionUnknown}}{{CompatGeckoMobile("49.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

[1] This feature is implemented behind the preference dom.forms.datetime since Gecko 51 {{geckoRelease(51)}}, defaulting to false. Since Gecko 55 it is enabled by default on Firefox Nightly (see {{bug(1366188)}}). See also {{bug("888320")}} and TPE DOM/Date time input types.

+ +

[2] It is recognized but there is no UI.

+ +

[3] Missing for type="checkbox" and type="radio".

+ +

[4] In Safari autocapitalize="words" capitalizes every word's second character.

+ +

[5] datetime has been removed from the spec and browsers in favour of datetime-local.

+ +

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:

+ +

mozactionhint.png

+ +

See also

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