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" role="group" aria-describedby="passport-issued-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
When was your passport issued?
</h1>
</legend>
<div id="passport-issued-hint" class="govuk-hint">
For example, 27 3 2007
</div>
<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="text" inputmode="numeric">
</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="text" inputmode="numeric">
</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="text" inputmode="numeric">
</div>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/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--l"
}
},
hint: {
text: "For example, 27 3 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.
Make sure that any example dates you use in hint text are valid for the question being asked.
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" role="group" aria-describedby="passport-issued-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
When was your passport issued?
</h1>
</legend>
<div id="passport-issued-hint" class="govuk-hint">
For example, 27 3 2007
</div>
<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="text" inputmode="numeric">
</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="text" inputmode="numeric">
</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="text" inputmode="numeric">
</div>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/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--l"
}
},
hint: {
text: "For example, 27 3 2007"
}
}) }}
Never automatically tab users between the fields of the date input because this can be confusing and may clash with normal keyboard controls.
If you’re asking more than one question on the page
If you’re asking more than one question on the page, do not set the contents of the <legend>
as the page heading. Read more about asking multiple questions on question pages.
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" role="group" aria-describedby="passport-issued-hint">
<legend class="govuk-fieldset__legend">
When was your passport issued?
</legend>
<div id="passport-issued-hint" class="govuk-hint">
For example, 27 3 2007
</div>
<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="text" inputmode="numeric">
</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="text" inputmode="numeric">
</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="text" inputmode="numeric">
</div>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/date-input/macro.njk" import govukDateInput %}
{{ govukDateInput({
id: "passport-issued",
namePrefix: "passport-issued",
fieldset: {
legend: {
text: "When was your passport issued?"
}
},
hint: {
text: "For example, 27 3 2007"
}
}) }}
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" role="group" aria-describedby="dob-hint">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
What is your date of birth?
</h1>
</legend>
<div id="dob-hint" class="govuk-hint">
For example, 31 3 1980
</div>
<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="text" autocomplete="bday-day" inputmode="numeric">
</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="text" autocomplete="bday-month" inputmode="numeric">
</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-4" id="dob-year" name="dob-year" type="text" autocomplete="bday-year" inputmode="numeric">
</div>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/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--l"
}
},
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-4",
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
If you’re highlighting the whole date, style all the fields like this:
<div class="govuk-form-group govuk-form-group--error">
<fieldset class="govuk-fieldset" role="group" aria-describedby="passport-issued-hint passport-issued-error">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
When was your passport issued?
</h1>
</legend>
<div id="passport-issued-hint" class="govuk-hint">
For example, 27 3 2007
</div>
<p 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
</p>
<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="text" value="6" inputmode="numeric">
</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="text" value="3" inputmode="numeric">
</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="text" value="2076" inputmode="numeric">
</div>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/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--l"
}
},
hint: {
text: "For example, 27 3 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"
}
]
}) }}
If you’re highlighting just one field - either the day, month or year - only style the field that has an error. The error message must say which field has an error, like this:
<div class="govuk-form-group govuk-form-group--error">
<fieldset class="govuk-fieldset" role="group" aria-describedby="passport-issued-hint passport-issued-error">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">
When was your passport issued?
</h1>
</legend>
<div id="passport-issued-hint" class="govuk-hint">
For example, 27 3 2007
</div>
<p id="passport-issued-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> The date your passport was issued must include a year
</p>
<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="text" value="6" inputmode="numeric">
</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="text" value="3" inputmode="numeric">
</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="text" inputmode="numeric">
</div>
</div>
</div>
</fieldset>
</div>
{% from "govuk/components/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--l"
}
},
hint: {
text: "For example, 27 3 2007"
},
errorMessage: {
text: "The date your passport was issued must include a year"
},
items: [
{
classes: "govuk-input--width-2",
name: "day",
value: "6"
},
{
classes: "govuk-input--width-2",
name: "month",
value: "3"
},
{
classes: "govuk-input--width-4 govuk-input--error",
name: "year"
}
]
}) }}
Make sure errors follow the guidance in error message and have specific error messages for specific error states.
If there’s more than one error, show the highest priority error message. In order of priority, show error messages about:
- missing or incomplete information
- information that cannot be correct (for example, the number ‘13’ in the month field)
- information that fails validation for another reason
If nothing is entered
Highlight the date input as a whole.
Say ‘Enter [whatever it is]’. For example, ‘Enter your date of birth’.
If the date is incomplete
Highlight the day, month or year field where the information is missing or incomplete. If more than one field is missing information, highlight the fields the user needs to fill in.
Say ‘[whatever it is] must include a [whatever is missing]’.
For example, ‘Date of birth must include a month’, ‘Date of birth must include a day and month’ or ‘Year must include 4 numbers’.
If the date entered cannot be correct
For example, ‘13’ in the month field cannot be correct.
Highlight the day, month or year field with the incorrect information. Or highlight the date as a whole if there’s incorrect information in more than one field, or it’s not clear which field is incorrect.
Say ‘[Whatever it is] must be a real date’. For example, ‘Date of birth must be a real date’.
If the date is in the future when it needs to be in the past
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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
Highlight the date input as a whole.
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 component
To help make sure that this page is useful, relevant and up to date, you can:
- take part in the 'Date input' discussion on GitHub and share your research
- propose a change – read more about how to propose changes in GitHub
Need help?
If you’ve got a question about the GOV.UK Design System, contact the team.