165
▪The following commoninputp434
element content attributes, IDL attributes, and methodsapplyp437
to the element:autocompletep516
,listp469
,maxp467
,minp467
,
readonlyp464
,requiredp464
, andstepp468
content attributes;listp475
,valuep472
,valueAsDatep473
, andvalueAsNumberp473
IDL attributes;select()p529
,
stepDown()p474
, andstepUp()p474
methods.
▪Thevaluep472
IDL attribute is in modevaluep473
.
▪Theinputp1154
andchangep1154
eventsapplyp437
.
▪The following content attributes must not be specified anddo not applyp437
to the element:acceptp457
,altp460
,checkedp439
,dirnamep510
,formactionp512
,
formenctypep513
,formmethodp512
,formnovalidatep513
,formtargetp513
,heightp393
,inputmodep515
,maxlengthp463
,minlengthp463
,multiplep465
,patternp466
,
placeholderp471
,sizep463
,srcp460
, andwidthp393
.
▪The following IDL attributes and methodsdo not applyp437
to the element:checkedp473
,filesp473
,selectionStartp529
,selectionEndp530
,selectionDirectionp530
,
valueLowp474
, andvalueHighp474
IDL attributes;setRangeText()p530
, andsetSelectionRange()p530
methods.
4.10.5.1.9Weekstate (type=week)
When aninputp434
element'stypep436
attribute is in theWeekp447
state, the rules in this section apply.
Theinputp434
elementrepresentsp112
a control for setting the element'svaluep508
to a string representing a specificweekp78
.
If the element ismutablep508
, the user agent should allow the user to change theweekp78
represented by itsvaluep508
, as obtained byparsing a
weekp78
from it. User agents must not allow the user to set thevaluep508
to a non-empty string that is not avalid week stringp78
. If the user agent
provides a user interface for selecting aweekp78
, then thevaluep508
must be set to avalid week stringp78
representing the user's selection. User
agents should allow the user to set thevaluep508
to the empty string.
Constraint validation: While the user interface describes input that the user agent cannot convert to avalid week stringp78
, the control issuffering
from bad inputp532
.
Thevaluep438
attribute, if specified and not empty, must have a value that is avalid week stringp78
.
Thevalue sanitization algorithmp438
is as follows: If thevaluep508
of the element is not avalid week stringp78
, then set it to the empty string
instead.
Theminp467
attribute, if specified, must have a value that is avalid week stringp78
. Themaxp467
attribute, if specified, must have a value that is a
valid week stringp78
.
Thestepp468
attribute is expressed in weeks. Thestep scale factorp468
is 604,800,000 (which converts the weeks to milliseconds, as used in the
other algorithms). Thedefault stepp468
is 1 week. Thedefault step basep468
is −259,200,000 (the start of week 1970-W01).
When the element issuffering from a step mismatchp532
, the user agent may round the element'svaluep508
to the nearestweekp78
for which the
element would notsuffer from a step mismatchp532
.
Thealgorithm to convert a string to a numberp438
, given a stringinput, is as follows: Ifparsing a week stringp78
frominputresults in an error,
then return an error; otherwise, return the number of milliseconds elapsed from midnight UTC on the morning of 1970-01-01 (the time represented
by the value "1970-01-01T00:00:00.0Z") to midnight UTC on the morning of the Monday of the parsedweekp78
, ignoring leap seconds.
Thealgorithm to convert a number to a stringp438
, given a numberinput, is as follows: Return avalid week stringp78
that represents the
weekp78
that, in UTC, is currentinputmilliseconds after midnight UTC on the morning of 1970-01-01 (the time represented by the value
"1970-01-01T00:00:00.0Z").
Thealgorithm to convert a string to aDateobjectp438
, given a stringinput, is as follows: Ifparsing a weekp78
frominputresults in an error,
then return an error; otherwise, returna newDateobjectp51
representing midnight UTC on the morning of the Monday of the parsedweekp78
.
Thealgorithm to convert aDateobject to a stringp438
, given aDate
objectinput, is as follows: Return avalid week stringp78
that represents
theweekp78
current at the time represented byinputin the UTC time zone.
Bookkeeping details
▪The following commoninputp434
element content attributes, IDL attributes, and methodsapplyp437
to the element:autocompletep516
,listp469
,maxp467
,minp467
,
readonlyp464
,requiredp464
, andstepp468
content attributes;listp475
,valuep472
,valueAsDatep473
, andvalueAsNumberp473
IDL attributes;select()p529
,
stepDown()p474
, andstepUp()p474
methods.
See theintroduction sectionp428
for a discussion of the difference between the input format and submission format for date, time, and
number form controls, and theimplementation notesp463
regarding localization of form controls.
Note
447
151
▪Thevaluep472
IDL attribute is in modevaluep473
.
▪Theinputp1154
andchangep1154
eventsapplyp437
.
▪The following content attributes must not be specified anddo not applyp437
to the element:acceptp457
,altp460
,checkedp439
,dirnamep510
,formactionp512
,
formenctypep513
,formmethodp512
,formnovalidatep513
,formtargetp513
,heightp393
,inputmodep515
,maxlengthp463
,minlengthp463
,multiplep465
,patternp466
,
placeholderp471
,sizep463
,srcp460
, andwidthp393
.
▪The following IDL attributes and methodsdo not applyp437
to the element:checkedp473
,filesp473
,selectionStartp529
,selectionEndp530
,selectionDirectionp530
,
valueLowp474
, andvalueHighp474
IDL attributes;setRangeText()p530
, andsetSelectionRange()p530
methods.
4.10.5.1.10Timestate (type=time)
When aninputp434
element'stypep436
attribute is in theTimep448
state, the rules in this section apply.
Theinputp434
elementrepresentsp112
a control for setting the element'svaluep508
to a string representing a specifictimep73
.
If the element ismutablep508
, the user agent should allow the user to change thetimep73
represented by itsvaluep508
, as obtained byparsing a
timep74
from it. User agents must not allow the user to set thevaluep508
to a non-empty string that is not avalid time stringp73
. If the user agent
provides a user interface for selecting atimep73
, then thevaluep508
must be set to avalid time stringp73
representing the user's selection. User
agents should allow the user to set thevaluep508
to the empty string.
Constraint validation: While the user interface describes input that the user agent cannot convert to avalid time stringp73
, the control issuffering
from bad inputp532
.
Thevaluep438
attribute, if specified and not empty, must have a value that is avalid time stringp73
.
Thevalue sanitization algorithmp438
is as follows: If thevaluep508
of the element is not avalid time stringp73
, then set it to the empty string
instead.
The form controlhas a periodic domainp467
.
Theminp467
attribute, if specified, must have a value that is avalid time stringp73
. Themaxp467
attribute, if specified, must have a value that is avalid
time stringp73
.
Thestepp468
attribute is expressed in seconds. Thestep scale factorp468
is 1000 (which converts the seconds to milliseconds, as used in the other
algorithms). Thedefault stepp468
is 60 seconds.
When the element issuffering from a step mismatchp532
, the user agent may round the element'svaluep508
to the nearesttimep73
for which the
element would notsuffer from a step mismatchp532
.
Thealgorithm to convert a string to a numberp438
, given a stringinput, is as follows: Ifparsing a timep74
frominputresults in an error, then
return an error; otherwise, return the number of milliseconds elapsed from midnight to the parsedtimep73
on a day with no time changes.
Thealgorithm to convert a number to a stringp438
, given a numberinput, is as follows: Return avalid time stringp73
that represents thetimep73
that isinputmilliseconds after midnight on a day with no time changes.
Thealgorithm to convert a string to aDateobjectp438
, given a stringinput, is as follows: Ifparsing a timep74
frominputresults in an error,
then return an error; otherwise, returna newDateobjectp51
representing the parsedtimep73
in UTC on 1970-01-01.
Thealgorithm to convert aDateobject to a stringp438
, given aDate
objectinput, is as follows: Return avalid time stringp73
that represents
the UTCtimep73
component that is represented byinput.
Bookkeeping details
▪The following commoninputp434
element content attributes, IDL attributes, and methodsapplyp437
to the element:autocompletep516
,listp469
,maxp467
,minp467
,
readonlyp464
,requiredp464
, andstepp468
content attributes;listp475
,valuep472
,valueAsDatep473
, andvalueAsNumberp473
IDL attributes;select()p529
,
stepDown()p474
, andstepUp()p474
methods.
▪Thevaluep472
IDL attribute is in modevaluep473
.
▪Theinputp1154
andchangep1154
eventsapplyp437
.
See theintroduction sectionp428
for a discussion of the difference between the input format and submission format for date, time, and
number form controls, and theimplementation notesp463
regarding localization of form controls.
Note
448
173
▪The following content attributes must not be specified anddo not applyp437
to the element:acceptp457
,altp460
,checkedp439
,dirnamep510
,formactionp512
,
formenctypep513
,formmethodp512
,formnovalidatep513
,formtargetp513
,heightp393
,inputmodep515
,maxlengthp463
,minlengthp463
,multiplep465
,patternp466
,
placeholderp471
,sizep463
,srcp460
, andwidthp393
.
▪The following IDL attributes and methodsdo not applyp437
to the element:checkedp473
,filesp473
,selectionStartp529
,selectionEndp530
,selectionDirectionp530
,
valueLowp474
, andvalueHighp474
IDL attributes;setRangeText()p530
, andsetSelectionRange()p530
methods.
4.10.5.1.11Local Date and Timestate (type=datetime-local)
When aninputp434
element'stypep436
attribute is in theLocal Date and Timep449
state, the rules in this section apply.
Theinputp434
elementrepresentsp112
a control for setting the element'svaluep508
to a string representing alocal date and timep74
, with no time-
zone offset information.
If the element ismutablep508
, the user agent should allow the user to change thedate and timep74
represented by itsvaluep508
, as obtained by
parsing a date and timep75
from it. User agents must not allow the user to set thevaluep508
to a non-empty string that is not avalid normalised local
date and time stringp75
. If the user agent provides a user interface for selecting alocal date and timep74
, then thevaluep508
must be set to avalid
normalised local date and time stringp75
representing the user's selection. User agents should allow the user to set thevaluep508
to the empty string.
Constraint validation: While the user interface describes input that the user agent cannot convert to avalid normalised local date and time
stringp75
, the control issuffering from bad inputp532
.
Thevaluep438
attribute, if specified and not empty, must have a value that is avalid local date and time stringp74
.
Thevalue sanitization algorithmp438
is as follows: If thevaluep508
of the element is avalid local date and time stringp74
, then set it to avalid
normalised local date and time stringp75
representing the same date and time; otherwise, set it to the empty string instead.
Theminp467
attribute, if specified, must have a value that is avalid local date and time stringp74
. Themaxp467
attribute, if specified, must have a
value that is avalid local date and time stringp74
.
Thestepp468
attribute is expressed in seconds. Thestep scale factorp468
is 1000 (which converts the seconds to milliseconds, as used in the other
algorithms). Thedefault stepp468
is 60 seconds.
When the element issuffering from a step mismatchp532
, the user agent may round the element'svaluep508
to the nearestlocal date and timep74
for
which the element would notsuffer from a step mismatchp532
.
Thealgorithm to convert a string to a numberp438
, given a stringinput, is as follows: Ifparsing a date and timep75
frominputresults in an
error, then return an error; otherwise, return the number of milliseconds elapsed from midnight on the morning of 1970-01-01 (the time represented
by the value "1970-01-01T00:00:00.0") to the parsedlocal date and timep74
, ignoring leap seconds.
Thealgorithm to convert a number to a stringp438
, given a numberinput, is as follows: Return avalid normalised local date and time stringp75
that represents the date and time that isinputmilliseconds after midnight on the morning of 1970-01-01 (the time represented by the value
"1970-01-01T00:00:00.0").
Bookkeeping details
▪The following commoninputp434
element content attributes, IDL attributes, and methodsapplyp437
to the element:autocompletep516
,listp469
,maxp467
,minp467
,
readonlyp464
,requiredp464
, andstepp468
content attributes;listp475
,valuep472
, andvalueAsNumberp473
IDL attributes;select()p529
,stepDown()p474
, and
stepUp()p474
methods.
▪Thevaluep472
IDL attribute is in modevaluep473
.
▪Theinputp1154
andchangep1154
eventsapplyp437
.
▪The following content attributes must not be specified anddo not applyp437
to the element:acceptp457
,altp460
,checkedp439
,dirnamep510
,formactionp512
,
formenctypep513
,formmethodp512
,formnovalidatep513
,formtargetp513
,heightp393
,inputmodep515
,maxlengthp463
,minlengthp463
,multiplep465
,patternp466
,
placeholderp471
,sizep463
,srcp460
, andwidthp393
.
▪The following IDL attributes and methodsdo not applyp437
to the element:checkedp473
,filesp473
,selectionStartp529
,selectionEndp530
,selectionDirectionp530
,
valueAsDatep473
,valueLowp474
, andvalueHighp474
IDL attributes;setRangeText()p530
, andsetSelectionRange()p530
methods.
See theintroduction sectionp428
for a discussion of the difference between the input format and submission format for date, time, and
number form controls, and theimplementation notesp463
regarding localization of form controls.
Note
Seethe note on historical datesp445
in theDatep445
state section.
Note
Example
449
112
4.10.5.1.12Numberstate (type=number)
When aninputp434
element'stypep436
attribute is in theNumberp450
state, the rules in this section apply.
Theinputp434
elementrepresentsp112
a control for setting the element'svaluep508
to a string representing a number.
If the element ismutablep508
, the user agent should allow the user to change the number represented by itsvaluep508
, as obtained from applying the
rules for parsing floating-point number valuesp67
to it. User agents must not allow the user to set thevaluep508
to a non-empty string that is not a
valid floating-point numberp67
. If the user agent provides a user interface for selecting a number, then thevaluep508
must be set to thebest
representation of the number representing the user's selection as a floating-point numberp67
. User agents should allow the user to set thevaluep508
to the empty string.
Constraint validation: While the user interface describes input that the user agent cannot convert to avalid floating-point numberp67
, the control is
suffering from bad inputp532
.
Thevaluep438
attribute, if specified and not empty, must have a value that is avalid floating-point numberp67
.
Thevalue sanitization algorithmp438
is as follows: If thevaluep508
of the element is not avalid floating-point numberp67
, then set it to the empty
string instead.
Theminp467
attribute, if specified, must have a value that is avalid floating-point numberp67
. Themaxp467
attribute, if specified, must have a value
that is avalid floating-point numberp67
.
Thestep scale factorp468
is 1. Thedefault stepp468
is 1 (allowing only integers to be selected by the user, unless thestep basep468
has a non-integer
value).
When the element issuffering from a step mismatchp532
, the user agent may round the element'svaluep508
to the nearest number for which the
element would notsuffer from a step mismatchp532
. If there are two such numbers, user agents are encouraged to pick the one nearest positive
infinity.
Thealgorithm to convert a string to a numberp438
, given a stringinput, is as follows: If applying therules for parsing floating-point number
valuesp67
toinputresults in an error, then return an error; otherwise, return the resulting number.
Thealgorithm to convert a number to a stringp438
, given a numberinput, is as follows: Return avalid floating-point numberp67
that represents
input.
Bookkeeping details
The following example shows part of a flight booking application. The application uses aninputp434
element with itstypep436
attribute
set todatetime-localp449
, and it then interprets the given date and time in the time zone of the selected airport.
<fieldset>
<legend>Destination</legend>
<p><label>Airport: <input type=text name=to list=airports></label></p>
<p><label>Departure time: <input type=datetime-local name=totime step=3600></label></p>
</fieldset>
<datalist id=airports>
<option value=ATL label="Atlanta">
<option value=MEM label="Memphis">
<option value=LHR label="London Heathrow">
<option value=LAX label="Los Angeles">
<option value=FRA label="Frankfurt">
</datalist>
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.
Note
Support:
Chrome
6+
Chrome for Android
(limited)
50+
UC Browser for Android
(limited)
9.9+
iOS Safari(limited)
3.2+
Firefox
29+
IE(limited)
10+
Opera Mini
None
Android Browser(limited) 4+
Edge(limited)
12+
Safari
5+
Opera
9+
IE Mobile(limited)
10+
Source:caniuse.com
⋰
450
Documents you may be interested
Documents you may be interested