Use placeholder attributes
Don’t replace a label with a placeholder attribute. If labels are visually hidden, confirm that placeholders have sufficient contrast.
Form input placeholder attributes are helpful for providing hints to (sighted) users in forms. Often times, due to design decisions, a placeholder is used to replace a more semantic label element. Unfortunately, accessible placeholder browser support isn’t complete and placeholders often lack sufficient color contrast by default.
Now, there’s nothing wrong with using placeholders — they can still be used. However, they should be used in addition to a label, not as a replacement. What happens when we don’t use a label for an input element, is a screen reader will get to that field, but won’t have any information for the user on what the input element is for. So the screen reader user doesn’t know what information to fill out. Also, a placeholder disappears when the input element is in focus, and can be an issue for people with memory impairments.
Make your forms accessible by using one of the following methods (in order of preference):
- Redesign to include a proper visible label
- Use aria-label or aria-labelledby to provide assistive text label elements (in an accessible manner)
While we’re paying attention to our placeholder text, let’s review how to add better contrast:
The above CSS assumes that the background for the form controls are #fff . If we test #fff and #626262 in a color contrast tool like Tanaguru Contrast-Finder, the results will approve these colors for valid contrast. You can use your own color for this, but be sure to read about how conformance levels work, and use a color contrast tool to confirm.
In the above CSS, each selector for placeholder text needs to be seperate in their own declaration blocks. The reason for this is due to the prefixes needed for placeholder styles to apply. The browser will read the first selector, and if it’s not the prefix for that browser, instead of reading through the rest until one applies, it will ignore the rest. To ensure each browser can find it’s own prefixed placeholder text styles, it’s necessary to write them each separate as we did above.
Once we have sufficient color contrast in our placeholders, placeholders can be used in addition to labels. Here are two examples of forms where placeholders are used with labels to maintain accessibility.
Labeling
Explicit labeling
Implicit & explicit labeling combined
Note that in the second example above, omitting the for attribute on the label is still valid, but still best practice to include. By keeping the for attribute in place, we’re combining both explicit and implicit techniques.
For more about explicit and implicit labeling, check out "Labeled with Love". By adding the for attribute to a label with the same value as the ID for the input element it corresponds to, the label becomes explicitly associated with that input element. Explicit labeling is great for screen reader users and when clicking/focusing that label, it will automatically focus the associated input element.
HTML: The Living Standard
The input element represents a typed data field, usually with a form control to allow the user to edit the data.
The attribute controls the data type (and associated control) of the element. It is an enumerated attribute. The following table lists the keywords and states for the attribute — the keywords in the left column map to the states in the cell in the second column on the same row as the keyword.
Which of the accept , alt , autocomplete , checked , dirname , formaction , formenctype , formmethod , formnovalidate , formtarget , height , list , max , maxlength , min , minlength , multiple , pattern , placeholder , readonly , required , size , src , step , and width content attributes, the checked , files , valueAsDate , valueAsNumber , and list IDL attributes, the select() method, the selectionStart , selectionEnd , and selectionDirection , IDL attributes, the setRangeText() and setSelectionRange() methods, the stepUp() and stepDown() methods, and the input and change events to an input element depends on the state of its type attribute. The subsections that define each type also clearly define in normative «bookkeeping» sections which of these feature apply, and which , to each type. The behavior of these features depends on whether they apply or not, as defined in their various sections (q.v. for content attributes, for APIs, for events).
The following table summarizes which of those content attributes, IDL attributes, methods, and events apply to each state:
† If the control has no selectable text, the select() method results in a no-op, with no » InvalidStateError » DOMException .
The content attribute gives the default value of the input element.
Support in all current engines.
The content attribute is a boolean attribute that gives the default checkedness of the input element.
The name attribute represents the element’s name. The dirname attribute controls how the element’s directionality is submitted. The disabled attribute is used to make the control non-interactive and to prevent its value from being submitted. The form attribute is used to explicitly associate the input element with its form owner. The autocomplete attribute controls how the user agent provides autofill behavior.
4.10.5.1 States of the type attribute
4.10.5.1.1 state ( type=hidden )
Support in all current engines.
The input element represents a value that is not intended to be examined or manipulated by the user.
If the name attribute is present and has a value that is an ASCII case-insensitive match for » _charset_ «, then the element’s value attribute must be omitted.
The autocomplete content attribute applies to this element.
The value IDL attribute applies to this element and is in mode default .
4.10.5.1.2 ( type=text ) state and state ( type=search )
Support in all current engines.
Support in all current engines.
The input element represents a one line plain text edit control for the element’s value.
The difference between the Text state and the Search state is primarily stylistic: on platforms where search controls are distinguished from regular text controls, the Search state might result in an appearance consistent with the platform’s search controls rather than appearing like a regular text control.
The value attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , dirname , list , maxlength , minlength , pattern , placeholder , readonly , required , and size content attributes; list , selectionStart , selectionEnd , selectionDirection , and value IDL attributes; select() , setRangeText() , and setSelectionRange() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , valueAsDate , and valueAsNumber IDL attributes; stepDown() and stepUp() methods.
4.10.5.1.3 state ( type=tel )
Support in all current engines.
The input element represents a control for editing a telephone number given in the element’s value.
The value attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters.
Unlike the URL and Email types, the Telephone type does not enforce a particular syntax. This is intentional; in practice, telephone number fields tend to be free-form fields, because there are a wide variety of valid phone numbers. Systems that need to enforce a particular format are encouraged to use the pattern attribute or the setCustomValidity() method to hook into the client-side validation mechanism.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , maxlength , minlength , pattern , placeholder , readonly , required , and size content attributes; list , selectionStart , selectionEnd , selectionDirection , and value IDL attributes; select() , setRangeText() , and setSelectionRange() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , valueAsDate , and valueAsNumber IDL attributes; stepDown() and stepUp() methods.
4.10.5.1.4 state ( type=url )
Support in all current engines.
The input element represents a control for editing a single absolute URL given in the element’s value.
The value attribute, if specified and not empty, must have a value that is a valid URL potentially surrounded by spaces that is also an absolute URL.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , maxlength , minlength , pattern , placeholder , readonly , required , and size content attributes; list , selectionStart , selectionEnd , selectionDirection , and value IDL attributes; select() , setRangeText() , and setSelectionRange() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , valueAsDate , and valueAsNumber IDL attributes; stepDown() and stepUp() methods.
If a document contained the following markup:
. and the user had typed » spec.w «, and the user agent had also found that the user had visited https://url.spec.whatwg.org/#url-parsing and https://streams.spec.whatwg.org/ in the recent past, then the rendering might look like this:
The first four URLs in this sample consist of the four URLs in the author-specified list that match the text the user has entered, sorted in some implementation-defined manner (maybe by how frequently the user refers to those URLs). Note how the UA is using the knowledge that the values are URLs to allow the user to omit the scheme part and perform intelligent matching on the domain name.
The last two URLs (and probably many more, given the scrollbar’s indications of more values being available) are the matches from the user agent’s session history data. This data is not made available to the page DOM. In this particular case, the UA has no titles to provide for those values.
4.10.5.1.5 state ( type=email )
Support in all current engines.
How the Email state operates depends on whether the multiple attribute is specified or not.
When the multiple attribute is not specified on the element
The input element represents a control for editing an email address given in the element’s value.
The value attribute, if specified and not empty, must have a value that is a single valid email address.
When the multiple attribute is specified on the element
The input element represents a control for adding, removing, and editing the email addresses given in the element’s values.
The value attribute, if specified, must have a value that is a valid email address list.
When the multiple attribute is set or removed, the user agent must run the value sanitization algorithm .
A is a string that matches the email production of the following ABNF, the character set for which is Unicode. This ABNF implements the extensions described in RFC 1123. [ABNF] [RFC5322] [RFC1034] [RFC1123]
This requirement is a willful violation of RFC 5322, which defines a syntax for email addresses that is simultaneously too strict (before the «@» character), too vague (after the «@» character), and too lax (allowing comments, whitespace characters, and quoted strings in manners unfamiliar to most users) to be of practical use here.
The following JavaScript- and Perl-compatible regular expression is an implementation of the above definition.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , maxlength , minlength , multiple , pattern , placeholder , readonly , required , and size content attributes; list and value IDL attributes; select() method.
The value IDL attribute is in mode value .
4.10.5.1.6 state ( type=password )
Support in all current engines.
The input element represents a one line plain text edit control for the element’s value. The user agent should obscure the value so that people other than the user cannot see it.
The value attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , maxlength , minlength , pattern , placeholder , readonly , required , and size content attributes; selectionStart , selectionEnd , selectionDirection , and value IDL attributes; select() , setRangeText() , and setSelectionRange() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , list , valueAsDate , and valueAsNumber IDL attributes; stepDown() and stepUp() methods.
4.10.5.1.7 state ( type=date )
Support in all current engines.
The input element represents a control for setting the element’s value to a string representing a specific date.
See the introduction section for a discussion of the difference between the input format and submission format for date, time, and number form controls.
The value attribute, if specified and not empty, must have a value that is a valid date string.
The min attribute, if specified, must have a value that is a valid date string. The max attribute, if specified, must have a value that is a valid date string.
The step attribute is expressed in days. The default step is 1 day.
The Date state (and other date- and time-related states described in subsequent sections) is not intended for the entry of values for which a precise date and time relative to the contemporary calendar cannot be established. For example, it would be inappropriate for the entry of times like «one millisecond after the big bang», «the early part of the Jurassic period», or «a winter around 250 BCE».
For the input of dates before the introduction of the Gregorian calendar, authors are encouraged to not use the Date state (and the other date- and time-related states described in subsequent sections), as user agents are not required to support converting dates and times from earlier periods to the Gregorian calendar, and asking users to do so manually puts an undue burden on users. (This is complicated by the manner in which the Gregorian calendar was phased in, which occurred at different times in different countries, ranging from partway through the 16th century all the way to early in the 20th.) Instead, authors are encouraged to provide fine-grained input controls using the select element and input elements with the Number state.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , max , min , readonly , required , and step content attributes; list , value , valueAsDate , and valueAsNumber IDL attributes; select() , stepDown() , and stepUp() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , selectionStart , selectionEnd , and selectionDirection IDL attributes; setRangeText() , and setSelectionRange() methods.
4.10.5.1.8 state ( type=month )
Support in all current engines.
The input element represents a control for setting the element’s value to a string representing a specific month.
See the introduction section for a discussion of the difference between the input format and submission format for date, time, and number form controls.
The value attribute, if specified and not empty, must have a value that is a valid month string.
The min attribute, if specified, must have a value that is a valid month string. The max attribute, if specified, must have a value that is a valid month string.
The step attribute is expressed in months. The default step is 1 month.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , max , min , readonly , required , and step content attributes; list , value , valueAsDate , and valueAsNumber IDL attributes; select() , stepDown() , and stepUp() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , selectionStart , selectionEnd , and selectionDirection IDL attributes; setRangeText() , and setSelectionRange() methods.
4.10.5.1.9 state ( type=week )
The input element represents a control for setting the element’s value to a string representing a specific week.
See the introduction section for a discussion of the difference between the input format and submission format for date, time, and number form controls.
The value attribute, if specified and not empty, must have a value that is a valid week string.
The min attribute, if specified, must have a value that is a valid week string. The max attribute, if specified, must have a value that is a valid week string.
The step attribute is expressed in weeks. The default step is 1 week.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , max , min , readonly , required , and step content attributes; list , value , valueAsDate , and valueAsNumber IDL attributes; select() , stepDown() , and stepUp() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , selectionStart , selectionEnd , and selectionDirection IDL attributes; setRangeText() , and setSelectionRange() methods.
4.10.5.1.10 state ( type=time )
Support in all current engines.
The input element represents a control for setting the element’s value to a string representing a specific time.
See the introduction section for a discussion of the difference between the input format and submission format for date, time, and number form controls.
The value attribute, if specified and not empty, must have a value that is a valid time string.
The min attribute, if specified, must have a value that is a valid time string. The max attribute, if specified, must have a value that is a valid time string.
The step attribute is expressed in seconds. The default step is 60 seconds.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , max , min , readonly , required , and step content attributes; list , value , valueAsDate , and valueAsNumber IDL attributes; select() , stepDown() , and stepUp() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , selectionStart , selectionEnd , and selectionDirection IDL attributes; setRangeText() , and setSelectionRange() methods.
4.10.5.1.11 state ( type=datetime-local )
Support in all current engines.
The input element represents a control for setting the element’s value to a string representing a local date and time, with no time-zone offset information.
See the introduction section for a discussion of the difference between the input format and submission format for date, time, and number form controls.
The value attribute, if specified and not empty, must have a value that is a valid local date and time string.
The min attribute, if specified, must have a value that is a valid local date and time string. The max attribute, if specified, must have a value that is a valid local date and time string.
The step attribute is expressed in seconds. The default step is 60 seconds.
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , max , min , readonly , required , and step content attributes; list , value , and valueAsNumber IDL attributes; select() , stepDown() , and stepUp() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , selectionStart , selectionEnd , selectionDirection , and valueAsDate IDL attributes; setRangeText() , and setSelectionRange() methods.
The following example shows part of a flight booking application. The application uses an input element with its type attribute set to datetime-local , and it then interprets the given date and time in the time zone of the selected airport.
4.10.5.1.12 state ( type=number )
Support in all current engines.
The input element represents a control for setting the element’s value to a string representing a number.
This specification does not define what user interface user agents are to use; user agent vendors are encouraged to consider what would best serve their users’ needs. For example, a user agent in Persian or Arabic markets might support Persian and Arabic numeric input (converting it to the format required for submission as described above). Similarly, a user agent designed for Romans might display the value in Roman numerals rather than in decimal; or (more realistically) a user agent designed for the French market might display the value with apostrophes between thousands and commas before the decimals, and allow the user to enter a value in that manner, internally converting it to the submission format described above.
The value attribute, if specified and not empty, must have a value that is a valid floating-point number.
The min attribute, if specified, must have a value that is a valid floating-point number. The max attribute, if specified, must have a value that is a valid floating-point number.
The default step is 1 (allowing only integers to be selected by the user, unless the step base has a non-integer value).
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , max , min , placeholder , readonly , required , and step content attributes; list , value , and valueAsNumber IDL attributes; select() , stepDown() , and stepUp() methods.
The value IDL attribute is in mode value .
The following IDL attributes and methods do not apply to the element: checked , files , selectionStart , selectionEnd , selectionDirection , and valueAsDate IDL attributes; setRangeText() , and setSelectionRange() methods.
Here is an example of using a numeric input control:
As described above, a user agent might support numeric input in the user’s local format, converting it to the format required for submission as described above. This might include handling grouping separators (as in «872,000,000,000») and various decimal separators (such as «3,99» vs «3.99») or using local digits (such as those in Arabic, Devanagari, Persian, and Thai).
The type=number state is not appropriate for input that happens to only consist of numbers but isn’t strictly speaking a number. For example, it would be inappropriate for credit card numbers or US postal codes. A simple way of determining whether to use type=number is to consider whether it would make sense for the input control to have a spinbox interface (e.g. with «up» and «down» arrows). Getting a credit card number wrong by 1 in the last digit isn’t a minor mistake, it’s as wrong as getting every digit incorrect. So it would not make sense for the user to select a credit card number using «up» and «down» buttons. When a spinbox interface is not appropriate, type=text is probably the right choice (possibly with an inputmode or pattern attribute).
4.10.5.1.13 state ( type=range )
Support in all current engines.
The input element represents a control for setting the element’s value to a string representing a number, but with the caveat that the exact value is not important, letting UAs provide a simpler interface than they do for the Number state.
The value attribute, if specified, must have a value that is a valid floating-point number.
The is the minimum plus half the difference between the minimum and the maximum , unless the maximum is less than the minimum , in which case the default value is the minimum .
Here is an example of a range control using an autocomplete list with the list attribute. This could be useful if there are values along the full range of the control that are especially important, such as preconfigured light levels or typical speed limits in a range control used as a speed control. The following markup fragment:
. with the following style sheet applied:
. might render as:

Note how the UA determined the orientation of the control from the ratio of the style-sheet-specified height and width properties. The colors were similarly derived from the style sheet. The tick marks, however, were derived from the markup. In particular, the step attribute has not affected the placement of tick marks, the UA deciding to only use the author-specified completion values and then adding longer tick marks at the extremes.
Note also how the invalid value ++50 was ignored.
For another example, consider the following markup fragment:
A user agent could display in a variety of ways, for instance:

Or, alternatively, for instance:

The user agent could pick which one to display based on the dimensions given in the style sheet. This would allow it to maintain the same resolution for the tick marks, despite the differences in width.
Finally, here is an example of a range control with two labeled values:
With styles that make the control draw vertically, it might look as follows:

In this state, the range and step constraints are enforced even during user input, and there is no way to set the value to the empty string.
The min attribute, if specified, must have a value that is a valid floating-point number. The default minimum is 0. The max attribute, if specified, must have a value that is a valid floating-point number. The default maximum is 100.
The default step is 1 (allowing only integers, unless the min attribute has a non-integer value).
The following common input element content attributes, IDL attributes, and methods apply to the element: autocomplete , list , max , min , and step content attributes; list , value , and valueAsNumber IDL attributes; stepDown() and stepUp() methods.
The value IDL attribute is in mode value .
4.10.5.1.14 state ( type=color )
Support in all current engines.
The input element represents a color well control, for setting the element’s value to a string representing a simple color.
The value attribute, if specified and not empty, must have a value that is a valid simple color.
The following common input element content attributes and IDL attributes apply to the element: autocomplete and list content attributes; list and value IDL attributes; select() method.
The value IDL attribute is in mode value .
4.10.5.1.15 state ( type=checkbox )
Support in all current engines.
The input element represents a two-state control that represents the element’s checkedness state. If the element’s checkedness state is true, the control represents a positive selection, and if it is false, a negative selection. If the element’s indeterminate IDL attribute is set to true, then the control’s selection should be obscured as if the control was in a third, indeterminate, state.
The control is never a true tri-state control, even if the element’s indeterminate IDL attribute is set to true. The indeterminate IDL attribute only gives the appearance of a third state.
input . indeterminate [ = value ]
Support in all current engines.
When set, overrides the rendering of checkbox controls so that the current value is not visible.
The following common input element content attributes and IDL attributes apply to the element: checked , and required content attributes; checked and value IDL attributes.
The value IDL attribute is in mode default/on .
4.10.5.1.16 state ( type=radio )
Support in all current engines.
The input element represents a control that, when used in conjunction with other input elements, forms a radio button group in which only one control can have its checkedness state set to true. If the element’s checkedness state is true, the control represents the selected control in the group, and if it is false, it indicates a control in the group that is not selected.
The that contains an input element a also contains all the other input elements b that fulfill all of the following conditions:
- The input element b ‘s type attribute is in the Radio Button state.
- Either a and b have the same form owner, or they both have no form owner.
- Both a and b are in the same tree.
- They both have a name attribute, their name attributes are not empty, and the value of a ‘s name attribute equals the value of b ‘s name attribute.
A tree must not contain an input element whose radio button group contains only that element.
If none of the radio buttons in a radio button group are checked, then they will all be initially unchecked in the interface, until such time as one of them is checked (either by the user or by script).
The following common input element content attributes and IDL attributes apply to the element: checked and required content attributes; checked and value IDL attributes.
The value IDL attribute is in mode default/on .
4.10.5.1.17 state ( type=file )
Support in all current engines.
The input element represents a list of , each file consisting of a filename, a file type, and a file body (the contents of the file).
Support in all current engines.
Support in all current engines.
The attribute may be specified to provide user agents with a hint of what file types will be accepted.
If specified, the attribute must consist of a set of comma-separated tokens, each of which must be an ASCII case-insensitive match for one of the following:
The string » audio/* » Indicates that sound files are accepted. The string » video/* » Indicates that video files are accepted. The string » image/* » Indicates that image files are accepted. A valid MIME type string with no parameters Indicates that files of the specified type are accepted. A string whose first character is a U+002E FULL STOP character (.) Indicates that files with the specified file extension are accepted.
The tokens must not be ASCII case-insensitive matches for any of the other tokens (i.e. duplicates are not allowed).
User agents may use the value of this attribute to display a more appropriate user interface than a generic file picker. For instance, given the value image/* , a user agent could offer the user the option of using a local camera or selecting a photograph from their photo collection; given the value audio/* , a user agent could offer the user the option of recording a clip using a headset microphone.
Authors are encouraged to specify both any MIME types and any corresponding extensions when looking for data in a specific format.
For example, consider an application that converts Microsoft Word documents to Open Document Format files. Since Microsoft Word documents are described with a wide variety of MIME types and extensions, the site can list several, as follows:
On platforms that only use file extensions to describe file types, the extensions listed here can be used to filter the allowed documents, while the MIME types can be used with the system’s type registration table (mapping MIME types to extensions used by the system), if any, to determine any other extensions to allow. Similarly, on a system that does not have filenames or extensions but labels documents with MIME types internally, the MIME types can be used to pick the allowed files, while the extensions can be used if the system has an extension registration table that maps known extensions to MIME types used by the system.
Extensions tend to be ambiguous (e.g. there are an untold number of formats that use the » .dat » extension, and users can typically quite easily rename their files to have a » .doc » extension even if they are not Microsoft Word documents), and MIME types tend to be unreliable (e.g. many formats have no formally registered types, and many formats are in practice labeled using a number of different MIME types). Authors are reminded that, as usual, data received from a client should be treated with caution, as it may not be in an expected format even if the user is not hostile and the user agent fully obeyed the accept attribute’s requirements.
For historical reasons, the value IDL attribute prefixes the filename with the string » C:\fakepath\ «. Some legacy user agents actually included the full path (which was a security vulnerability). As a result of this, obtaining the filename from the value IDL attribute in a backwards-compatible way is non-trivial. The following function extracts the filename in a suitably compatible manner:
This can be used as follows:
The following common input element content attributes and IDL attributes apply to the element: accept , multiple , and required content attributes; files and value IDL attributes; select() method.
The value IDL attribute is in mode filename .
The element’s value attribute must be omitted.
4.10.5.1.18 state ( type=submit )
Support in all current engines.
The input element represents a button that, when activated, submits the form. The element is a button, specifically a submit button.
Since the default label is implementation-defined, and the width of the button typically depends on the button’s label, the button’s width can leak a few bits of fingerprintable information. These bits are likely to be strongly correlated to the identity of the user agent and the user’s locale.
The formnovalidate attribute can be used to make submit buttons that do not trigger the constraint validation.
The following common input element content attributes and IDL attributes apply to the element: formaction , formenctype , formmethod , formnovalidate , formtarget , popovertarget , and popovertargetaction content attributes; value IDL attribute.
The value IDL attribute is in mode default .
The following content attributes must not be specified and do not apply to the element: accept , alt , autocomplete , checked , dirname , height , list , max , maxlength , min , minlength , multiple , pattern , placeholder , readonly , required , size , src , step , and width .
4.10.5.1.19 state ( type=image )
Support in all current engines.
The input element represents either an image from which a user can select a coordinate and submit the form, or alternatively a button from which the user can submit the form. The element is a button, specifically a submit button.
The coordinate is sent to the server during form submission by sending two entries for the element, derived from the name of the control but with » .x » and » .y » appended to the name with the x and y components of the coordinate respectively.
Support in all current engines.
The image is given by the attribute. The src attribute must be present, and must contain a valid non-empty URL potentially surrounded by spaces referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted.
Support in all current engines.
The attribute provides the textual label for the button for users and user agents who cannot use the image. The alt attribute must be present, and must contain a non-empty string giving the label that would be appropriate for an equivalent button if the image was unavailable.
If the src attribute is set, and the image is available and the user agent is configured to display that image, then the element represents a control for selecting a coordinate from the image specified by the src attribute. In that case, if the element is mutable, the user agent should allow the user to select this coordinate .
Otherwise, the element represents a submit button whose label is given by the value of the alt attribute.
image . width [ = value ] image . height [ = value ]
These attributes return the actual rendered dimensions of the image, or zero if the dimensions are not known.
They can be set, to change the corresponding content attributes.
The following common input element content attributes and IDL attributes apply to the element: alt , formaction , formenctype , formmethod , formnovalidate , formtarget , height , popovertarget , popovertargetaction , src , and width content attributes; value IDL attribute.
The value IDL attribute is in mode default .
The following content attributes must not be specified and do not apply to the element: accept , autocomplete , checked , dirname , list , max , maxlength , min , minlength , multiple , pattern , placeholder , readonly , required , size , and step .
The element’s value attribute must be omitted.
Many aspects of this state’s behavior are similar to the behavior of the img element. Readers are encouraged to read that section, where many of the same requirements are described in more detail.
Take the following form:
If the user clicked on the image at coordinate (127,40) then the URL used to submit the form would be » process.cgi?where.x=127&where.y=40 «.
(In this example, it’s assumed that for users who don’t see the map, and who instead just see a button labeled «Show location list», clicking the button will cause the server to show a list of locations to pick from instead of the map.)
4.10.5.1.20 state ( type=reset )
Support in all current engines.
The input element represents a button that, when activated, resets the form. The element is a button.
Since the default label is implementation-defined, and the width of the button typically depends on the button’s label, the button’s width can leak a few bits of fingerprintable information. These bits are likely to be strongly correlated to the identity of the user agent and the user’s locale.
The value IDL attribute applies to this element and is in mode default .
The following common input element content attributes apply to the element: popovertarget and popovertargetaction .
4.10.5.1.21 state ( type=button )
Support in all current engines.
The input element represents a button with no default behavior. A label for the button must be provided in the value attribute, though it may be the empty string. The element is a button.
The value IDL attribute applies to this element and is in mode default .
The following common input element content attributes apply to the element: popovertarget and popovertargetaction .
4.10.5.2 Common input element attributes
4.10.5.2.1 The maxlength and minlength attributes
Support in all current engines.
Support in all current engines.
Support in all current engines.
Support in all current engines.
Support in all current engines.
Support in all current engines.
If the input element has a maximum allowed value length, then the length of the value of the element’s value attribute must be equal to or less than the element’s maximum allowed value length.
The following extract shows how a messaging client’s text entry could be arbitrarily restricted to a fixed number of characters, thus forcing any conversation through this medium to be terse and discouraging intelligent discourse.
Here, a password is given a minimum length:
4.10.5.2.2 The size attribute
The attribute gives the number of characters that, in a visual rendering, the user agent is to allow the user to see while editing the element’s value.
The size attribute, if specified, must have a value that is a valid non-negative integer greater than zero.
4.10.5.2.3 The readonly attribute
Support in all current engines.
Support in all current engines.
Support in all current engines.
The attribute is a boolean attribute that controls whether or not the user can edit the form control.
The difference between disabled and readonly is that read-only controls can still function, whereas disabled controls generally do not function as controls until they are enabled. This is spelled out in more detail elsewhere in this specification with normative requirements that refer to the disabled concept (for example, the element’s activation behavior, whether or not it is a focusable area, or when constructing the entry list ). Any other behavior related to user interaction with disabled controls, such as whether text can be selected or copied, is not defined in this standard.
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.
In the following example, the existing product identifiers cannot be modified, but they are still displayed as part of the form, for consistency with the row representing a new product (where the identifier is not yet filled in).
4.10.5.2.4 The required attribute
The attribute is a boolean attribute. When specified, the element is .
The following form has two required fields, one for an email address and one for a password. It also has a third field that is only considered valid if the user types the same password in the password field and this third field.
For radio buttons, the required attribute is satisfied if any of the radio buttons in the group is selected. Thus, in the following example, any of the radio buttons can be checked, not just the one marked as required:
To avoid confusion as to whether a radio button group is required or not, authors are encouraged to specify the attribute on all the radio buttons in a group. Indeed, in general, authors are encouraged to avoid having radio button groups that do not have any initially checked controls in the first place, as this is a state that the user cannot return to, and is therefore generally considered a poor user interface.
4.10.5.2.5 The multiple attribute
Support in all current engines.
Support in all current engines.
The attribute is a boolean attribute that indicates whether the user is to be allowed to specify more than one value.
The following extract shows how an email client’s «To» field could accept multiple email addresses.
If the user had, amongst many friends in their user contacts database, two friends «Spider-Man» (with address «spider@parker.example.net») and «Scarlet Witch» (with address «scarlet@avengers.example.net»), then, after the user has typed » s «, the user agent might suggest these two email addresses to the user.
The page could also link in the user’s contacts database from the site:
Suppose the user had entered » bob@example.net » into this text control, and then started typing a second email address starting with » s «. The user agent might show both the two friends mentioned earlier, as well as the «astrophy» and «astronomy» values given in the datalist element.
The following extract shows how an email client’s «Attachments» field could accept multiple files for upload.
4.10.5.2.6 The pattern attribute
Support in all current engines.
Support in all current engines.
The attribute specifies a regular expression against which the control’s value, or, when the multiple attribute applies and is set, the control’s values, are to be checked.
If specified, the attribute’s value must match the JavaScript Pattern [+UnicodeSetsMode, +N] production. [JSREGEXPVFLAG]
When an input element has a pattern attribute specified, authors should include a attribute to give a description of the pattern. User agents may use the contents of this attribute, if it is present, when informing the user that the pattern is not matched, or at any other suitable time, such as in a tooltip or read out by assistive technology when the control gains focus.
For example, the following snippet:
. could cause the UA to display an alert such as:
When a control has a pattern attribute, the title attribute, if used, must describe the pattern. Additional information could also be included, so long as it assists the user in filling in the control. Otherwise, assistive technology would be impaired.
For instance, if the title attribute contained the caption of the control, assistive technology could end up saying something like The text you have entered does not match the required pattern. Birthday , which is not useful.
UAs may still show the title in non-error situations (for example, as a tooltip when hovering over the control), so authors should be careful not to word title s as if an error has necessarily occurred.
4.10.5.2.7 The min and max attributes
Support in all current engines.
Support in all current engines.
Some form controls can have explicit constraints applied limiting the allowed range of values that the user can provide. Normally, such a range would be linear and continuous. A form control can , however, in which case the form control’s broadest possible range is finite, and authors can specify explicit ranges within it that span the boundaries.
Specifically, the broadest range of a type=time control is midnight to midnight (24 hours), and authors can set both continuous linear ranges (such as 9pm to 11pm) and discontinuous ranges spanning midnight (such as 11pm to 1am).
The and attributes indicate the allowed range of values for the element.
If the element does not have a periodic domain, the max attribute’s value (the maximum ) must not be less than the min attribute’s value (its minimum ).
An element if it has a defined minimum or a defined maximum .
The following date control limits input to dates that are before the 1980s:
The following number control limits input to whole numbers greater than zero:
The following time control limits input to those minutes that occur between 9pm and 6am, defaulting to midnight:
4.10.5.2.8 The step attribute
Support in all current engines.
The attribute indicates the granularity that is expected (and required) of the value or values, by limiting the allowed values.
The step attribute, if specified, must either have a value that is a valid floating-point number that parses to a number that is greater than zero, or must have a value that is an ASCII case-insensitive match for the string » any «.
The following range control only accepts values in the range 0..1, and allows 256 steps in that range:
The following control allows any time in the day to be selected, with any accuracy (e.g. thousandth-of-a-second accuracy or more):
Normally, time controls are limited to an accuracy of one minute.
4.10.5.2.9 The list attribute
Support in all current engines.
The attribute is used to identify an element that lists predefined options suggested to the user.
If present, its value must be the ID of a datalist element in the same tree.
This URL field offers some suggestions.
Other URLs from the user’s history might show also; this is up to the user agent.
This example demonstrates how to design a form that uses the autocompletion list feature while still degrading usefully in legacy user agents.
If the autocompletion list is merely an aid, and is not important to the content, then simply using a datalist element with children option elements is enough. To prevent the values from being rendered in legacy user agents, they need to be placed inside the value attribute instead of inline.
However, if the values need to be shown in legacy UAs, then fallback content can be placed inside the datalist element, as follows:
The fallback content will only be shown in UAs that don’t support datalist . The options, on the other hand, will be detected by all UAs, even though they are not children of the datalist element.
Note that if an option element used in a datalist is selected , it will be selected by default by legacy UAs (because it affects the select element), but it will not have any effect on the input element in UAs that support datalist .
4.10.5.2.10 The placeholder attribute
Support in all current engines.
Support in all current engines.
The attribute represents a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format. The attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters.
The placeholder attribute should not be used as an alternative to a label . For a longer hint or other advisory text, the title attribute is more appropriate.
These mechanisms are very similar but subtly different: the hint given by the control’s label is shown at all times; the short hint given in the placeholder attribute is shown before the user enters a value; and the hint in the title attribute is shown when the user requests further help.
Here is an example of a mail configuration user interface that uses the placeholder attribute:
In situations where the control’s content has one directionality but the placeholder needs to have a different directionality, Unicode’s bidirectional-algorithm formatting characters can be used in the attribute value:
For slightly more clarity, here’s the same example using numeric character references instead of inline Arabic:
4.10.5.3 Common input element APIs
Returns the current value of the form control.
Can be set, to change the value.
Throws an » InvalidStateError » DOMException if it is set to any value other than the empty string when the control is a file upload control.
input . checked [ = value ]
Returns the current checkedness of the form control.
Can be set, to change the checkedness.
input . files [ = files ]
Returns a FileList object listing the selected files of the form control.
Returns null if the control isn’t a file control.
Can be set to a FileList object to change the selected files of the form control. For instance, as the result of a drag-and-drop operation.
input . valueAsDate [ = value ]
Returns a Date object representing the form control’s value, if applicable; otherwise, returns null.
Can be set, to change the value.
Throws an » InvalidStateError » DOMException if the control isn’t date- or time-based.
input . valueAsNumber [ = value ]
Returns a number representing the form control’s value, if applicable; otherwise, returns NaN.
Can be set, to change the value. Setting this to NaN will set the underlying value to the empty string.
Throws an » InvalidStateError » DOMException if the control is neither date- or time-based nor numeric.
input . stepUp ([ n ]) input . stepDown ([ n ])
Changes the form control’s value by the value given in the step attribute, multiplied by n . The default value for n is 1.
Throws » InvalidStateError » DOMException if the control is neither date- or time-based nor numeric, or if the step attribute’s value is » any «.
Returns the datalist element indicated by the list attribute. input . showPicker ()
Support in all current engines.
Shows any applicable picker UI for input , so that the user can select a value. (If no picker UI is implemented for the given control, then this method does nothing.)
Throws a » NotAllowedError » DOMException if called without transient user activation .
Throws a » SecurityError » DOMException if input is inside a cross-origin iframe , unless input is in the File Upload or Color states.
::placeholder
Псевдоэлемент ::placeholder используется для стилизации текста-плейсхолдера в полях ввода <input> и <textarea> .
Пример
Как это понять
Элементам <input> и <textarea> можно задавать атрибут placeholder . Текст, содержащийся в этом атрибуте, будет отображаться внутри поля ввода, пока пользователь ничего не ввёл. Этот текст можно стилизовать, используя псевдоэлемент ::placeholder . Стили для введённого текста и текста-плейсхолдера в общем случае должны различаться.
Как пишется
Стиль применится ко всем плейсхолдерам на странице.
Стиль применится только к плейсхолдерам на полях ввода атрибут class которых равен email-input .
Подсказки
Для стилизации плейсхолдера можно использовать только следующие свойства:
- все шрифтовые свойства, начинающиеся с font (например, font-size или font-style );
- все свойства для работы с фоном, начинающиеся с background- (например, background-color или background-size );
- свойство color ;
- свойства word-spacing , letter-spacing , text-decoration , text-transform и line-height ;
- cвойства text-shadow , группу свойств text-decoration и vertical-align .
В работе
Плейсхолдер не должен выступать как замена тегу <label> . Основное назначение плейсхолдера — дать подсказку к правильному заполнению поля. Дизайнеры зачастую любят экономить место в формах и не рисуют лейблы у полей, заменяя их плейсхолдерами. Это не лучшая практика, поэтому, если вам попадётся такой макет, обговорите с дизайнером возможность изменения макета в лучшую сторону, добавив лейблы.
Желательно стилизовать плейсхолдер таким образом, чтобы визуально он отличался от введённого текста. Как правило плейсхолдер делают полупрозрачным, либо просто светлее вводимого текста.
CSS ::placeholder Pseudo Element
The ::placeholder pseudo-class is used to style the placeholder text of a form element. The ::placeholder pseudo-element selects <form> elements with placeholder text in an <input> field. By default, the appearance of placeholder text is a semi-transparent or light gray color in most browsers.

The placeholder text is set with the placeholder attribute, which specifies a hint that describes the expected value of an input field.