The HTML <input type="date">
element is a specific version of the <input>
element used to create an input field accepting a date.
Browsers generate a control for entering, and changing, the date. This date includes a year, month and day. The control itself varies from one browser to another; browsers not supporting this type will display a simple text control.
Content categories | Flow content, listed, submittable, resettable, form-associated element, phrasing content, labellable element, palpable content. |
---|---|
Permitted content | None, it is an empty element. |
Tag omission | Must have a start tag and must not have an end tag. |
Permitted parent elements | Any element that accepts phrasing content. |
DOM interface | HTMLInputElement |
Attributes
Beside the attributes listed below, this element can have any of the global attributes.
mozactionhint
- 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
, andsend
; these automatically get mapped to the appropriate string (and are case-insensitive). autofocus
- This Boolean attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it, for example 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). 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. form
- The form element that the input element is associated with (its form owner). The value of the attribute must be an id of a
<form>
element in the same document. If this attribute is not specified, this<input>
element must be a descendant of a<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. formaction
- 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
action
attribute of the element's form owner. formenctype
- 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 thetype
attribute set tofile
.text/plain
If this attribute is specified, it overrides the
enctype
attribute of the element's form owner. formmethod
- 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
method
attribute of the element's form owner. formnovalidate
- 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
novalidate
attribute of the element's form owner. formtarget
- 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 (for example, tab, window, or inline frame). If this attribute is specified, it overrides the
target
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 (that is, 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
.
- _
inputmode
- 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 for 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.
list
- Identifies a list of pre-defined options to suggest to the user. The value must be the id of a
<datalist>
element in the same document. The browser displays only options that are valid values for this input element. max
- The maximum value for this item, which must not be less than its minimum (min attribute) value.
min
- The minimum value for this item, which must not be greater than its maximum (max attribute) value.
name
- The name of the control, which is submitted with the form data.
readonly
- This Boolean attribute indicates that the user cannot modify the value of the control.
required
- 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
, orbutton
). The:optional
and:required
CSS pseudo-classes will be applied to the field as appropriate. selectionDirection
- 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. This can be "none" if the selection direction is unknown.
spellcheck
- Setting the value of this attribute to
true
indicates that the element needs to have its spelling and grammar checked. The valuedefault
indicates that the element is to act according to a default behavior, possibly based on the parent element's ownspellcheck
value. The valuefalse
indicates that the element should not be checked. step
- 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 toany
, the control accepts only values at multiples of the step value greater than the minimum. value
- The initial value of the control. This attribute is optional.
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. x-moz-errormessage
- This Mozilla extension allows you to specify the error message to display when a field doesn't successfully validate.
Examples
To create a widget to display a date, use:
<input type="date">
Fix me: Insert Browser Compatibility and specification tables here.
See also
- The generic
<input>
element and the interface used to manipulate it,HTMLInputElement
- Date and Time picker tutorial