Form elements
–
Date input
Use date input to help users enter a date, like an appointment date.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string |
Required.
This is used for the main component and to compose the id attribute for each item.
|
|
name |
string |
Optional prefix. This is used to prefix each date input name attribute, wrapped in [ and ]. For example, setting namePrefix: "dob" will output the name attributes dob[day], dob[month] and dob[year] respectively.
|
| items | array |
The inputs within the date input component. The input.errorMessage and input.hint options are not supported.
See items macro options using input component macro.
|
| hint | object | Can be used to add a hint to the date input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the date input component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.
See macro options for error |
|
form |
object |
Additional options for the form group containing the date input component.
See macro options for form |
| fieldset | object |
Can be used to add a fieldset to the date input component. The fieldset.html option is not supported.
See macro options for fieldset.
|
| day | object |
Can be used to customise the day input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See day macro options using input component macro.
|
| month | object |
Can be used to customise the month input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See month macro options using input component macro.
|
| year | object |
Can be used to customise the year input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See year macro options using input component macro.
|
| values | object |
An optional object used to specify value attributes for the inputs within the date input component without setting items.
See macro options for values.
|
| disabled | boolean |
If true, inputs used by the date input component will be disabled.
|
| classes | string | Classes to add to the date input container. |
|
input |
object |
Additional options for the wrapping element containing the date input component.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the date input container. |
| Name | Type | Description |
|---|---|---|
| name | string |
Required.
Item-specific name attribute. Defaults to "day", "month" or "year".
|
| label | object |
Item-specific label. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the item input.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
|
before |
object |
Content to add before the inputs used by the date input component.
See macro options for form |
|
after |
object |
Content to add after the inputs used by the date input component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the inputs. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the inputs. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the inputs. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the inputs. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the day input. Defaults to "day".
|
| value | string |
The value attribute for the day input.
|
| label | object |
The label used by the day input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the day input.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the month input. Defaults to "month".
|
| value | string |
The value attribute for the month input.
|
| label | object |
The label used by the month input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the month input.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the year input. Defaults to "year".
|
| value | string |
The value attribute for the year input.
|
| label | object |
The label used by the year input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the year input.
|
| Name | Type | Description |
|---|---|---|
| day | string |
The value attribute for the day input.
|
| month | string |
The value attribute for the month input.
|
| year | string |
The value attribute for the year input.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the wrapping element. |
| attributes | object | HTML attributes (for example data attributes) to add to the wrapping element. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
|
is |
boolean | Whether the label also acts as the heading for the page. |
| size | string |
Size of the label – "s", "m", "l" or "xl".
|
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
When to use date input
We follow the GOV.UK Design System. Use date input when you're asking users for a date they already know.
When not to use date input
Do not use date input if users are unlikely to know the exact date you're asking about.
How to use date input
Date input consists of 3 fields to let users enter a day, month and year.
Group the 3 date fields together in a <fieldset> with a <legend> that describes them. You can see an example at the top of this page. The legend is usually a question, like "When was your appointment?".
If you are asking just 1 question per page as we recommend, you can set the contents of the <legend> as the page heading. This is good practice as it means that screen reader users will only hear the contents once.
Read more on the GOV.UK Design System about how to ask users for dates and making labels and legends headings.
Using the autocomplete attribute
If you are asking the user for their own date of birth, use the autocomplete attributes. This lets some browsers autofill the information if the user has entered it previously.
You'll need to do this to meet WCAG 2.2 success criterion 1.3.5: Identify input purpose, level AA.
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.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string |
Required.
This is used for the main component and to compose the id attribute for each item.
|
|
name |
string |
Optional prefix. This is used to prefix each date input name attribute, wrapped in [ and ]. For example, setting namePrefix: "dob" will output the name attributes dob[day], dob[month] and dob[year] respectively.
|
| items | array |
The inputs within the date input component. The input.errorMessage and input.hint options are not supported.
See items macro options using input component macro.
|
| hint | object | Can be used to add a hint to the date input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the date input component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.
See macro options for error |
|
form |
object |
Additional options for the form group containing the date input component.
See macro options for form |
| fieldset | object |
Can be used to add a fieldset to the date input component. The fieldset.html option is not supported.
See macro options for fieldset.
|
| day | object |
Can be used to customise the day input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See day macro options using input component macro.
|
| month | object |
Can be used to customise the month input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See month macro options using input component macro.
|
| year | object |
Can be used to customise the year input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See year macro options using input component macro.
|
| values | object |
An optional object used to specify value attributes for the inputs within the date input component without setting items.
See macro options for values.
|
| disabled | boolean |
If true, inputs used by the date input component will be disabled.
|
| classes | string | Classes to add to the date input container. |
|
input |
object |
Additional options for the wrapping element containing the date input component.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the date input container. |
| Name | Type | Description |
|---|---|---|
| name | string |
Required.
Item-specific name attribute. Defaults to "day", "month" or "year".
|
| label | object |
Item-specific label. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the item input.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
|
before |
object |
Content to add before the inputs used by the date input component.
See macro options for form |
|
after |
object |
Content to add after the inputs used by the date input component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the inputs. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the inputs. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the inputs. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the inputs. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the day input. Defaults to "day".
|
| value | string |
The value attribute for the day input.
|
| label | object |
The label used by the day input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the day input.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the month input. Defaults to "month".
|
| value | string |
The value attribute for the month input.
|
| label | object |
The label used by the month input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the month input.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the year input. Defaults to "year".
|
| value | string |
The value attribute for the year input.
|
| label | object |
The label used by the year input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the year input.
|
| Name | Type | Description |
|---|---|---|
| day | string |
The value attribute for the day input.
|
| month | string |
The value attribute for the month input.
|
| year | string |
The value attribute for the year input.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the wrapping element. |
| attributes | object | HTML attributes (for example data attributes) to add to the wrapping element. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
|
is |
boolean | Whether the label also acts as the heading for the page. |
| size | string |
Size of the label – "s", "m", "l" or "xl".
|
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
Error messages
Style error messages like this.
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work. These are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string |
Required.
This is used for the main component and to compose the id attribute for each item.
|
|
name |
string |
Optional prefix. This is used to prefix each date input name attribute, wrapped in [ and ]. For example, setting namePrefix: "dob" will output the name attributes dob[day], dob[month] and dob[year] respectively.
|
| items | array |
The inputs within the date input component. The input.errorMessage and input.hint options are not supported.
See items macro options using input component macro.
|
| hint | object | Can be used to add a hint to the date input component. See macro options for hint. |
|
error |
object |
Can be used to add an error message to the date input component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.
See macro options for error |
|
form |
object |
Additional options for the form group containing the date input component.
See macro options for form |
| fieldset | object |
Can be used to add a fieldset to the date input component. The fieldset.html option is not supported.
See macro options for fieldset.
|
| day | object |
Can be used to customise the day input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See day macro options using input component macro.
|
| month | object |
Can be used to customise the month input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See month macro options using input component macro.
|
| year | object |
Can be used to customise the year input within the date input component. The input.formGroup and input.inputWrapper options are not supported.
See year macro options using input component macro.
|
| values | object |
An optional object used to specify value attributes for the inputs within the date input component without setting items.
See macro options for values.
|
| disabled | boolean |
If true, inputs used by the date input component will be disabled.
|
| classes | string | Classes to add to the date input container. |
|
input |
object |
Additional options for the wrapping element containing the date input component.
See macro options for input |
| attributes | object | HTML attributes (for example data attributes) to add to the date input container. |
| Name | Type | Description |
|---|---|---|
| name | string |
Required.
Item-specific name attribute. Defaults to "day", "month" or "year".
|
| label | object |
Item-specific label. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the item input.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
|
before |
object |
Content to add before the inputs used by the date input component.
See macro options for form |
|
after |
object |
Content to add after the inputs used by the date input component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the inputs. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the inputs. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the inputs. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the inputs. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the day input. Defaults to "day".
|
| value | string |
The value attribute for the day input.
|
| label | object |
The label used by the day input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the day input.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the month input. Defaults to "month".
|
| value | string |
The value attribute for the month input.
|
| label | object |
The label used by the month input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the month input.
|
| Name | Type | Description |
|---|---|---|
| name | string |
The name attribute for the year input. Defaults to "year".
|
| value | string |
The value attribute for the year input.
|
| label | object |
The label used by the year input. The label.size and label.isPageHeading options are not supported. Defaults to the name option capitalised.
See macro options for label.
|
| error | boolean |
If set to true, show a red border on the year input.
|
| Name | Type | Description |
|---|---|---|
| day | string |
The value attribute for the day input.
|
| month | string |
The value attribute for the month input.
|
| year | string |
The value attribute for the year input.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the wrapping element. |
| attributes | object | HTML attributes (for example data attributes) to add to the wrapping element. |
| Name | Type | Description |
|---|---|---|
| id | string | The ID of the label. |
| text | string |
Required.
If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
|
| caller | nunjucks-block |
Not strictly a parameter but Nunjucks code convention. Using a call block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire label component in a call block.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
|
is |
boolean | Whether the label also acts as the heading for the page. |
| size | string |
Size of the label – "s", "m", "l" or "xl".
|
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
Follow:
Research
Our date input is based on the component in the GOV.UK Design System. GOV.UK says that they need to do more research to understand if users struggle to enter months as numbers and whether it's more helpful to let them enter months as text.
If you've used this component, get in touch to share your user research findings.
Help us improve this guidance
Share insights or feedback and take part in the discussion. We use GitHub as a collaboration space. All the information on it is open to the public.
Feed back or share insights on GitHubRead more about how to feed back or share insights.
If you have any questions, get in touch with the service manual team.
Updated: April 2026