Skip to main content
Components

Date input

Use the date input component to help users enter a memorable date.

Read the Design System guidance for date input

Import

import * as DateInput from 'govuk-react/date-input';

Examples

Default

Code
<DateInput.Field
  id="passport-issued"
  namePrefix="passport-issued"
  legend="When was your passport issued?"
  hint="For example, 27 3 2007"
/>

Date with default values

Code
<DateInput.Field
  id="passport-issued"
  namePrefix="passport-issued"
  legend="When was your passport issued?"
  hint="For example, 27 3 2007"
  values={{ day: '27', month: '3', year: '2007' }}
/>

Date with hint text error

Code
<DateInput.Field
  id="passport-issued"
  namePrefix="passport-issued"
  legend="When was your passport issued?"
  hint="For example, 27 3 2007"
  errorMessage="The date your passport was issued must be in the past"
/>

Date with custom items

Code
<DateInput.Field
  id="passport-issued"
  namePrefix="passport-issued"
  legend="When does your passport expire?"
  hint="For example, 3 2027"
>
  {(
    <>
      <DateInput.Item>
        <DateInput.Label htmlFor="expiry-month">Month</DateInput.Label>
        <DateInput.Input id="expiry-month" name="expiry-month" width={2} />
      </DateInput.Item>
      <DateInput.Item>
        <DateInput.Label htmlFor="expiry-year">Year</DateInput.Label>
        <DateInput.Input id="expiry-year" name="expiry-year" width={4} />
      </DateInput.Item>
    </>
  )}
</DateInput.Field>

API reference

DateInput.Root

Use the date input component to help users enter a memorable date.

No props of its own. Other props are passed to the element it renders.

DateInput.Field

Use the date input component to help users enter a memorable date.

PropType
legendSize"s" | "m" | "l" | "xl"
legendIsPageHeadingboolean
values

Specify value attributes for the date parts.

{ day?: string; month?: string; year?: string; }
namePrefix

Optional prefix. This is used to prefix each item name, separated by -.

string
legendRequired

The legend for the fieldset used by the date input component.

ReactNode
hint

Can be used to add a hint to a date input component.

ReactNode
errorMessage

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.

ReactNode

DateInput.Input

PropType
errorboolean
width

A number of characters, or a fraction of the container.

2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth
extraLetterSpacingboolean

DateInput.Item

No props of its own. Other props are passed to the element it renders.

DateInput.Label

PropType
size"s" | "m" | "l" | "xl"
isPageHeading

Whether the label also acts as the heading for the page.

boolean