Skip to main content

Date input examples

  • # default

    What is your date of birth?
    For example, 31 3 1980
    {
      "id": "dob",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      }
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      }
    }) }}
            
  • # day and month

    What is your birthday?
    For example, 5 12
    {
      "id": "bday",
      "namePrefix": "bday",
      "fieldset": {
        "legend": {
          "text": "What is your birthday?"
        }
      },
      "hint": {
        "text": "For example, 5 12"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "bday",
      "namePrefix": "bday",
      "fieldset": {
        "legend": {
          "text": "What is your birthday?"
        }
      },
      "hint": {
        "text": "For example, 5 12"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        }
      ]
    }) }}
            
  • # month and year

    When did you move to this property?
    For example, 3 1980
    {
      "id": "dob",
      "namePrefix": "dob",
      "fieldset": {
        "legend": {
          "text": "When did you move to this property?"
        }
      },
      "hint": {
        "text": "For example, 3 1980"
      },
      "items": [
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob",
      "namePrefix": "dob",
      "fieldset": {
        "legend": {
          "text": "When did you move to this property?"
        }
      },
      "hint": {
        "text": "For example, 3 1980"
      },
      "items": [
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }) }}
            
  • # with errors only

    What is your date of birth?

    Error: Error message goes here

    {
      "id": "dob-errors",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4 govuk-input--error"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-errors",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4 govuk-input--error"
        }
      ]
    }) }}
            
  • # with errors and hint

    What is your date of birth?
    For example, 31 3 1980

    Error: Error message goes here

    {
      "id": "dob-errors",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4 govuk-input--error"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-errors",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4 govuk-input--error"
        }
      ]
    }) }}
            
  • # with error on day input

    What is your date of birth?
    For example, 31 3 1980

    Error: Error message goes here

    {
      "id": "dob-day-error",
      "namePrefix": "dob-day-error",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-day-error",
      "namePrefix": "dob-day-error",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }) }}
            
  • # with error on month input

    What is your date of birth?
    For example, 31 3 1980

    Error: Error message goes here

    {
      "id": "dob-month-error",
      "namePrefix": "dob-month-error",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-month-error",
      "namePrefix": "dob-month-error",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2 govuk-input--error"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }) }}
            
  • # with error on year input

    What is your date of birth?
    For example, 31 3 1980

    Error: Error message goes here

    {
      "id": "dob-year-error",
      "namePrefix": "dob-year-error",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4 govuk-input--error"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-year-error",
      "namePrefix": "dob-year-error",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "errorMessage": {
        "text": "Error message goes here"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4 govuk-input--error"
        }
      ]
    }) }}
            
  • # classes

    {
      "id": "with-classes",
      "classes": "app-date-input--custom-modifier"
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-classes",
      "classes": "app-date-input--custom-modifier"
    }) }}
            
  • # attributes

    {
      "id": "with-attributes",
      "attributes": {
        "data-attribute": "my data value"
      }
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-attributes",
      "attributes": {
        "data-attribute": "my data value"
      }
    }) }}
            
  • # with items

    What is your date of birth?
    For example, 31 3 1980
    {
      "id": "dob",
      "namePrefix": "dob",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob",
      "namePrefix": "dob",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4"
        }
      ]
    }) }}
            
  • # with empty items

    {
      "id": "with-empty-items",
      "items": []
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-empty-items",
      "items": []
    }) }}
            
  • # custom pattern

    {
      "id": "with-custom-pattern",
      "items": [
        {
          "name": "day",
          "pattern": "[0-8]*"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-custom-pattern",
      "items": [
        {
          "name": "day",
          "pattern": "[0-8]*"
        }
      ]
    }) }}
            
  • # custom inputmode

    {
      "id": "with-custom-inputmode",
      "items": [
        {
          "name": "day",
          "pattern": "[0-9X]*",
          "inputmode": "text"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-custom-inputmode",
      "items": [
        {
          "name": "day",
          "pattern": "[0-9X]*",
          "inputmode": "text"
        }
      ]
    }) }}
            
  • # with nested name

    {
      "id": "with-nested-name",
      "items": [
        {
          "name": "day[dd]"
        },
        {
          "name": "month[mm]"
        },
        {
          "name": "year[yyyy]"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-nested-name",
      "items": [
        {
          "name": "day[dd]"
        },
        {
          "name": "month[mm]"
        },
        {
          "name": "year[yyyy]"
        }
      ]
    }) }}
            
  • # with id on items

    {
      "id": "with-item-id",
      "items": [
        {
          "id": "day",
          "name": "day"
        },
        {
          "id": "month",
          "name": "month"
        },
        {
          "id": "year",
          "name": "year"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-item-id",
      "items": [
        {
          "id": "day",
          "name": "day"
        },
        {
          "id": "month",
          "name": "month"
        },
        {
          "id": "year",
          "name": "year"
        }
      ]
    }) }}
            
  • # suffixed id

    {
      "id": "my-date-input",
      "items": [
        {
          "name": "day"
        },
        {
          "name": "month"
        },
        {
          "name": "year"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "my-date-input",
      "items": [
        {
          "name": "day"
        },
        {
          "name": "month"
        },
        {
          "name": "year"
        }
      ]
    }) }}
            
  • # with values

    {
      "id": "with-values",
      "items": [
        {
          "id": "day",
          "name": "day"
        },
        {
          "id": "month",
          "name": "month"
        },
        {
          "id": "year",
          "name": "year",
          "value": 2018
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-values",
      "items": [
        {
          "id": "day",
          "name": "day"
        },
        {
          "id": "month",
          "name": "month"
        },
        {
          "id": "year",
          "name": "year",
          "value": 2018
        }
      ]
    }) }}
            
  • # with hint and describedBy

    What is your date of birth?
    For example, 31 3 1980
    {
      "id": "dob-errors",
      "fieldset": {
        "describedBy": "test-target-element",
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      }
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-errors",
      "fieldset": {
        "describedBy": "test-target-element",
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      }
    }) }}
            
  • # with error and describedBy

    What is your date of birth?

    Error: Error message goes here

    {
      "id": "dob-errors",
      "fieldset": {
        "describedBy": "test-target-element",
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "errorMessage": {
        "text": "Error message goes here"
      }
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-errors",
      "fieldset": {
        "describedBy": "test-target-element",
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "errorMessage": {
        "text": "Error message goes here"
      }
    }) }}
            
  • # fieldset html

    What is your date of birth?
    {
      "id": "with-fieldset-html",
      "fieldset": {
        "legend": {
          "html": "What is your <b>date of birth</b>?"
        }
      }
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-fieldset-html",
      "fieldset": {
        "legend": {
          "html": "What is your <b>date of birth</b>?"
        }
      }
    }) }}
            
  • # items with classes

    {
      "id": "with-item-classes",
      "items": [
        {
          "name": "day",
          "classes": "app-date-input__day"
        },
        {
          "name": "month",
          "classes": "app-date-input__month"
        },
        {
          "name": "year",
          "classes": "app-date-input__year"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "with-item-classes",
      "items": [
        {
          "name": "day",
          "classes": "app-date-input__day"
        },
        {
          "name": "month",
          "classes": "app-date-input__month"
        },
        {
          "name": "year",
          "classes": "app-date-input__year"
        }
      ]
    }) }}
            
  • # items without classes

    {
      "id": "without-item-classes",
      "items": [
        {
          "name": "day"
        },
        {
          "name": "month"
        },
        {
          "name": "year"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "without-item-classes",
      "items": [
        {
          "name": "day"
        },
        {
          "name": "month"
        },
        {
          "name": "year"
        }
      ]
    }) }}
            
  • # with optional form-group classes

    What is your date of birth?
    For example, 31 3 1980
    {
      "id": "dob",
      "namePrefix": "dob",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "formGroup": {
        "classes": "extra-class"
      }
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob",
      "namePrefix": "dob",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "formGroup": {
        "classes": "extra-class"
      }
    }) }}
            
  • # with autocomplete values

    What is your date of birth?
    For example, 31 3 1980
    {
      "id": "dob-with-autocomplete-attribute",
      "namePrefix": "dob-with-autocomplete",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2",
          "autocomplete": "bday-day"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2",
          "autocomplete": "bday-month"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4",
          "autocomplete": "bday-year"
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-with-autocomplete-attribute",
      "namePrefix": "dob-with-autocomplete",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2",
          "autocomplete": "bday-day"
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2",
          "autocomplete": "bday-month"
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4",
          "autocomplete": "bday-year"
        }
      ]
    }) }}
            
  • # with input attributes

    What is your date of birth?
    For example, 31 3 1980
    {
      "id": "dob-with-input-attributes",
      "namePrefix": "dob-with-input-attributes",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2",
          "attributes": {
            "data-example-day": "day"
          }
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2",
          "attributes": {
            "data-example-month": "month"
          }
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4",
          "attributes": {
            "data-example-year": "year"
          }
        }
      ]
    }
    
    {% from "govuk/components/date-input/macro.njk" import govukDateInput %}
    
    {{ govukDateInput({
      "id": "dob-with-input-attributes",
      "namePrefix": "dob-with-input-attributes",
      "fieldset": {
        "legend": {
          "text": "What is your date of birth?"
        }
      },
      "hint": {
        "text": "For example, 31 3 1980"
      },
      "items": [
        {
          "name": "day",
          "classes": "govuk-input--width-2",
          "attributes": {
            "data-example-day": "day"
          }
        },
        {
          "name": "month",
          "classes": "govuk-input--width-2",
          "attributes": {
            "data-example-month": "month"
          }
        },
        {
          "name": "year",
          "classes": "govuk-input--width-4",
          "attributes": {
            "data-example-year": "year"
          }
        }
      ]
    }) }}