Preview brand Custom

Date field

A date field that opens a large calendar instead of the browser's own picker: two months side by side, or a bottom sheet on phones.

Beta

Show code
astro
<label for="start">Start date</label>
<DateField name="start" id="start" future placeholder="Any date" />

When to use it

  • Someone has to pick a day near today: the start of a trip, a day to publish.
  • Some days can’t be chosen (the past, days outside a season): the calendar shows which.

Use something else when:

  • The date is one people know by heart, such as a date of birth: three plain fields (day, month, year) are quicker than paging back through years.
  • You need a time as well as a day: this is a day only.

How it works

  • Built on Cally (a small, accessible calendar web component), styled with Somnia DS's tokens.
  • Dates are shown in the visitor's own style (day first in the UK, month first in the US) and the week starts on their usual day. The form sends an ISO date (2026-11-14).
  • future blocks past days, worked out in the browser so a build doesn't go stale.
  • The calendar opens with the browser's Popover API. Older browsers without it (Safari before 17) get the same calendar opened by the script, closed by Escape, a click elsewhere, Close or choosing a date.
  • Contact forms use it for type: 'date' fields. A script that sets its value dispatches a sync event so the field shows it.

Do and don't

Do

  • Label which date it is ("Start date")
  • Block the days that can’t be chosen, with future, min and max
  • Let the form send the ISO date; show people their own style

Don't

  • Use it for a date of birth
  • Write the format in a hint ("DD/MM/YYYY"): nobody types here
  • Open it without being asked

Accessibility

What it does for you

  • A button that reads as the field: its name is the label and the date chosen.
  • A large calendar (the Cally web component) with its own keys: arrows by day and week, Page Up and Page Down by month.
  • Dates in the visitor’s own style and their own first day of the week, from their browser’s language. The form is sent an ISO date.
  • Days that can’t be chosen (the past, when future is set) are marked as such, not only greyed.
  • A safety net: where the calendar can’t run, the field becomes the browser’s own date input with the same name and limits.

What you need to do

  • A label that says which date ("Start date").
  • A hint when only some dates can be chosen, saying which.
  • For a date someone knows by heart (a date of birth), use three plain fields; a calendar is for choosing a day near now.

Keyboard

KeyWhat it does
TabMoves to the field’s button.
Enter or SpaceOpens the calendar.
Arrow keysIn the calendar: a day left or right, a week up or down.
Page Up, Page DownA month back or on.
Enter or SpaceOn a day: chooses it and closes the calendar.
EscapeCloses the calendar without choosing.

What a screen reader is told

  • The button: its label and the chosen date, or that none is chosen.
  • In the calendar: each day’s full date, and whether it is chosen, today, or can’t be chosen.

This is what the browser reports to assistive technology. What each screen reader then says varies, and has not been listened to yet.

WCAG 2.2

CriterionLevelHow this meets it
1.3.1 Info and RelationshipsAThe calendar is a grid of days under its month’s name.
2.1.1 KeyboardAOpening, moving, choosing and closing all work from the keyboard.
2.1.2 No Keyboard TrapAEscape always leaves the calendar.
2.5.8 Target Size (Minimum)AADays are large targets: the calendar was chosen for its size on phones.
3.3.2 Labels or InstructionsAThe field carries its label, and the date is shown in the visitor’s own style.
4.1.2 Name, Role, ValueAThe button says whether the calendar is open; days say their state.

The criteria this component has a part in. A page that uses it still has to meet the rest.

Checked

CheckHowResult
Automated (axe-core)WCAG 2.0, 2.1 and 2.2 rules at A and AA, the page in light and in darkPassed
Nothing found, light or dark
Narrow screenNo sideways scrolling at 320px wide (WCAG 1.4.10)Passed
No sideways scrolling
Keyboard and what the browser reportsReal key presses on the live example, and the role, name and state given to assistive technologyPassed
7 of 7 checks pass
On paperSomnia’s print check: no overlaps, stranded headings or controls on the pagePassed
No faults on 5 sheets
Screen readerListened to by a person, in VoiceOver and NVDANot yet
Not yet checked by a person

The 7 checks made with the keyboard, on the example at the top of this page:

  • Passed Tab reaches the field’s button
  • Passed The browser reports the button with its label and the date showing
  • Passed Enter opens the calendar, with focus on a day
  • Passed Right arrow moves a day on; Enter chooses it, closes the calendar and goes back to the button
  • Passed Once a date is chosen, the button’s name says it
  • Passed Escape closes the calendar without choosing, back on the button
  • Passed A past day can’t be chosen, and says so

Run by script on against Somnia DS 1.89.0, in Chromium with axe-core 4.14.0. How these checks work, and every component's results.

Not yet checked

  • How it sounds in a screen reader (VoiceOver, NVDA, TalkBack) has not been checked by a person. The roles, names and states the browser reports are checked by script; what is actually spoken is not.
  • Windows high contrast (forced colours) has not been looked at by a person.
  • The calendar’s own keys and announcements come from Cally; they are checked here by key presses in one browser, not in each screen reader.

Evidence

Where it's used

WhereFor
Headland YachtingThe charter enquiry’s dates, and the yacht search on its home page.
Somnia CMSDate fields in its forms, such as an entry’s Published date.
Any contact formA field of type: 'date'.

What we saw, and what changed

WhenWhat we sawWhat changed
The calendar would not open in Safari before version 17, which has no Popover API.The script opens and closes it there (1.22.1).
A browser that couldn’t run the calendar left a field that did nothing.If a field isn’t wired up a moment after the page loads, it becomes the browser’s own date input (1.28.0).
On paper, an opened calendar lost its weekday letters.Folded parts are measured opened while a page is prepared for print (1.32.0).
The checks written for this page found the button was named by its label alone: a screen reader was told "Start date" and never the date chosen.Its name is now the label and the date showing (1.81.0).

From building and using it on real sites, each entry taken from the changelog or the build's own notes. This is observation by the studio and its clients, not research sessions with users.

What it rests on

What we don't know yet

  • Not watched in use by a charter guest on a phone.
  • Two dates are two fields; a single range picker has not been tried.