Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Calendar for UI SDK

A month grid that stays on the page for picking a day, a range or several days, for React on UI SDK, with blocked dates, presets and year menus.

On this page9 sections

A calendar lays out a month as a grid of days and keeps it on the page, so people pick a day, a range or a handful of separate days by clicking them. Reach for it when choosing the date is the task itself, as on a booking screen, a shift planner or a report filter.

When the date is one field in a form, a Date Picker opens a month in a popover instead. For a short strip of the days around today, use a Mini Calendar.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Calendar anatomy: prev trigger, month select, year select, next trigger, table, table cell

Usage

import { useState } from "react";
import { Calendar } from "@/components/ui/calendar";
const frame = "w-72 rounded-xl border shadow-xs/5";
// With year menus and no `endMonth`, DayPicker stops paging and lists years
// only up to this December; ten years on leaves room for future dates.
const endMonth = new Date(new Date().getFullYear() + 10, 11);

const CalendarDemo = () => {
  const [date, setDate] = useState<Date | undefined>(new Date());

  return (
    <Calendar
      captionLayout="dropdown"
      className={frame}
      endMonth={endMonth}
      fixedWeeks
      mode="single"
      onSelect={setDate}
      selected={date}
    />
  );
};

Accessibility

Each month is a grid labeled with its month and year, and each day is a grid cell labeled with its full date, which a screen reader reads out with selected, today or unavailable. Only one day is in the tab order, the arrow keys move between days and stop on disabled ones too, so they're still heard, and the month's heading is a live region, so a screen reader announces the new month after a page. To say what the date is for, such as Check-in date, pass aria-label to Calendar, and its root becomes a group announced by that name.

Arrow Left
Moves focus to the previous day. In a right-to-left calendar it moves to the next day.
Arrow Right
Moves focus to the next day. In a right-to-left calendar it moves to the previous day.
Arrow Up
Moves focus to the same day of the week in the previous week.
Arrow Down
Moves focus to the same day of the week in the next week.
Home
Moves focus to the first day of the week.
End
Moves focus to the last day of the week.
Page Up
Moves focus to the same day in the previous month, or to its last day when that month is shorter.
Page Down
Moves focus to the same day in the next month, or to its last day when that month is shorter.
Shift+Page Up
Moves focus to the same day in the previous year.
Shift+Page Down
Moves focus to the same day in the next year.
Enter
Selects the focused day. In a range calendar, the first press starts the range and the second ends it.
Space
Selects the focused day, as Enter does.
Escape
In a range calendar, drops a start that has no end yet and puts back the range there was.

Demos

Hijri

UI SDK dates everything in the Gregorian calendar. A locale such as fa-IR translates the month and weekday names, but the months keep their Gregorian lengths, so there is no UI SDK version of this demo.

Basic

One month between previous and next buttons, with nothing selected yet and no state of your own, since the calendar keeps the selection itself. Setting fixedWeeks keeps every month six rows tall, so the frame doesn't jump as the month changes. Start here when the dates people pick are a few weeks from today.

Preview width

Range

Two months side by side, with a range already selected from the 20th of this month to 18 days later. mode is range and numberOfMonths is 2, and the value is an object with from and to. Use a range for a hotel stay, a leave request or a report period, anywhere the value is a start and an end.

Preview width

Caption

With captionLayout set to dropdown, month and year menus replace the month's name. Someone can reach a date years away in two choices instead of paging month by month. The years run from 100 years ago to the end of this year until you set startMonth and endMonth, and paging stops at the same bounds. Use this layout for a birth date or a document date.

Preview width

Presets

Today, Tomorrow and Next week buttons sit under the grid. Each one sets the selected date and month together, so the view moves with the selection and Next week near the end of a month doesn't land off screen. Add presets where most people choose a date relative to today, such as a due date or a reminder.

Preview width

Time

From and To time inputs, set to 10:30 and 12:30, sit under the grid. The calendar still holds only the date and the demo never joins the times to it, so combine the two yourself when you save a meeting. Use this layout when the month should stay open while people set the hours, and a Date Picker when the date and time are fields in a form.

Preview width

Booked dates

Days 8 through 18 of this month are booked. They're passed to disabled, so they're dimmed and can't be selected, though the arrow keys still stop on them so keyboard users hear them. The 4th starts selected. Keep blocked days visible when people need to see why a stay won't fit, as on a booking page, and say near the calendar what the dimmed days mean.

Preview width

Custom days

Each day of the month shows a price under its number, $100 on weekdays and $120 on weekends, with the 8th to the 16th selected as a range. A custom DayButton, passed in components, renders CalendarDayButton with the price after the day. Use it for fares, room rates or seats left, and keep the extra to a few characters.

Preview width

Week numbers

A column of week numbers runs down the left of the grid, with the 12th of this month selected, and showWeekNumber turns it on. Weeks here start on Sunday, as in US English, so week 1 is the one holding January 1. Set weekStartsOn to 1 and the column counts ISO weeks instead, which start on Monday, as most of Europe plans them.

Preview width

Multiple

The 4th, 12th and 18th of this month start selected, and with mode set to multiple, clicking a day adds it or takes it back out. Use it for shifts, delivery days or exceptions to a schedule, dates that aren't one continuous stretch. When the value is really a start and an end, a Range fits better.

Preview width

RTL

The calendar in Arabic, with dir set to rtl, locale set to ar-SA, and today selected. The week starts at the right edge, the month and year menus follow, and the arrows flip on screen and on the keyboard, where ArrowLeft moves to the next day. The months stay Gregorian, with Arabic names and digits. Set both props whenever the page is in Arabic or Hebrew.

Preview width

FAQ

When should I use a Calendar instead of a Date Picker?

Use a Calendar when the month should stay on screen while people choose, as on a booking page, a shift planner or a report filter that sits beside its results. Every day is one click away and nothing has to open first.

Use a Date Picker when the date is one field in a form: it shows an input and opens a month in a popover only while someone is choosing. For a row of the days around today, such as a delivery slot this week, a Mini Calendar takes far less room.

How do I get the selected date out of the Calendar?

With mode set to single, onSelect receives a Date at the start of that day in the browser's time zone, or undefined when the selected day is clicked again. Hold it in state and pass it back as selected. To store it, write out the year, month and day yourself, because toISOString() converts to UTC and gives the day before anywhere east of Greenwich.

How do I select a date range or several dates with the Calendar in React?

Set mode to range for a start and an end, and selected becomes an object with from and to. Set it to multiple for separate days, and selected becomes an array of dates, where max caps the count and a click past it is ignored until a day is taken out. Add numberOfMonths set to 2 to show two months side by side, as the Range demo does.

The Multiple demo starts with three separate days selected.

How do I disable booked or past dates in the Calendar?

Pass the days to disabled: an array of dates, an object such as { before: new Date() } for the past, or { dayOfWeek: [0, 6] } for weekends. Disabled days are dimmed and can't be selected, as in the Booked dates demo. The arrow keys still stop on them, so keyboard users hear that they're unavailable instead of skipping past without knowing.

How do I let users jump to a year, such as a birth year, in the UI SDK Calendar?

Set captionLayout to dropdown, as the Caption demo does, to swap the month's name for month and year menus. The year menu runs from 100 years ago to the end of the current year, which suits a birth date. For anything later, such as an expiry date, set endMonth, and startMonth for the first year listed.

How do I start the Calendar week on Monday?

Set weekStartsOn to 1, counting from 0 for Sunday. Without it the first day comes from the locale you pass, else from the page's lang, so an English page starts its weeks on Sunday and a German one on Monday. Weeks that start on Monday also switch the Week numbers column to ISO weeks.

Why does the Calendar select the day before the date I set?

A Date made from a date-only string, such as new Date("2025-06-01"), is midnight UTC, which is still May 31 anywhere west of Greenwich, so the calendar marks the 31st. Build dates from their parts instead, new Date(2025, 5, 1), for local midnight. Where you set the month as well, pass the same kind of date to defaultMonth or month.

Can the Calendar show a Persian or Hijri calendar?

No, UI SDK dates everything in the Gregorian calendar, so a locale such as fa-IR or ar-SA translates the month and weekday names and the digits, while the months keep their Gregorian lengths. That's why the Hijri demo has no UI SDK version. For a real Persian or Islamic month, use this component on Base UI or React Aria.

API Reference

Calendar

<div> data-slot="calendar"

PropType
month?Date

The month shown first. Pass it with onMonthChange to control it.

defaultMonth?Date

The month shown first, when uncontrolled. Defaults to today's.

onMonthChange?(month: Date) → void
Parameters

month – Date

Returns
void
buttonVariant?ButtonProps["variant"]

The variant of the previous and next month buttons.

Default
"ghost"
captionLayout?"label" | "dropdown" | "dropdown-months" | "dropdown-years"

A label naming the month, or selects to jump to a month and year.

Type
"label" | "dropdown" | "dropdown-months" | "dropdown-years"
Default
"label"
classNames?CalendarClassNames
components?object
Type
{ Chevron?: React.ComponentType<ChevronProps>; DayButton?: React.ComponentType<DayButtonProps>; Dropdown?: React.ComponentType<DropdownProps>; DropdownNav?: React.ComponentType<React.ComponentProps<"div">>; MonthCaption?: React.ComponentType<MonthCaptionProps> }
disabled?Matcher | Matcher[]

Days that can't be picked. They stay focusable, so keyboard users hear them.

Type
Matcher | Matcher[]
endMonth?Date

The last month that can be shown.

excludeDisabled?boolean

Keeps disabled days out of a range.

fixedWeeks?boolean

Shows six weeks in every month, so the calendar keeps its height.

Default
false
footer?React.ReactNode

Content under the months, announced as it changes.

formatters?Partial<CalendarFormatters>
Type
{ formatCaption: (month: Date) → string; formatDay: (date: Date) → string; formatMonthDropdown: (month: Date) → string; formatWeekdayName: (weekday: Date) → string; formatWeekNumber: (weekNumber: number) → string; formatYearDropdown: (year: Date) → string }
hideNavigation?boolean

Hides the previous and next month buttons.

Default
false
hideWeekdays?boolean

Hides the row of weekday names.

Default
false
locale?string | { code?: string }

The language of names and labels: a tag like "de-DE", or a locale object with a code.

Type
string | { code?: string }
max?number

The most days that can be selected.

min?number

The fewest days that can be selected.

mode?undefined

Without a mode, days can be focused but not selected.

modifiers?Record<string, Matcher | Matcher[]>

Flags days for modifiersClassNames, and for a custom DayButton.

Type
Record<string, Matcher | Matcher[]>
modifiersClassNames?Record<string, string>

Classes for the days a modifier flags, on the day's cell.

Type
Record<string, string>
numberOfMonths?number

How many months show side by side.

Default
1
onSelect?undefined

Called when the item is selected, by pointer or keyboard. Prevent its default to keep the menu open.

pagedNavigation?boolean

Turns all the months shown at once, rather than one.

required?undefined

Whether a value is required to submit its form.

selected?undefined
showOutsideDays?boolean

Shows the days of the months before and after at the edges.

Default
true
showWeekNumber?boolean

Shows the week number at the start of each week.

Default
false
startMonth?Date

The first month that can be shown.

timeZone?string

The time zone that says which day today is.

today?Date

Today's date, marked with aria-current="date". Defaults to today in timeZone.

weekStartsOn?0 | 1 | 2 | 3 | 4 | 5 | 6

The first day of the week, 0 for Sunday. Defaults to the locale's.

Type
0 | 1 | 2 | 3 | 4 | 5 | 6
className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present on the root, grids and selects when the calendar is disabled, on a day that can't be picked, and on Previous or Next at min or max.

data-mode"single" | "multiple" | "range"

How the calendar selects.

Type
"single" | "multiple" | "range"
data-readonly?string

Present when dates can be focused but not picked.

CalendarDayButton

<span> data-slot="calendar-day-button"

PropType
dayobject
Type
{ date: Date; displayMonth: Date; isoDate: string; outside: boolean }
modifiersModifiers
locale?string | { code?: string }

The locale data-day writes the date in.

Type
string | { code?: string }
className?string

Merged with the part's classes.

AttributeType
data-day?string
data-disabled?string
data-range-end?string

Mirrors range_end.

data-range-middle?string

Mirrors range_middle.

data-range-start?string

Mirrors range_start.

data-selected-single?string
data-size"icon-md"
Default
"icon-md"
data-variant"ghost"
Default
"ghost"
CSS variableType
--cell-radiusstring
--cell-sizestring