Date input
<gcds-date-input>
Also called: dates, dateinput, date, memorable date.
A date input is a space to enter a known date.
-
GitHub -
Figma
Date input component preview
On this page
Coding and accessibility for date inputs
Apply required attributes
For the date input to function properly, always use the following attributes with <gcds-date-input>:
namelegendformat
Format the date input
- Choose the format of the date input by entering either
full,compact, orisoin theformatattribute of the date input. - The
fullvalue will render the date input with a year, month, and day form field in the order month, day, and year in English and the order of day, month, and year in French. In this format, the month is written while the day and year are numbers. - The
compactvalue will render the date input with a year and month form field in the order of month and year in both English and French. In this format, the month is written and the year is a number. - The
isovalue will render the date input with a year, month, and day form field in that order. In this format, all inputs are numeric, following ISO standards.
Entering and receiving the value from date input
Date input can receive and output different value formats depending on the format attribute:
- The
fullandisoformat will expect/output a value formattedYYYY-MM-DD. - The
compactformat will expect/output a value formattedYYYY-MM.
Use valid properties
Component properties have built-in validation. Required properties or properties prone to misuse will be validated. If there are any validation errors, the component will be non-functional and won't render. Review the browser's console for details and adjust the properties accordingly to ensure proper functionality.
Handle error messages and validation
-
Use the
requiredattribute to activate the required validator. Validation will happen by default on theonBlurevent. A missing or invalid entry will prompt an inline error message with preset text. -
If you need to change the validation event, use the
validate-onattribute. Validation can happen on blur, when the element loses focus, or manually with thevalidate()method. -
Use the
requiredattribute for fields that must be filled in. This places "required" at the end of the label. -
Use the
error-messageattribute to include an error message text for all required inputs. Avoid using error messages for optional ones. -
For optional fields, avoid adding the
error-messageattribute. -
For an optional field that needs validation based on user input (like validating an email address format), opt to add custom validation with a custom error message.
Include a hint text for task success
-
Use the
hintattribute to add hint text to help a person provide a complete value in the input and avoid an error state. -
Avoid adding hint text in the field (sometimes called placeholder text) where it will disappear once the field is selected or a response starts to be entered.
In this section
format
The format attribute sets how the date is formatted.
<gcds-date-input format="full" legend="Legend" name="example-default">
</gcds-date-input>
legend
The legend attribute defines the legend for the date input.
<gcds-date-input format="full" legend="Legend" name="example-default">
</gcds-date-input>
name
The name attribute identifies the date input component within a form. It is used to reference the component after a form is submitted.
<gcds-date-input format="full" legend="Legend" name="example-default">
</gcds-date-input>
autofocus
The autofocus attribute controls whether the date input will be focused automatically when the page loads. By default, it is set to false. When set to true, the date input is focused on render.
<gcds-date-input autofocus format="full" legend="Legend" name="example-default">
</gcds-date-input>
disabled
The disabled attribute controls whether the date input is disabled or not. By default, it is set to false.
<gcds-date-input disabled format="full" legend="Legend" name="example-default">
</gcds-date-input>
error-message
The error-message attribute defines the error message to display for invalid date inputs.
<gcds-date-input error-message="Error message" format="full" legend="Legend" name="example-default">
</gcds-date-input>
form
The form attribute specifies the ID of the form that the date input belongs to.
<gcds-date-input form="form-id" format="full" legend="Legend" name="example-default">
</gcds-date-input>
hint
The hint attribute defines the hint text displayed under the legend.
<gcds-date-input hint="Day can be 1 or 2 digits. Year must be 4 digits." format="full" legend="Legend" name="example-default">
</gcds-date-input>
max
The max attribute defines the maximum date that the date input can accept. Format: YYYY-MM-DD or YYYY-MM.
<gcds-date-input max="2000-01-01" hint="The date must be before 2000-01-01" format="full" legend="Legend" name="example-default">
</gcds-date-input>
min
The min attribute defines the minimum date that the date input can accept. Format: YYYY-MM-DD or YYYY-MM.
<gcds-date-input min="2000-01-01" hint="The date must be after 2000-01-01" format="full" legend="Legend" name="example-default">
</gcds-date-input>
required
The required attribute controls whether the date input field is required or not. When set to true, it adds “required” after the legend, and activates the required validator.
<gcds-date-input required format="full" legend="Legend" name="example-default">
</gcds-date-input>
validate-on
The validate-on attribute defines the validation event for the date input.
<gcds-date-input validate-on="other" required format="full" legend="Legend" name="example-default">
</gcds-date-input>
value
The value attribute sets the initial date displayed in the component. It also provides a reference to the entered date. Format: YYYY-MM-DD or YYYY-MM.
<gcds-date-input value="2026-02-22" format="full" legend="Legend" name="example-default">
</gcds-date-input>
Code builder
Generate an instance of the component you need by selecting its code properties.
-
Explore by choosing different code values to generate the instance you want.
-
Get the code and pull it into your environment.
-
Add any copy you need to the component (like text for a label).
Note: The code builder uses English for all code elements, which follows standard practice.
Help us improve
Have questions or a request? Give feedback on our contact form.
Something's wrong? Raise it through GitHub with an