Date input
Use the date input component to help users enter a memorable date or one they can easily look up.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="passport-issued-hint" role="group">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
When was your passport issued?
</h1>
</legend>
<span id="passport-issued-hint" class="govuk-hint">
For example, 12 11 2007
</span>
<div class="govuk-date-input" id="passport-issued">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-day">
Day
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="passport-issued-day" name="passport-issued-day" type="number" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-month">
Month
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="passport-issued-month" name="passport-issued-month" type="number" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-year">
Year
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-4" id="passport-issued-year" name="passport-issued-year" type="number" pattern="[0-9]*">
</div>
</div>
</div>
</fieldset>
</div>
{% from "date-input/macro.njk" import govukDateInput %}
{{ govukDateInput({
id: "passport-issued",
namePrefix: "passport-issued",
fieldset: {
legend: {
text: "When was your passport issued?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "For example, 12 11 2007"
}
}) }}
When to use this component
Use the date input component when you’re asking users for a date they’ll already know, or can look up without using a calendar.
When not to use this component
Do not use the date input component if users are unlikely to know the exact date of the event you’re asking about.
Read more about how to ask users for dates.
How it works
The date input component consists of 3 fields to let users enter a day, month and year.
The 3 date fields are grouped together in a <fieldset>
with a <legend>
that describes them, as shown in the examples on this page. This is usually a question, like ‘What is your date of birth?’.
If you’re asking one question per page, you can set the contents of the <legend>
as the page heading. This is good practice as it means that users of screen readers will only hear the contents once.
Read more about why and how to set legends as headings.
There are 2 ways to use the date input component. You can use HTML or, if you’re using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="passport-issued-hint" role="group">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
When was your passport issued?
</h1>
</legend>
<span id="passport-issued-hint" class="govuk-hint">
For example, 12 11 2007
</span>
<div class="govuk-date-input" id="passport-issued">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-day">
Day
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="passport-issued-day" name="passport-issued-day" type="number" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-month">
Month
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="passport-issued-month" name="passport-issued-month" type="number" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-year">
Year
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-4" id="passport-issued-year" name="passport-issued-year" type="number" pattern="[0-9]*">
</div>
</div>
</div>
</fieldset>
</div>
{% from "date-input/macro.njk" import govukDateInput %}
{{ govukDateInput({
id: "passport-issued",
namePrefix: "passport-issued",
fieldset: {
legend: {
text: "When was your passport issued?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "For example, 12 11 2007"
}
}) }}
Never automatically tab users between the fields of the date input because this can be confusing and may clash with normal keyboard controls.
Use the autocomplete attribute for a date of birth
Use the autocomplete
attribute on the date input component when you’re asking for a date of birth. This lets browsers autofill the information on a user’s behalf if they’ve entered it previously.
To do this, set the autocomplete
attribute on the 3 fields to bday-day
, bday-month
and bday-year
. See how to do this in the HTML and Nunjucks tabs in the following example.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="dob-hint" role="group">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
What is your date of birth?
</h1>
</legend>
<span id="dob-hint" class="govuk-hint">
For example, 31 3 1980
</span>
<div class="govuk-date-input" id="dob">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="dob-day">
Day
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="dob-day" name="dob-day" type="number" autocomplete="bday-day" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="dob-month">
Month
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="dob-month" name="dob-month" type="number" autocomplete="bday-month" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="dob-year">
Year
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2" id="dob-year" name="dob-year" type="number" autocomplete="bday-year" pattern="[0-9]*">
</div>
</div>
</div>
</fieldset>
</div>
{% from "date-input/macro.njk" import govukDateInput %}
{{ govukDateInput({
id: "dob",
namePrefix: "dob",
fieldset: {
legend: {
text: "What is your date of birth?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "For example, 31 3 1980"
},
items: [
{
name: "day",
classes: "govuk-input--width-2",
autocomplete: "bday-day"
},
{
name: "month",
classes: "govuk-input--width-2",
autocomplete: "bday-month"
},
{
name: "year",
classes: "govuk-input--width-2",
autocomplete: "bday-year"
}
]
}) }}
If you are working in production you’ll need to do this to meet WCAG 2.1 Level AA.
You will not normally need to use the autocomplete
attribute in prototypes, as users will not generally be using their own devices.
Error messages
Error messages should be styled like this:
<div class="govuk-form-group govuk-form-group--error">
<fieldset class="govuk-fieldset" aria-describedby="passport-issued-hint passport-issued-error" role="group">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--xl">
<h1 class="govuk-fieldset__heading">
When was your passport issued?
</h1>
</legend>
<span id="passport-issued-hint" class="govuk-hint">
For example, 12 11 2007
</span>
<span id="passport-issued-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> The date your passport was issued must be in the past
</span>
<div class="govuk-date-input" id="passport-issued">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-day">
Day
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2 govuk-input--error" id="passport-issued-day" name="passport-issued-day" type="number" value="6" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-month">
Month
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-2 govuk-input--error" id="passport-issued-month" name="passport-issued-month" type="number" value="3" pattern="[0-9]*">
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label class="govuk-label govuk-date-input__label" for="passport-issued-year">
Year
</label>
<input class="govuk-input govuk-date-input__input govuk-input--width-4 govuk-input--error" id="passport-issued-year" name="passport-issued-year" type="number" value="2076" pattern="[0-9]*">
</div>
</div>
</div>
</fieldset>
</div>
{% from "date-input/macro.njk" import govukDateInput %}
{{ govukDateInput({
id: "passport-issued",
namePrefix: "passport-issued",
fieldset: {
legend: {
text: "When was your passport issued?",
isPageHeading: true,
classes: "govuk-fieldset__legend--xl"
}
},
hint: {
text: "For example, 12 11 2007"
},
errorMessage: {
text: "The date your passport was issued must be in the past"
},
items: [
{
classes: "govuk-input--width-2 govuk-input--error",
name: "day",
value: "6"
},
{
classes: "govuk-input--width-2 govuk-input--error",
name: "month",
value: "3"
},
{
classes: "govuk-input--width-4 govuk-input--error",
name: "year",
value: "2076"
}
]
}) }}
Make sure errors follow the guidance in error message and have specific error messages for specific error states.
Check the entire date, not the day, month and year separately.
Avoid assuming what is wrong with the date. For example, if a user enters ‘31 2 2016’, the day may be right and the month may be wrong. An error message that mentions February may be confusing if they meant to enter ‘1’.
If nothing is entered
Say ‘Enter [whatever it is]’.
For example, ‘Enter your date of birth’.
If an incomplete date is entered and you know what is missing
Say ‘[whatever it is] must include a [whatever is missing]’.
For example, ‘Date of birth must include a month’ or ‘Date of birth must include a day and month’.
If an incomplete date is entered and you do not know what is missing
Say ‘Enter [whatever it is] and include a day, month and year’.
For example, ‘Enter your date of birth and include a day, month and year’.
If the date entered is not a real one
Say ‘Enter a real [whatever it is]’.
For example, ‘Enter a real date of birth’.
If the date is in the future when it needs to be in the past
Say ‘[whatever it is] must be in the past’.
For example, ‘Date of birth must be in the past’.
If the date is in the future when it needs to be today or in the past
Say ‘[whatever it is] must be today or in the past’.
For example, ‘Date of birth must be today or in the past’.
If the date is in the past when it needs to be in the future
Say ‘[whatever it is] must be in the future’.
For example, ‘The date your course ends must be in the future’.
If the date is in the past when it needs to be today or in the future
Say ‘[whatever it is] must be today or in the future’.
For example, ‘The date your course ends must be today or in the future’.
If the date must be the same as or after another date
Say ‘[whatever it is] must be the same as or after [date and optional description]’.
For example, ‘The date your course ends must be the same as or after 1 September 2017 when you started the course’.
If the date must be after another date
Say ‘[whatever it is] must be after [date and optional description]’.
For example, ‘The day your course ends must be after 1 September 2017’.
If the date must be the same as or before another date
Say ‘[whatever it is] must be the same as or before [date and optional description]’.
For example, ‘The date of Gordon’s last exam must be the same as or before 31 August 2017 when they left school’.
If the date must be before another date
Say ‘[whatever it is] must be before [date and optional description]’.
For example, ‘The date of Gordon’s last exam must be the same as or before 31 August 2017’.
If the date must be between two dates
Say ‘[whatever it is] must be between [date] and [date and optional description]’.
For example, ‘The date your contract started must be between 1 September 2017 and 30 September 2017 when you were self-employed’.
Research on this component
More research is needed to determine the extent to which users struggle to enter months as numbers, and whether allowing them to enter months as text is helpful.
Help improve this page
To help make sure the Date input page is useful, relevant and up to date, you can:
- share research or feedback about the Date input component on GitHub
- propose a change to this page - read more about how to propose changes in GitHub
Need help?
If you’ve got a question about the GOV.UK Design System you can contact the team: