Date input
Use the date input component to help users enter a memorable date or one they can easily look up.
<div class="govuk-form-group">
<fieldset
class="govuk-fieldset"
role="group"
aria-describedby="contract-start-date-default-hint"
>
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">When will the contract start?</h1>
</legend>
<div id="contract-start-date-default-hint" class="govuk-hint">
For example, 27 3 2023
</div>
<div class="govuk-date-input" id="contract-start-date-default">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-default-day"
>
Day
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-2"
id="contract-start-date-default-day"
name="contract-start-date-default-day"
type="text"
inputmode="numeric"
/>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-default-month"
>
Month
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-2"
id="contract-start-date-default-month"
name="contract-start-date-default-month"
type="text"
inputmode="numeric"
/>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-default-year"
>
Year
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-4"
id="contract-start-date-default-year"
name="contract-start-date-default-year"
type="text"
inputmode="numeric"
/>
</div>
</div>
</div>
</fieldset>
</div>
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.
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. |
namePrefix | string | Optional prefix. This is used to prefix each item |
items | array | The inputs within the date input component. See items. |
hint | object | Can be used to add a hint to a date input component. See hint. |
errorMessage | 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 See error message. |
formGroup | object | Additional options for the form group containing the date input component. See formGroup. |
fieldset | object | Can be used to add a fieldset to the date input component. See fieldset. |
classes | string | Classes to add to the date-input container. |
attributes | object | HTML attributes (for example data attributes) to add to the date-input container. |
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. |
beforeInputs | object | Content to add before the inputs used by the date input component. See beforeInputs. |
afterInputs | object | Content to add after the inputs used by the date input component. See afterInputs. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the inputs. If |
html | string | Required. HTML to add after the inputs. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the inputs. If |
html | string | Required. HTML to add before the inputs. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
id | string | Optional ID attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
id | string | Item-specific ID. If provided, it will be used instead of the generated ID. |
name | string | Required. Item-specific name attribute. |
label | string | Item-specific label text. If provided, this will be used instead of |
value | string | If provided, it will be used as the initial value of the input. |
autocomplete | string | Attribute to identify input purpose, for instance |
pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
classes | string | Classes to add to date input item. |
attributes | object | HTML attributes (for example data attributes) to add to the date input tag. |
{% from "moduk/components/date-input/macro.njk" import modukDateInput -%}
{{ modukDateInput({
id: "contract-start-date-default",
namePrefix: "contract-start-date-default",
fieldset: {
legend: {
text: "When will the contract start?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "For example, 27 3 2023"
}
}) -}}
See GOV.UK date input component guidance for:
- when to use this component
- when not to use it
How it works
See GOV.UK date input component guidance for detail on how this component works.
If you’re asking one question on the page
<div class="govuk-form-group">
<fieldset
class="govuk-fieldset"
role="group"
aria-describedby="contract-start-date-with-page-heading-hint"
>
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading">When will the contract start?</h1>
</legend>
<div id="contract-start-date-with-page-heading-hint" class="govuk-hint">
For example, 27 3 2023
</div>
<div class="govuk-date-input" id="contract-start-date-with-page-heading">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-with-page-heading-day"
>
Day
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-2"
id="contract-start-date-with-page-heading-day"
name="contract-start-date-with-page-heading-day"
type="text"
inputmode="numeric"
/>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-with-page-heading-month"
>
Month
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-2"
id="contract-start-date-with-page-heading-month"
name="contract-start-date-with-page-heading-month"
type="text"
inputmode="numeric"
/>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-with-page-heading-year"
>
Year
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-4"
id="contract-start-date-with-page-heading-year"
name="contract-start-date-with-page-heading-year"
type="text"
inputmode="numeric"
/>
</div>
</div>
</div>
</fieldset>
</div>
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.
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. |
namePrefix | string | Optional prefix. This is used to prefix each item |
items | array | The inputs within the date input component. See items. |
hint | object | Can be used to add a hint to a date input component. See hint. |
errorMessage | 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 See error message. |
formGroup | object | Additional options for the form group containing the date input component. See formGroup. |
fieldset | object | Can be used to add a fieldset to the date input component. See fieldset. |
classes | string | Classes to add to the date-input container. |
attributes | object | HTML attributes (for example data attributes) to add to the date-input container. |
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. |
beforeInputs | object | Content to add before the inputs used by the date input component. See beforeInputs. |
afterInputs | object | Content to add after the inputs used by the date input component. See afterInputs. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the inputs. If |
html | string | Required. HTML to add after the inputs. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the inputs. If |
html | string | Required. HTML to add before the inputs. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
id | string | Optional ID attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
id | string | Item-specific ID. If provided, it will be used instead of the generated ID. |
name | string | Required. Item-specific name attribute. |
label | string | Item-specific label text. If provided, this will be used instead of |
value | string | If provided, it will be used as the initial value of the input. |
autocomplete | string | Attribute to identify input purpose, for instance |
pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
classes | string | Classes to add to date input item. |
attributes | object | HTML attributes (for example data attributes) to add to the date input tag. |
{% from "moduk/components/date-input/macro.njk" import modukDateInput %}
{{ modukDateInput({
id: "contract-start-date-with-page-heading",
namePrefix: "contract-start-date-with-page-heading",
fieldset: {
legend: {
text: "When will the contract start?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "For example, 27 3 2023"
}
}) }}
If you’re asking more than one question on the page
<div class="govuk-form-group">
<fieldset
class="govuk-fieldset"
role="group"
aria-describedby="contract-start-date-not-as-heading-hint"
>
<legend class="govuk-fieldset__legend">
When will the contract start?
</legend>
<div id="contract-start-date-not-as-heading-hint" class="govuk-hint">
For example, 27 3 2023
</div>
<div class="govuk-date-input" id="contract-start-date-not-as-heading">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-not-as-heading-day"
>
Day
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-2"
id="contract-start-date-not-as-heading-day"
name="contract-start-date-not-as-heading-day"
type="text"
inputmode="numeric"
/>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-not-as-heading-month"
>
Month
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-2"
id="contract-start-date-not-as-heading-month"
name="contract-start-date-not-as-heading-month"
type="text"
inputmode="numeric"
/>
</div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<label
class="govuk-label govuk-date-input__label"
for="contract-start-date-not-as-heading-year"
>
Year
</label>
<input
class="govuk-input govuk-date-input__input govuk-input--width-4"
id="contract-start-date-not-as-heading-year"
name="contract-start-date-not-as-heading-year"
type="text"
inputmode="numeric"
/>
</div>
</div>
</div>
</fieldset>
</div>
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.
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. |
namePrefix | string | Optional prefix. This is used to prefix each item |
items | array | The inputs within the date input component. See items. |
hint | object | Can be used to add a hint to a date input component. See hint. |
errorMessage | 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 See error message. |
formGroup | object | Additional options for the form group containing the date input component. See formGroup. |
fieldset | object | Can be used to add a fieldset to the date input component. See fieldset. |
classes | string | Classes to add to the date-input container. |
attributes | object | HTML attributes (for example data attributes) to add to the date-input container. |
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. |
beforeInputs | object | Content to add before the inputs used by the date input component. See beforeInputs. |
afterInputs | object | Content to add after the inputs used by the date input component. See afterInputs. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the inputs. If |
html | string | Required. HTML to add after the inputs. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the inputs. If |
html | string | Required. HTML to add before the inputs. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
id | string | Optional ID attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
id | string | Item-specific ID. If provided, it will be used instead of the generated ID. |
name | string | Required. Item-specific name attribute. |
label | string | Item-specific label text. If provided, this will be used instead of |
value | string | If provided, it will be used as the initial value of the input. |
autocomplete | string | Attribute to identify input purpose, for instance |
pattern | string | Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value. |
classes | string | Classes to add to date input item. |
attributes | object | HTML attributes (for example data attributes) to add to the date input tag. |
{% from "moduk/components/date-input/macro.njk" import modukDateInput -%}
{{ modukDateInput({
id: "contract-start-date-not-as-heading",
namePrefix: "contract-start-date-not-as-heading",
fieldset: {
legend: {
text: "When will the contract start?"
}
},
hint: {
text: "For example, 27 3 2023"
}
}) -}}
Changes from the GOV.UK version
MOD.UK Design System components are closely based on GOV.UK Design System components.
For this component we’ve changed the font.
Have you tested this component?
Let us know how we could improve this component or share your user research findings.
Email the MOD.UK Design System team at design-system@digital.mod.uk
Need help?
Email the MOD.UK Design System team at design-system@digital.mod.uk if you have questions or feedback.