The HTML datepicker component now works in most browsers and the minimum and maximum control attributes are fully implemented. The correct format is yyyy-mm-dd
, as described at MDN.
<input type="date" id="birthday" name="birthday" min="2020-01-20" max="2021-01-28">
A simple example adapted from w3school:
<!DOCTYPE html>
<html>
<body>
<h1>Show a Date Control</h1>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday" min="2020-01-20" max="2021-01-28">
<p><strong>Note:</strong> type="date" is not supported in Safari or Internet Explorer 11 (or earlier).</p>
</body>
</html>
As supplementary information, from the HTML5 specification documentation.
In session 4.10.5.1.7 Date state (type=date), we read:
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.
And in the other session, 4.10.1.8 Date, time, and number formats, we find:
...is intended to be computer-readable and consistent irrespective of
the user's locale. Dates, for instance, are always written in the
format "YYYY-MM-DD", as in "2003-02-01".