Back to Blog
Close up of developer typing code on keyboard
Development
9 min read

How to Build an Accessible Calendar Component (ARIA + WCAG)

By SimpleCalendarJS Team

SimpleCalendarJS~14 KB gzipped · Zero dependencies · Any framework
Short answer

An accessible calendar component uses a labelled table with role="grid", one focusable day cell (roving tabindex), the APG arrow and Page Up/Page Down keys, aria-selected on the picked date and a polite live region for month changes. It also needs visible focus, 4.5:1 text contrast, 24px targets and a click alternative to dragging.

A calendar is one of the hardest widgets to make accessible. It's a two-dimensional grid of dates that people expect to move through with arrow keys, it shows state mostly through color, and it often relies on dragging. This guide shows how to build an accessible calendar component: which ARIA pattern to use, the exact keyboard model from the W3C Authoring Practices Guide, a complete vanilla JS month grid, and the WCAG 2.2 criteria that catch most calendars out.

What Makes an Accessible Calendar Component

"Accessible" here means four things: someone using only a keyboard can reach and operate every date and event, a screen reader user hears what each cell is and what changed, low-vision users can see focus and state, and nothing works only by dragging or only through color.

These are the WCAG 2.2 success criteria a calendar trips over most often:

CriterionLevelWhat it means for a calendar
1.4.1 Use of ColorA"Today", "selected" and "outside this month" can't be shown by color alone
1.4.3 Contrast (Minimum)AA4.5:1 for normal text, 3:1 for large text (18pt, or 14pt bold)
2.4.7 Focus VisibleAAThe focused day or event must show a visible focus indicator
2.5.7 Dragging MovementsAAAnything you can drag must also work with a single click or tap
2.5.8 Target Size (Minimum)AAClick targets of at least 24 × 24 CSS pixels, or enough spacing around them

The contrast threshold isn't rounded: the W3C Understanding document says a ratio of 4.499:1 fails. The target size rule has exceptions (spacing, an equivalent control, inline text, user agent controls, essential presentation), but a day cell in a date picker usually can't use any of them. The easy fix is to make the cells big enough.

Choosing the Pattern: Table, Grid or Dialog

Not every calendar needs role="grid". MDN's grid role page is explicit: for many use cases a plain HTML table is enough, because table elements already map to ARIA roles. Only use grid when the widget needs interactive, two-dimensional keyboard navigation. MDN also warns that even when keyboard support is correct, some users won't realize they're supposed to use arrow keys.

Here's how that plays out:

  • Read-only month overview (an events page, a fixture list): use a table with a caption, th scope="col" weekday headers and events as links or buttons inside the cells. Users Tab through the events and the table semantics do the rest.
  • Date picker or range picker: use the APG pattern, a table role="grid" labelled by the month heading, usually inside a modal dialog that opens from a "Choose date" button next to a text input. The text input matters: typing a date is often faster than navigating to it.
  • Scheduler with week and day views: the time grid is usually too dense for cell-by-cell navigation. Make events focusable, give each one a full accessible name (title, date, time) and offer a list view as the screen-reader-friendly route.

The rest of this guide builds the date grid, because it's the pattern with the most specific rules.

Need a calendar in your app?

SimpleCalendarJS: ~14 KB gzipped, zero dependencies, works in any framework. Free for personal use.

Building the Accessible Calendar Grid in Vanilla JS

The W3C APG date picker dialog example defines the keyboard model most screen reader users expect:

KeyAction
Left / Right ArrowPrevious / next day (crosses weeks and months)
Up / Down ArrowSame weekday in the previous / next week
Home / EndFirst / last day of the current week
Page Up / Page DownSame day in the previous / next month (or the month's last day if that date doesn't exist)
Shift + Page Up / Page DownSame day in the previous / next year
Enter / SpaceSelect the focused date

Two details from the APG example are easy to miss. First, roving tabindex: only one cell has tabindex="0", so the whole grid is a single Tab stop, and the script moves that 0 as focus moves. Second, aria-selected="true" goes only on the selected date's cell.

Markup

<div class="datepicker"> <div class="dp-header"> <button type="button" class="dp-prev" aria-label="Previous month">‹</button> <h2 id="dp-title" aria-live="polite"></h2> <button type="button" class="dp-next" aria-label="Next month">›</button> </div> <table role="grid" aria-labelledby="dp-title" class="dp-grid"> <thead><tr></tr></thead> <tbody></tbody> </table> <p id="dp-status" aria-live="polite"></p> </div>

The month heading labels the grid and is a polite live region, as in the APG example, so "January 2027" is read when Page Down moves to the next month. The status paragraph confirms the selection. Both live regions are in the HTML from the start. MDN notes that content added after the accessibility tree is built can go unannounced, so create the empty region first and fill it in later.

Rendering and keyboard handling

const title = document.getElementById('dp-title'); const grid = document.querySelector('.dp-grid'); const headRow = grid.querySelector('thead tr'); const body = grid.querySelector('tbody'); const status = document.getElementById('dp-status'); const locale = navigator.language; const weekStartsOn = 1; // Monday const longDay = new Intl.DateTimeFormat(locale, { weekday: 'long' }); const shortDay = new Intl.DateTimeFormat(locale, { weekday: 'short' }); const fullDate = new Intl.DateTimeFormat(locale, { dateStyle: 'full' }); const monthYear = new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }); const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()); const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n); const sameDay = (a, b) => !!a && !!b && a.getTime() === b.getTime(); function addMonths(d, n) { const target = new Date(d.getFullYear(), d.getMonth() + n, 1); const lastDay = new Date(target.getFullYear(), target.getMonth() + 1, 0).getDate(); target.setDate(Math.min(d.getDate(), lastDay)); // Jan 31 + 1 month = Feb 28/29 return target; } let focusDate = startOfDay(new Date()); let selectedDate = null; function renderHeader() { // 4 January 2026 was a Sunday; offset from there to get each weekday name. for (let i = 0; i < 7; i++) { const day = new Date(2026, 0, 4 + ((weekStartsOn + i) % 7)); const th = document.createElement('th'); th.scope = 'col'; th.abbr = longDay.format(day); // full name for screen readers th.textContent = shortDay.format(day); headRow.append(th); } } function render() { const label = monthYear.format(focusDate); if (title.textContent !== label) title.textContent = label; // announce only real changes const today = startOfDay(new Date()); const first = new Date(focusDate.getFullYear(), focusDate.getMonth(), 1); let day = addDays(first, -((first.getDay() - weekStartsOn + 7) % 7)); body.replaceChildren(); for (let week = 0; week < 6; week++) { const tr = document.createElement('tr'); for (let i = 0; i < 7; i++) { const td = document.createElement('td'); td.dataset.time = day.getTime(); td.textContent = day.getDate(); td.tabIndex = sameDay(day, focusDate) ? 0 : -1; td.setAttribute('aria-label', fullDate.format(day) + (sameDay(day, today) ? ', today' : '')); if (sameDay(day, today)) td.classList.add('is-today'); if (sameDay(day, selectedDate)) td.setAttribute('aria-selected', 'true'); if (day.getMonth() !== focusDate.getMonth()) td.classList.add('is-outside'); tr.append(td); day = addDays(day, 1); } body.append(tr); } } function moveFocus(next) { const monthChanged = next.getMonth() !== focusDate.getMonth() || next.getFullYear() !== focusDate.getFullYear(); focusDate = next; if (monthChanged) render(); body.querySelectorAll('td').forEach((td) => { td.tabIndex = Number(td.dataset.time) === focusDate.getTime() ? 0 : -1; }); body.querySelector('td[tabindex="0"]').focus(); } function select(date) { selectedDate = date; body.querySelectorAll('td').forEach((td) => { if (Number(td.dataset.time) === date.getTime()) td.setAttribute('aria-selected', 'true'); else td.removeAttribute('aria-selected'); }); status.textContent = `Selected: ${fullDate.format(date)}`; } grid.addEventListener('keydown', (e) => { const col = (focusDate.getDay() - weekStartsOn + 7) % 7; let next; switch (e.key) { case 'ArrowLeft': next = addDays(focusDate, -1); break; case 'ArrowRight': next = addDays(focusDate, 1); break; case 'ArrowUp': next = addDays(focusDate, -7); break; case 'ArrowDown': next = addDays(focusDate, 7); break; case 'Home': next = addDays(focusDate, -col); break; case 'End': next = addDays(focusDate, 6 - col); break; case 'PageUp': next = addMonths(focusDate, e.shiftKey ? -12 : -1); break; case 'PageDown': next = addMonths(focusDate, e.shiftKey ? 12 : 1); break; case 'Enter': case ' ': e.preventDefault(); select(focusDate); return; default: return; // leave Tab, Escape, etc. alone } e.preventDefault(); // stop the page from scrolling moveFocus(next); }); body.addEventListener('click', (e) => { const td = e.target.closest('td'); if (!td) return; moveFocus(new Date(Number(td.dataset.time))); select(focusDate); }); // The buttons change the month but keep focus on the button. document.querySelector('.dp-prev').addEventListener('click', () => { focusDate = addMonths(focusDate, -1); render(); }); document.querySelector('.dp-next').addEventListener('click', () => { focusDate = addMonths(focusDate, 1); render(); }); renderHeader(); render();

A few design decisions worth explaining:

  • Today is marked in the accessible name, not with aria-current. MDN lists date as a value of aria-current ("the current date within a calendar"), but it also says aria-current shouldn't be used on gridcell, option, row or tab. Adding ", today" to the cell's label is the safe choice inside a grid. (Translate that string along with your other UI text.)
  • Six rows, always. The grid's size doesn't change between months, so the layout doesn't jump and Down Arrow behaves the same everywhere.
  • Out-of-month days stay focusable. Arrow keys cross into the next month anyway, so focusing a visible trailing day just triggers a re-render to that month.
  • Weekday headers use abbr, following the APG example: short visible text, full names for screen readers.
  • Right-to-left layouts. If dir="rtl", swap the Left and Right Arrow cases so the keys follow the visual direction.

If the grid sits inside a modal dialog, as in the APG pattern, Escape closes the dialog and focus returns to the button that opened it. For locale-aware weekday names, week starts and month labels, the Intl internationalization guide covers the formatter options in depth.

Styles: focus, state and target size

.dp-grid { border-collapse: collapse; } .dp-grid td { width: 2.75rem; /* 44px: well above the 24px minimum */ height: 2.75rem; text-align: center; cursor: pointer; color: #111827; } .dp-grid td.is-outside { color: #4b5563; } /* Today: an underline as well as a color, so it doesn't rely on color alone */ .dp-grid td.is-today { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; } /* Selected: fill and bold weight */ .dp-grid td[aria-selected="true"] { background: #1d4ed8; color: #ffffff; font-weight: 700; } /* currentColor stays visible on both white and the blue selected fill */ .dp-grid td:focus-visible { outline: 3px solid currentColor; outline-offset: -5px; } @media (forced-colors: active) { .dp-grid td[aria-selected="true"] { border: 2px solid; } }

Every state has a cue besides color: underline for today, bold weight for selected, an outline for focus. Run your final palette through a contrast checker: muted out-of-month text is where calendars most often fall below 4.5:1. Because the focus indicator is non-text content, it also needs to meet 1.4.11 Non-text Contrast, which the Focus Visible Understanding document points out.

Screen Reader Announcements Without Noise

Live regions are useful in a calendar and very easy to overdo. MDN's guidance is to use polite for nearly everything and assertive only when an interruption is truly necessary. A month change or a moved event never qualifies.

Rules that keep a calendar quiet but informative:

  1. Announce what changed outside the focused element. A new month heading, an event that moved, a save that failed. Don't announce the focused cell. The screen reader already reads it when focus moves.
  2. Only write to a live region when the text actually changes. That's why render() compares title.textContent before setting it.
  3. Keep live regions in the DOM permanently and change their text. Don't insert a new element carrying both the attribute and the message.
  4. Make confirmation messages full sentences ("Design review moved to Tuesday, December 8 at 10:00 AM"), not "Saved".

The APG example adds one more touch: after a date is selected, the "Choose Date" button's accessible name changes to include that date. When focus returns to it, the user hears what they picked.

Drag and Drop Needs a Click Alternative

Drag-to-reschedule is the most common accessibility failure in event calendars. WCAG 2.5.7 Dragging Movements (AA) requires that anything done by dragging can also be done with a single pointer, without dragging. The W3C examples are all close relatives of a calendar: a task board with a "move to" pop-up menu, a kanban widget where you select an item and then press an arrow button, a sortable list with up and down controls.

For a calendar, the equivalent is simple: clicking or pressing Enter on an event opens a dialog where the user can pick a new date and time. That one dialog also covers keyboard users and people using voice control, who can't drag at all. The drag and drop calendar guide covers the drag side; the next section shows the click-based alternative.

The native dialog element does much of the work. MDN documents that showModal() moves focus into the dialog, makes the rest of the page inert, exposes aria-modal="true" and closes on Escape. A form method="dialog" closes it and sets returnValue to the button that was pressed. MDN doesn't promise where focus goes when the dialog closes, so send it back yourself.

Where SimpleCalendarJS Fits

If you need a full month/week/day/list calendar rather than a single date grid, building all of the above for every view is a lot of work. SimpleCalendarJS is a zero-dependency calendar component (~14 KB gzipped JS) that renders semantic HTML with ARIA attributes, uses Intl.DateTimeFormat for locale-aware labels and is responsive. It doesn't do your accessibility testing for you, though. What it provides are the hooks to add what WCAG asks for on top:

  • onEventClick and onSlotClick to open your own accessible dialogs (it has no built-in editing forms, so the markup is yours to get right)
  • onEventDrop to confirm drag-and-drop moves through a live region
  • CSS variables to set colors that pass contrast, autoContrastText for readable text on colored events, and the uc-dark class for a dark theme (see the dark mode guide)
  • a list view, a linear, easy-to-scan way through upcoming events

This example adds a click-based alternative to dragging, announcements and focus return:

<section aria-labelledby="schedule-heading"> <h2 id="schedule-heading" tabindex="-1">Team schedule</h2> <div id="calendar" style="height: 640px"></div> <p id="cal-status" class="visually-hidden" aria-live="polite"></p> </section> <dialog id="move-dialog" aria-labelledby="move-title"> <form method="dialog"> <h3 id="move-title">Move event</h3> <p id="move-event-name"></p> <label for="move-start">New start</label> <input id="move-start" type="datetime-local" required> <button value="cancel" formnovalidate>Cancel</button> <button value="save">Save</button> </form> </dialog>
import SimpleCalendarJs from 'simple-calendar-js'; import 'simple-calendar-js/dist/simple-calendar-js.min.css'; const events = [ { id: 1, title: 'Design review', start: new Date(2026, 11, 8, 10, 0), end: new Date(2026, 11, 8, 11, 0), color: '#1d4ed8', description: 'Room 2 and video link' }, { id: 2, title: 'Sprint planning', start: new Date(2026, 11, 9, 14, 0), end: new Date(2026, 11, 9, 15, 30), color: '#047857' }, ]; const status = document.getElementById('cal-status'); const dialog = document.getElementById('move-dialog'); const startInput = document.getElementById('move-start'); const heading = document.getElementById('schedule-heading'); const when = new Intl.DateTimeFormat('en-US', { dateStyle: 'full', timeStyle: 'short' }); let editing = null; let returnFocusTo = null; function announce(message) { status.textContent = ''; requestAnimationFrame(() => { status.textContent = message; }); // re-announces repeated messages } const pad = (n) => String(n).padStart(2, '0'); const toLocalInput = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`; function moveEvent(id, newStart, newEnd) { const ev = events.find((e) => e.id === id); ev.start = newStart; ev.end = newEnd; // Persist to your API here, then: calendar.refresh(); announce(`${ev.title} moved to ${when.format(newStart)}`); } const calendar = new SimpleCalendarJs('#calendar', { defaultView: 'week', enabledViews: ['month', 'week', 'day', 'list'], defaultDate: new Date(2026, 11, 8), locale: 'en-US', weekStartsOn: 1, enableDragDrop: true, autoContrastText: true, fetchEvents: async () => events, // Pointer users who drag still get a spoken confirmation. onEventDrop: (event, oldStart, oldEnd, newStart, newEnd) => { moveEvent(event.id, newStart, newEnd); }, // The single-pointer alternative to dragging (WCAG 2.5.7). onEventClick: (event) => { editing = event; returnFocusTo = document.activeElement; document.getElementById('move-event-name').textContent = event.title; startInput.value = toLocalInput(new Date(event.start)); dialog.showModal(); }, onViewChange: (view) => announce(`${view} view`), }); dialog.addEventListener('close', () => { if (dialog.returnValue === 'save' && editing) { const oldStart = new Date(editing.start); const duration = new Date(editing.end) - oldStart; const newStart = new Date(startInput.value); // local date-time string moveEvent(editing.id, newStart, new Date(newStart.getTime() + duration)); } editing = null; // refresh() may re-render the event, so fall back to a stable target. if (returnFocusTo?.isConnected) returnFocusTo.focus(); else heading.focus(); });
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } .uc-calendar { --cal-primary: #1d4ed8; --cal-primary-dark: #1e3a8a; --cal-text: #111827; --cal-text-muted: #4b5563; --cal-text-secondary: #374151; --cal-today-bg: #dbeafe; --cal-today-text: #1e3a8a; --cal-border-strong: #6b7280; --cal-font-size: 1rem; }

Be honest with yourself about what to check. Open the sandbox, go through each view using only the keyboard and a screen reader, and confirm that the events you care about can be reached and opened. If any workflow can't be done that way in your setup, add a route outside the calendar too. A plain list of upcoming events with a "Move" button on each, wired to the same dialog, is always keyboard-accessible. Don't put essential details only in hover tooltips. Repeat them in the dialog.

SimpleCalendarJS is free for personal, educational and open source projects; commercial use requires a license (see pricing). If what you actually need is a single accessible date input, the hand-built grid above, or the date range picker walkthrough, may be all you need.

Need a calendar in your app?

SimpleCalendarJS: ~14 KB gzipped, zero dependencies, works in any framework. Free for personal use.

Testing Checklist for an Accessible Calendar Component

Automated checkers catch missing labels and low contrast. They can't tell you whether the keyboard model makes sense. The APG itself says its example code is illustrative, not production-ready, and should be tested with assistive technologies. Before you ship, go through this list:

  1. Keyboard only. Unplug the mouse. Tab into the grid (one stop), use every key in the table above, select a date, move an event through the dialog and press Escape to close. Focus should never disappear or get stuck.
  2. Screen reader. Test with at least one desktop screen reader and one mobile one. Each cell should read as a full date, the selected state should be announced, a month change should be read once, and moved events should be confirmed.
  3. Zoom to 200% and 400%. The grid should reflow or scroll without hiding the toolbar or cutting off dates.
  4. Contrast. Check muted text, today's highlight, event text on every event color, and the focus indicator in both light and dark themes.
  5. Color removed. Use a grayscale filter in DevTools. Today, selected and out-of-month days should still be distinguishable.
  6. Touch. Every day cell and toolbar button should be at least 24 × 24 CSS pixels, and every drag action needs a tap alternative.
  7. Forced colors. Turn on Windows high contrast mode and confirm the selected and focused states are still visible.

Sources & Further Reading

Image Credits

Image free to use under the Pexels License.

Frequently Asked Questions

Is aria-activedescendant better than roving tabindex for a calendar grid?

Both are valid ways to manage focus inside a composite widget. The W3C APG date picker example and MDN's grid calendar example both use roving tabindex: one cell has tabindex="0", the rest -1, and real DOM focus moves between cells. Your :focus-visible styles and scroll-into-view then work without extra code, which makes it the simpler default.

Can I put aria-current="date" on today's cell in a calendar grid?

MDN says aria-current can be used in every role except gridcell, option, row and tab. So in a role="grid" calendar, don't put it on the td. Add the word "today" to the cell's accessible name, or put aria-current="date" on an inner element. Use aria-selected for the date the user picked, not aria-current.

Should arrow keys in a calendar wrap to the next week and month?

Yes, in a date grid. The APG date picker treats Left and Right as previous day and next day, so focus moves across rows and into the next or previous month. That's different from a generic data grid, where the APG says focus stays put at the edges.

Which WCAG success criteria apply to a calendar component?

The main ones are 1.4.1 Use of Color (A), 1.4.3 Contrast Minimum (AA), 2.4.7 Focus Visible (AA), 2.5.7 Dragging Movements (AA) and 2.5.8 Target Size Minimum (AA), plus the general keyboard and name/role/value requirements. 2.4.13 Focus Appearance (AAA) gives stricter guidance on focus indicators.

How do screen readers announce the month change in a date picker?

Put aria-live="polite" on the month and year heading, as the APG date picker example does. When Page Down or the Next button changes the month, update the heading's text and the screen reader reads the new month after the current speech. Only update the text when it actually changes, so it isn't announced again on every arrow key.

Is SimpleCalendarJS accessible out of the box?

SimpleCalendarJS renders semantic HTML with ARIA attributes and is responsive. You still need to check keyboard and screen reader behavior against your own requirements, add contrast-safe colors through its CSS variables, and use its callbacks to provide click-based alternatives to drag and drop and announcements for changes.

Add a calendar to your app today

Free for personal projects. $49/year or $199 lifetime per commercial project.

Keep Reading