Date picker
Let people enter or choose a single date with a date picker and calendar controls.
Example
Mobile
320pxMobile Lg
480pxTablet
640pxDesktop
1024pxComponent API
Initialization
import { datePickerInit } from '@uswds-tailwind/compat/date-picker'
datePickerInit()The initializer returns an array of instances and reuses existing instances. For one picker, use DatePicker.getOrCreateInstance(elementOrSelector, options).
Anatomy
Use data-scope="date-picker" data-part="root" on the root. Descendant parts use short names such as input, trigger, content, and status. Keep all three view elements, with data-view="day", "month", and "year", and the complete table templates from the example.
The day view needs view-control, prev-trigger and next-trigger buttons with data-unit="month" or "year", and view-trigger buttons with data-view="month" or "year". The year view uses prev-trigger and next-trigger with data-view="year" to move through twelve-year ranges. Each view needs a table-cell-trigger button template. The day table also needs a table-header template.
The runtime generates calendar rows, IDs, labels, visibility, and state attributes. Include a status region for announcements.
Configuration
Constructor options take precedence over authored HTML. Attributes are read during construction; later attribute changes do not reconfigure the instance.
| HTML source | Constructor option | Behavior |
|---|---|---|
data-min-date, or input min |
min: Date |
Earliest selectable date. HTML uses ISO YYYY-MM-DD. |
data-max-date, or input max |
max: Date |
Latest selectable date. HTML uses ISO YYYY-MM-DD. |
data-default-value |
defaultValue: (Date | undefined)[] |
Initial selection. HTML uses an ISO date; constructor values use Date objects. |
data-default-date |
defaultDate: Date |
Navigation fallback when no date is selected. Does not select a value. |
data-range-date |
rangeAnchor: Date |
Fixed peer date for range markers and preview. |
Root or input disabled |
disabled: boolean |
Disables the picker. |
Root or input readonly |
readOnly: boolean |
Prevents input and calendar editing. |
Input name, required |
name: string, required: boolean |
Native form name and required state. |
<html lang> |
locale: string |
Locale for month and weekday labels. Uses English if <html lang> is unset. |
Use new Date(2026, 8, 28) for a local September 28 date in constructor options. The visible input uses MM/DD/YYYY. Its authored value does not initialize the single picker’s selection; use data-default-value or defaultValue.
Accessibility and lifecycle
Provide a visible label, a format hint, a named calendar trigger, and a status region. Typed dates must be real calendar dates within the bounds. Empty optional fields remain valid; blur and Enter update native validity.
Keep the complete calendar templates. Retain the root element because initialization changes generated IDs, and call destroy() before removing its markup. See instance lifecycle.