Calendar Component — Astro

Month grid calendar for date display or date picker use. Keyboard and screen reader accessible.

Calendar Component

A month-grid calendar for choosing a date. Includes previous/next month navigation and optional selected date. Uses role="group" and role="grid" with role="gridcell" for accessibility. Fires a calendar-select custom event when a day is chosen.

Add this component

Run the command below in your project directory. When prompted, select the component(s) you want. The CLI will copy the CSS and component files.

Choose your package manager — click a tab to select, then copy the command.

npm pnpm yarn bun

Props

  • id (string, optional) — Unique id (auto-generated if omitted)
  • initialMonth (string, optional) — Initial month as YYYY-MM (default: current month)
  • selected (string, optional) — Selected date as YYYY-MM-DD
  • label (string, optional) — Accessible label (default: "Calendar")
  • class (string, optional) — Additional CSS classes

Events

Listen for calendar-select on the calendar element. event.detail.date is YYYY-MM-DD.

Live Example

Calendar
Sun
Mon
Tue
Wed
Thu
Fri
Sat

Usage

Usage

Full example for each framework (Astro, Vanilla, Svelte, Vue, React). Switch framework via View as or by clicking a Usage tab—both stay in sync.

Astro Vanilla Svelte Vue React

Other frameworks: Vanilla · Svelte · Vue · React