Before HTML5, asking a visitor for a date meant either a plain text box, where people typed dates in a dozen different formats, or a JavaScript library that drew a calendar on the page. Today every modern browser has a date picker built in. You add a single attribute to an ordinary <input> element, and the browser shows a calendar on desktop and its native date wheel on phones, with no script and no extra files.
This article explains the five date and time input types, the format of the value each one sends, how to limit the dates a user can choose, how to read the value in JavaScript and on the server, and the situations where a JavaScript library is still the better choice.
The simplest date picker
A date picker is an <input> element whose type is date. Give it a name so its value is sent with the form, and a <label> so the field is announced correctly by screen readers and the label can be clicked:
<label for="birthday">Date of birth</label>
<input type="date" id="birthday" name="birthday" />
You can try it right here. Click the field or its calendar icon and the browser opens its own picker:
The look of the calendar is decided by the browser and the operating system, so it will appear slightly different in Chrome, Firefox and Safari, and quite different on Android and iPhone. That is intentional: each visitor gets the picker they are already used to.
The five date and time input types
HTML5 offers five related types. They all work the same way, and they differ only in what the user picks and in the text that ends up in the input’s value.
| Type | What the user chooses | Example value |
|---|---|---|
date | Day, month and year | 2026-12-04 |
time | Hours and minutes | 14:30 |
datetime-local | A date and a time together | 2026-12-04T14:30 |
month | Month and year | 2026-12 |
week | A week number and year | 2026-W49 |
The column on the right is the most important thing to understand about these inputs. The browser displays the date in the visitor’s own format, so someone in the United States sees 12/04/2026 while someone in Indonesia sees 04/12/2026. The value your code receives, however, is always in the fixed ISO format shown in the table. You never have to guess whether 04/12 means April or December, and you cannot change the displayed format either, because it follows the user’s language settings.
Here is a form that uses all five types:
<form action="/booking" method="post">
<p>
<label for="day">Day</label>
<input type="date" id="day" name="day" />
</p>
<p>
<label for="start">Start time</label>
<input type="time" id="start" name="start" />
</p>
<p>
<label for="meeting">Meeting</label>
<input type="datetime-local" id="meeting" name="meeting" />
</p>
<p>
<label for="period">Billing month</label>
<input type="month" id="period" name="period" />
</p>
<p>
<label for="sprint">Sprint week</label>
<input type="week" id="sprint" name="sprint" />
</p>
<button type="submit">Send</button>
</form>
The older type datetime, which you may still see in tutorials from around 2012, was removed from the standard and never became reliable in browsers. Use datetime-local instead.
Limiting the dates: min, max and step
Most real forms should not accept any date at all. A booking form should not allow dates in the past, and a date of birth should not be in the future. The min and max attributes set the earliest and latest allowed value, written in the same format as the value itself:
<label for="checkin">Check-in date</label>
<input type="date" id="checkin" name="checkin" min="2026-12-01" max="2027-06-30" required />
Browsers grey out the days outside the range in their calendar, and if someone types a date outside it, the form refuses to submit and shows a message. The required attribute works as it does on any other input and stops the form from being sent while the field is empty.
The step attribute controls the size of each step. For date it is counted in days, so step="7" together with a min that falls on a Monday only accepts Mondays. For time it is counted in seconds, which makes step="900" useful for appointments in 15-minute slots, and step="1" adds a seconds field to the picker. Keep in mind that not every browser greys out the disallowed steps in its calendar; some only show an error when the form is submitted.
Setting a default value and today’s date
To show a date that is already filled in, put it in the value attribute in the ISO format:
<input type="date" name="day" value="2026-12-04" />
HTML has no keyword for “today”, so a default of today’s date needs a small script. Be careful with the shortcut new Date().toISOString().slice(0, 10) that appears in many answers online. It returns the date in UTC, so a visitor in Jakarta who opens the page before seven in the morning would see yesterday’s date. Building the string from the local date avoids that problem:
<input type="date" id="day" name="day" />
<script>
const now = new Date();
const pad = (n) => String(n).padStart(2, "0");
const today = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
const field = document.getElementById("day");
field.value = today;
field.min = today; // also prevent dates in the past
</script>
Reading the value in JavaScript
The value property returns the ISO string from the table above, or an empty string if nothing has been chosen. Listening for the change event lets you react as soon as the user picks a date:
const field = document.getElementById("day");
field.addEventListener("change", () => {
if (!field.value) return; // the field was cleared
const [year, month, day] = field.value.split("-").map(Number);
const chosen = new Date(year, month - 1, day);
console.log(chosen.toLocaleDateString());
});
Date inputs also have a valueAsDate property, which looks convenient but gives you a Date set to midnight UTC. Depending on the visitor’s time zone, that can display as the previous day, which is why splitting the string as shown above is the safer habit. For datetime-local, valueAsDate is not available at all, and new Date(field.value) reads the value as local time, which is usually what you want.
If you want the calendar to open from your own button, for example an icon next to a styled field, call showPicker(). Browsers only allow it in response to a user action such as a click:
document.getElementById("open-calendar").addEventListener("click", () => {
document.getElementById("day").showPicker();
});
Processing the date on the server
When the form is submitted, the server receives the same ISO string, which is one of the biggest advantages of native date inputs. In PHP, for example, the value arrives as 2026-12-04 and can be read reliably:
<?php
$day = DateTime::createFromFormat('Y-m-d', $_POST['day'] ?? '');
if ($day === false) {
echo 'Please choose a valid date.';
} else {
echo 'You chose ' . $day->format('l, j F Y');
}
Always validate the date on the server as well, because min, max and required only guide honest users and can be bypassed by anyone sending the request directly. If you are new to handling form data in PHP, the article on building a form with separate processing in HTML5 and PHP walks through the whole flow.
Browser support
The date, time and datetime-local types work in all current versions of Chrome, Edge, Firefox and Safari, on desktop as well as on Android and iPhone, so they are safe to use in any new project.
The month and week types are the exception. Chrome, Edge and other Chromium-based browsers support them, but Firefox and Safari on desktop show an ordinary text box instead. If you need a month picker for every visitor, either use a date input and ignore the day, or give the text box a placeholder such as 2026-12 and a pattern attribute so that users know which format to type.
Styling and its limits
You can style the input box itself like any other input, changing its border, padding, font and colours. The calendar that pops up, however, belongs to the browser and cannot be restyled with CSS. In Chromium browsers you can adjust the small calendar icon through the ::-webkit-calendar-picker-indicator pseudo-element, for example to change its colour in a dark theme, but there is no standard way to change the popup.
When to use a JavaScript date picker instead
The native picker covers most forms, but it has limits that sometimes matter. It cannot disable individual dates, such as fully booked days or public holidays, it cannot select a range of dates in a single control, and its popup cannot match your design. If your form needs any of these, a library such as Flatpickr or the date picker that comes with your UI framework is the better fit. For everything else, the built-in input is lighter, more accessible and works well on phones without any extra code.
Frequently asked questions
How do I change the date format to dd/mm/yyyy?
You cannot change the displayed format of a native date input. The browser shows the date in the format of the visitor’s language and region, so visitors in Indonesia or the United Kingdom already see day before month. The submitted value is always yyyy-mm-dd, and you can format it however you like when you display it elsewhere.
Why does my date picker show a plain text box?
Either the browser does not support that particular type, which is usually the case with month and week in Firefox and Safari, or the type attribute contains a typo. Browsers silently fall back to a text box for any type they do not recognise.
Can I let the user choose both a start and an end date?
Use two date inputs. When the first one changes, set the second one’s min to the chosen start date, so the end date can never be earlier than the start.
Does the date picker work on mobile?
Yes. On Android and iPhone the input opens the phone’s own date picker, which is usually easier to use with a finger than a calendar drawn by a JavaScript library.
The original version of this article was accompanied by a video tutorial, which is still available below if you prefer to follow along by watching.