Skip to content

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

Components

Free

Calendar for Svelte UI SDK

A month grid that stays on the page for picking a day, a range or several days, for Svelte 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

<script lang="ts">
import {
  Calendar, CalendarMonthSelect, CalendarNextTrigger,
  CalendarPrevTrigger, CalendarTable, CalendarTableDays,
  CalendarViewControl, CalendarWeekDays, CalendarYearSelect,
  type DateValue, parseDate,
} from "@/components/ui/calendar"
const frame = "w-72 rounded-xl border shadow-xs/5"
let value = $state<DateValue | null>(parseDate(new Date()))
const setValue = (next: DateValue | null | ((previous: DateValue | null) => DateValue | null)) => { value = typeof next === "function" ? next(value) : next }
const handleValueChange = (next: DateValue | null) => {
    setValue(next);
  }
</script>
<Calendar class={frame} fixedWeeks onValueChange={handleValueChange} value={value}><CalendarViewControl><CalendarPrevTrigger /><CalendarMonthSelect /><CalendarYearSelect /><CalendarNextTrigger /></CalendarViewControl><CalendarTable><CalendarWeekDays /><CalendarTableDays /></CalendarTable></Calendar>

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

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. selectionMode is range, numOfMonths is 2, and the second month is a CalendarTableNextMonth next to the first. 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

CalendarMonthSelect and CalendarYearSelect, two native selects, take the place of the month's name between the arrows, so a date years away is a few choices instead of paging month by month. With no min or max, the year menu lists ten years either side of the year shown. Use this layout for a birth date, a contract start or a document date.

Preview width

Presets

Today, Tomorrow and Next week buttons sit under the grid. Each is a CalendarPresetTrigger with its date in value, and pressing one selects that date. 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, so they stay in the grid with a line through the number and can't be selected, while the 4th starts selected. isDateUnavailable returns true for each of them. 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 line means.

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. The cells are written out by hand inside CalendarContext, from calendar.weeks, so each one can hold more than its number. 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, headed Wk, runs down the left of the grid, with the 12th of this month selected, and showWeekNumbers turns it on. Each number is the ISO week holding most of its row, so a row that starts on Sunday takes its Monday's week. Use it where people plan in weeks, such as sprints or school terms.

Preview width

Multiple

The 4th, 12th and 18th of this month start selected, and with selectionMode 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, inside a LocaleProvider with the ar-SA locale, and today selected. The provider sets lang and dir on an element around the calendar, so 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.

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?

Bind it with bind:value, or read it in onValueChange, which receives the value first and the details second. One day is a DateValue, or null before one is picked, a range is a two-item array and multiple gives an array.

A DateValue is a date with no time attached. Call toString() on one for a string such as 2026-11-11 to send to a server, or toDate() when you need a JavaScript Date.

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

Set selectionMode to range for a start and an end, or to multiple for separate days. A range is a two-item array of sorted dates, and multiple an array of any number, which maxSelectedDates caps: a click past it is ignored until a day is taken out. Set numOfMonths to 2 and add a second table for the next month 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 isDateUnavailable, a function that gets each DateValue and returns true for a day that can't be picked. Set min to close off everything before a date, today for example, and max for everything after one. Those days stay in the grid and can't be selected, as in the Booked dates demo, and the arrow keys still stop on them, so keyboard users hear that they're unavailable.

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

Put CalendarMonthSelect and CalendarYearSelect in the control row, as the Caption demo does, so nobody pages back month by month. Without min or max the year menu lists ten years either side of the year shown, so for a birth date set max to today and min to the earliest date that makes sense, and the menu runs between their years.

How do I start the Calendar week on Monday?

Set startOfWeek to 1, counting from 0 for Sunday. Without it the first day comes from locale, else from the page's lang, so an English page starts its weeks on Sunday and a German one on Monday. The weekday headers and every row follow it, while the Week numbers column counts ISO weeks either way.

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

It shouldn't: a DateValue has no time, so a date made with parseDate is the same day everywhere. Today's marker and the Today button follow timeZone, the reader's own zone unless you pass one, so they match the reader's clock. Pass timeZone to tie them to one zone instead.

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, while the months keep their Gregorian lengths. That's why this page has no Hijri demo on UI SDK. For a real Persian or Islamic month in Svelte, use this component on Ark UI.

API Reference

Calendar

<div> data-slot="calendar"

PropType
month?Date

The month shown first. Pass it with onMonthChange to control it. Two-way with bind:month.

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?Snippet

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
class?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 }
class?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