<fieldsetclass="govuk-fieldset"role="group"aria-describedby="passport-issued-hint"><legendclass="govuk-fieldset__legend govuk-fieldset__legend--l"><h1class="govuk-fieldset__heading">
When was your passport issued?
</h1></legend><divid="passport-issued-hint"class="govuk-hint">
For example, 27 3 2007
</div><divclass="govuk-date-input"id="passport-issued"><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-day">
Day
</label><inputclass="govuk-input govuk-date-input__input govuk-input--width-2"id="passport-issued-day"name="passport-issued-day"type="text"inputmode="numeric"></div></div><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-month">
Month
</label><inputclass="govuk-input govuk-date-input__input govuk-input--width-2"id="passport-issued-month"name="passport-issued-month"type="text"inputmode="numeric"></div></div><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-year">
Year
</label><inputclass="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>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-date-input-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
This is used for the main component and to compose the ID attribute for each item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">namePrefix</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional prefix. This is used to prefix each <code>item.name</code> using <code>-</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">items</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
An array of input objects with name, value and classes.
See <a href="#options-date-input-example--items">items</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-date-input-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-date-input-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">fieldset</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the fieldset component (for example legend).
See <a href="/components/fieldset/#options-fieldset-example">fieldset</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the date-input container.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date-input container.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-example--items">
<caption class="govuk-table__caption govuk-heading-m ">Options for items</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific ID. If provided, it will be used instead of the generated ID.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Item-specific name attribute.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific label text. If provided, this will be used instead of <code>name</code> for item label text.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
If provided, it will be used as the initial value of the input.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">autocomplete</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html">identify input purpose</a>, for instance <code>bday-day</code>. See <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill">autofill</a> for full list of attributes that can be used.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">pattern</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/TR/html51/sec-forms.html#the-pattern-attribute">provide a regular expression pattern</a>, used to match allowed character combinations for the input value.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to date input item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date input tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
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.
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.
<fieldsetclass="govuk-fieldset"role="group"aria-describedby="passport-issued-hint"><legendclass="govuk-fieldset__legend govuk-fieldset__legend--l"><h1class="govuk-fieldset__heading">
When was your passport issued?
</h1></legend><divid="passport-issued-hint"class="govuk-hint">
For example, 27 3 2007
</div><divclass="govuk-date-input"id="passport-issued"><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-day">
Day
</label><inputclass="govuk-input govuk-date-input__input govuk-input--width-2"id="passport-issued-day"name="passport-issued-day"type="text"inputmode="numeric"></div></div><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-month">
Month
</label><inputclass="govuk-input govuk-date-input__input govuk-input--width-2"id="passport-issued-month"name="passport-issued-month"type="text"inputmode="numeric"></div></div><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-year">
Year
</label><inputclass="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>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-date-input-second-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
This is used for the main component and to compose the ID attribute for each item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">namePrefix</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional prefix. This is used to prefix each <code>item.name</code> using <code>-</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">items</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
An array of input objects with name, value and classes.
See <a href="#options-date-input-second-example--items">items</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-date-input-second-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-date-input-second-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">fieldset</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the fieldset component (for example legend).
See <a href="/components/fieldset/#options-fieldset-example">fieldset</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the date-input container.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date-input container.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-second-example--items">
<caption class="govuk-table__caption govuk-heading-m ">Options for items</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific ID. If provided, it will be used instead of the generated ID.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Item-specific name attribute.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific label text. If provided, this will be used instead of <code>name</code> for item label text.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
If provided, it will be used as the initial value of the input.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">autocomplete</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html">identify input purpose</a>, for instance <code>bday-day</code>. See <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill">autofill</a> for full list of attributes that can be used.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">pattern</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/TR/html51/sec-forms.html#the-pattern-attribute">provide a regular expression pattern</a>, used to match allowed character combinations for the input value.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to date input item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date input tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-second-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-second-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
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="app-example app-example--tabs">
<div class="app-example__toolbar">
<a href="/components/date-input/without-heading/index.html" class="app-example__new-window" target="_blank">
Open this
<span class="govuk-visually-hidden">date input without a heading second</span>
example in a new tab
</a>
</div>
<iframe title="Date input without a heading second example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable app-example__frame--s" src="/components/date-input/without-heading/index.html" frameBorder="0" loading="lazy"></iframe>
</div>
<span id="options-date-input-without-a-heading-second-example"></span>
<ul class="app-tabs" role="tablist">
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#date-input-without-a-heading-second-example-html" role="tab" aria-controls="date-input-without-a-heading-second-example-html" data-track="tab-html">HTML</a></li>
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#date-input-without-a-heading-second-example-nunjucks" role="tab" aria-controls="date-input-without-a-heading-second-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>
<div class="app-tabs__heading js-tabs__heading"><a href="#date-input-without-a-heading-second-example-html" aria-controls="date-input-without-a-heading-second-example-html" data-track="tab-html">HTML</a></div>
<div class="app-tabs__container js-tabs__container" id="date-input-without-a-heading-second-example-html" role="tabpanel">
<div class="app-example__code">
<pre data-module="app-copy" tabindex="0"><code class="hljs html"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"govuk-form-group"</span>></span>
<fieldsetclass="govuk-fieldset"role="group"aria-describedby="passport-issued-hint"><legendclass="govuk-fieldset__legend">
When was your passport issued?
</legend><divid="passport-issued-hint"class="govuk-hint">
For example, 27 3 2007
</div><divclass="govuk-date-input"id="passport-issued"><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-day">
Day
</label><inputclass="govuk-input govuk-date-input__input govuk-input--width-2"id="passport-issued-day"name="passport-issued-day"type="text"inputmode="numeric"></div></div><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-month">
Month
</label><inputclass="govuk-input govuk-date-input__input govuk-input--width-2"id="passport-issued-month"name="passport-issued-month"type="text"inputmode="numeric"></div></div><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-year">
Year
</label><inputclass="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>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-date-input-without-a-heading-second-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
This is used for the main component and to compose the ID attribute for each item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">namePrefix</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional prefix. This is used to prefix each <code>item.name</code> using <code>-</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">items</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
An array of input objects with name, value and classes.
See <a href="#options-date-input-without-a-heading-second-example--items">items</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-date-input-without-a-heading-second-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-date-input-without-a-heading-second-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">fieldset</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the fieldset component (for example legend).
See <a href="/components/fieldset/#options-fieldset-example">fieldset</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the date-input container.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date-input container.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-without-a-heading-second-example--items">
<caption class="govuk-table__caption govuk-heading-m ">Options for items</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific ID. If provided, it will be used instead of the generated ID.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Item-specific name attribute.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific label text. If provided, this will be used instead of <code>name</code> for item label text.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
If provided, it will be used as the initial value of the input.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">autocomplete</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html">identify input purpose</a>, for instance <code>bday-day</code>. See <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill">autofill</a> for full list of attributes that can be used.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">pattern</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/TR/html51/sec-forms.html#the-pattern-attribute">provide a regular expression pattern</a>, used to match allowed character combinations for the input value.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to date input item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date input tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-without-a-heading-second-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-without-a-heading-second-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
{{ 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="app-example app-example--tabs">
<div class="app-example__toolbar">
<a href="/components/date-input/date-of-birth/index.html" class="app-example__new-window" target="_blank">
Open this
<span class="govuk-visually-hidden">date input to ask for date of birth</span>
example in a new tab
</a>
</div>
<iframe title="Date input to ask for date of birth example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable app-example__frame--s" src="/components/date-input/date-of-birth/index.html" frameBorder="0" loading="lazy"></iframe>
</div>
<span id="options-default-2-open"></span>
<ul class="app-tabs" role="tablist">
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#default-2-open-html" role="tab" aria-controls="default-2-open-html" data-track="tab-html">HTML</a></li>
<li class="app-tabs__item js-tabs__item" role="presentation"><a href="#default-2-open-nunjucks" role="tab" aria-controls="default-2-open-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>
<div class="app-tabs__heading js-tabs__heading"><a href="#default-2-open-html" aria-controls="default-2-open-html" data-track="tab-html">HTML</a></div>
<div class="app-tabs__container js-tabs__container" id="default-2-open-html" role="tabpanel">
<div class="app-example__code">
<pre data-module="app-copy" tabindex="0"><code class="hljs html"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"govuk-form-group"</span>></span>
<fieldsetclass="govuk-fieldset"role="group"aria-describedby="dob-hint"><legendclass="govuk-fieldset__legend govuk-fieldset__legend--l"><h1class="govuk-fieldset__heading">
What is your date of birth?
</h1></legend><divid="dob-hint"class="govuk-hint">
For example, 31 3 1980
</div><divclass="govuk-date-input"id="dob"><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="dob-day">
Day
</label><inputclass="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><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="dob-month">
Month
</label><inputclass="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><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="dob-year">
Year
</label><inputclass="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>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-default-2-open--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
This is used for the main component and to compose the ID attribute for each item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">namePrefix</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional prefix. This is used to prefix each <code>item.name</code> using <code>-</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">items</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
An array of input objects with name, value and classes.
See <a href="#options-default-2-open--items">items</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-default-2-open--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-default-2-open--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">fieldset</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the fieldset component (for example legend).
See <a href="/components/fieldset/#options-fieldset-example">fieldset</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the date-input container.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date-input container.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-default-2-open--items">
<caption class="govuk-table__caption govuk-heading-m ">Options for items</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific ID. If provided, it will be used instead of the generated ID.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Item-specific name attribute.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific label text. If provided, this will be used instead of <code>name</code> for item label text.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
If provided, it will be used as the initial value of the input.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">autocomplete</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html">identify input purpose</a>, for instance <code>bday-day</code>. See <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill">autofill</a> for full list of attributes that can be used.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">pattern</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/TR/html51/sec-forms.html#the-pattern-attribute">provide a regular expression pattern</a>, used to match allowed character combinations for the input value.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to date input item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date input tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-default-2-open--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-default-2-open--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
<fieldsetclass="govuk-fieldset"role="group"aria-describedby="passport-issued-hint passport-issued-error"><legendclass="govuk-fieldset__legend govuk-fieldset__legend--l"><h1class="govuk-fieldset__heading">
When was your passport issued?
</h1></legend><divid="passport-issued-hint"class="govuk-hint">
For example, 27 3 2007
</div><pid="passport-issued-error"class="govuk-error-message"><spanclass="govuk-visually-hidden">Error:</span> The date your passport was issued must be in the past
</p><divclass="govuk-date-input"id="passport-issued"><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-day">
Day
</label><inputclass="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><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-month">
Month
</label><inputclass="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><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-year">
Year
</label><inputclass="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>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-date-input-with-errors-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
This is used for the main component and to compose the ID attribute for each item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">namePrefix</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional prefix. This is used to prefix each <code>item.name</code> using <code>-</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">items</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
An array of input objects with name, value and classes.
See <a href="#options-date-input-with-errors-example--items">items</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-date-input-with-errors-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-date-input-with-errors-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">fieldset</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the fieldset component (for example legend).
See <a href="/components/fieldset/#options-fieldset-example">fieldset</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the date-input container.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date-input container.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-with-errors-example--items">
<caption class="govuk-table__caption govuk-heading-m ">Options for items</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific ID. If provided, it will be used instead of the generated ID.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Item-specific name attribute.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific label text. If provided, this will be used instead of <code>name</code> for item label text.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
If provided, it will be used as the initial value of the input.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">autocomplete</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html">identify input purpose</a>, for instance <code>bday-day</code>. See <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill">autofill</a> for full list of attributes that can be used.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">pattern</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/TR/html51/sec-forms.html#the-pattern-attribute">provide a regular expression pattern</a>, used to match allowed character combinations for the input value.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to date input item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date input tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-with-errors-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-date-input-with-errors-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
{{ 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:
<fieldsetclass="govuk-fieldset"role="group"aria-describedby="passport-issued-hint passport-issued-error"><legendclass="govuk-fieldset__legend govuk-fieldset__legend--l"><h1class="govuk-fieldset__heading">
When was your passport issued?
</h1></legend><divid="passport-issued-hint"class="govuk-hint">
For example, 27 3 2007
</div><pid="passport-issued-error"class="govuk-error-message"><spanclass="govuk-visually-hidden">Error:</span> The date your passport was issued must include a year
</p><divclass="govuk-date-input"id="passport-issued"><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-day">
Day
</label><inputclass="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><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-month">
Month
</label><inputclass="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><divclass="govuk-date-input__item"><divclass="govuk-form-group"><labelclass="govuk-label govuk-date-input__label"for="passport-issued-year">
Year
</label><inputclass="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>
<p>
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
</p>
<p>
Some options are required for the macro to work; these are marked as "Required" in the option description.
</p>
<p>
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting">cross-site scripting exploits</a>.
</p>
<table class="govuk-table app-options__table" id="options-dates-with-errors-example--primary">
<caption class="govuk-table__caption govuk-heading-m govuk-visually-hidden">Primary options</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
This is used for the main component and to compose the ID attribute for each item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">namePrefix</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional prefix. This is used to prefix each <code>item.name</code> using <code>-</code>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">items</th>
<td class="govuk-table__cell ">array</td>
<td class="govuk-table__cell ">
An array of input objects with name, value and classes.
See <a href="#options-dates-with-errors-example--items">items</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">hint</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the hint component.
See <a href="#options-dates-with-errors-example--hint">hint</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">errorMessage</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the error message component. The error message component will not display if you use a falsy value for <code>errorMessage</code>, for example <code>false</code> or <code>null</code>.
See <a href="/components/error-message/#options-error-message-example">errorMessage</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">formGroup</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the form-group wrapper.
See <a href="#options-dates-with-errors-example--formGroup">formGroup</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">fieldset</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
Options for the fieldset component (for example legend).
See <a href="/components/fieldset/#options-fieldset-example">fieldset</a>.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the date-input container.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date-input container.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-dates-with-errors-example--items">
<caption class="govuk-table__caption govuk-heading-m ">Options for items</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific ID. If provided, it will be used instead of the generated ID.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">name</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
Item-specific name attribute.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">label</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Item-specific label text. If provided, this will be used instead of <code>name</code> for item label text.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">value</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
If provided, it will be used as the initial value of the input.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">autocomplete</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html">identify input purpose</a>, for instance <code>bday-day</code>. See <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill">autofill</a> for full list of attributes that can be used.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">pattern</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Attribute to <a href="https://www.w3.org/TR/html51/sec-forms.html#the-pattern-attribute">provide a regular expression pattern</a>, used to match allowed character combinations for the input value.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to date input item.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the date input tag.
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-dates-with-errors-example--formGroup">
<caption class="govuk-table__caption govuk-heading-m ">Options for formGroup</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the form group (for example to show error state for the whole group).
</td>
</tr>
</tbody>
</table>
<table class="govuk-table app-options__table" id="options-dates-with-errors-example--hint">
<caption class="govuk-table__caption govuk-heading-m ">Options for hint</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Name</th>
<th class="govuk-table__header app-options__limit-table-cell" scope="col">Type</th>
<th class="govuk-table__header" scope="col">Description</th>
</tr>
</thead>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">text</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>html</code> is set, this is not required. Text to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">html</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
<strong>Required.</strong>
If <code>text</code> is set, this is not required. HTML to use within the hint. If <code>html</code> is provided, the <code>text</code> option will be ignored.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">id</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Optional ID attribute to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">classes</th>
<td class="govuk-table__cell ">string</td>
<td class="govuk-table__cell ">
Classes to add to the hint span tag.
</td>
</tr>
<tr class="govuk-table__row">
<th class="govuk-table__header" scope="row">attributes</th>
<td class="govuk-table__cell ">object</td>
<td class="govuk-table__cell ">
HTML attributes (for example data attributes) to add to the hint span tag.
</td>
</tr>
</tbody>
</table>
{{ 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: