---
title: "Calendar"
description: "A calendar component that allows users to select a date or a range of dates."
component: true
---

```tsx
import { createSignal } from "solid-js"

import { Calendar } from "~/components/ui/calendar"
export default function CalendarDemo() {
  const [value, setValue] = createSignal<string | null>("2026-11-17")
  return (
    <div class="grid gap-3">
      <Calendar
        value={value()}
        onValueChange={(v) => setValue(typeof v === "string" ? v : null)}
        defaultMonth="2026-11"
        today="2026-11-17"
        class="rounded-md border"
      />
      <output class="text-center text-sm">{value() ?? "Choose a day"}</output>
    </div>
  )
}
```

## Installation

<CodeTabs>

<TabsList>
  <TabsTrigger value="cli">Command</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>

<TabsContent value="cli">

```bash
npx solidui-cli@latest add calendar
```

</TabsContent>

<TabsContent value="manual">

<Steps class="mb-0 pt-2">

<Step>Install the following dependencies:</Step>

```bash
npm install @ui-sdk/solid @ui-sdk/core
```

<Step>Copy and paste the following code into your project.</Step>

```tsx title="components/ui/calendar.tsx"
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import type { ComponentProps } from "@solidjs/web"
import {
  Calendar as SdkCalendar,
  CalendarPrevious as SdkCalendarPrevious,
  CalendarNext as SdkCalendarNext,
  CalendarHeading as SdkCalendarHeading,
  CalendarGrid as SdkCalendarGrid,
  CalendarWeekday as SdkCalendarWeekday,
  CalendarDay as SdkCalendarDay,
  CalendarMonthSelect as SdkCalendarMonthSelect,
  CalendarYearSelect as SdkCalendarYearSelect,
  type CalendarSelectState
} from "@ui-sdk/solid/calendar"
import {
  CalendarWeekdays as SdkCalendarWeekdays,
  CalendarWeeks as SdkCalendarWeeks
} from "@ui-sdk/solid/calendar"
import { For, omit, Show } from "solid-js"

import { cn } from "~/lib/utils"

export function CalendarRoot(
  props: Omit<ComponentProps<typeof SdkCalendar>, "class"> & { class?: string }
) {
  return <SdkCalendar {...props} class={cn("p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(7)] w-fit", props.class)} />
}

export function CalendarPrevious(
  props: Omit<ComponentProps<typeof SdkCalendarPrevious>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarPrevious
      {...props}
      class={cn(
        "inline-flex size-(--cell-size) items-center justify-center rounded-md hover:bg-muted disabled:opacity-50",
        props.class
      )}
    >
      {props.children ?? (
        <svg
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
          class="size-4 rtl:rotate-180"
        >
          <path d="m15 18-6-6 6-6" />
        </svg>
      )}
    </SdkCalendarPrevious>
  )
}

export function CalendarNext(
  props: Omit<ComponentProps<typeof SdkCalendarNext>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarNext
      {...props}
      class={cn(
        "inline-flex size-(--cell-size) items-center justify-center rounded-md hover:bg-muted disabled:opacity-50",
        props.class
      )}
    >
      {props.children ?? (
        <svg
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
          class="size-4 rtl:rotate-180"
        >
          <path d="m9 18 6-6-6-6" />
        </svg>
      )}
    </SdkCalendarNext>
  )
}

export function CalendarHeading(
  props: Omit<ComponentProps<typeof SdkCalendarHeading>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarHeading
      {...props}
      class={cn(
        "h-6 pr-1 pl-1.5 flex-1 text-center text-sm font-medium",
        props.class
      )}
    />
  )
}

function renderCalendarSelect(
  select: Record<string, unknown>,
  state: CalendarSelectState
) {
  return (
    <span class="border border-input has-focus:border-ring has-focus:ring-3 has-focus:ring-ring/50 relative rounded-(--cell-radius)">
      <select {...select} />
      <span
        aria-hidden="true"
        class="h-6 pr-1 pl-1.5 flex items-center gap-1 rounded-(--cell-radius) text-sm font-medium select-none [&>svg]:size-3.5 [&>svg]:text-muted-foreground"
      >
        {state.options.find((option) => option.value === state.value)?.label ??
          state.value}
        <svg
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
        >
          <path d="m6 9 6 6 6-6" />
        </svg>
      </span>
    </span>
  )
}

export function CalendarMonthSelect(
  props: Omit<ComponentProps<typeof SdkCalendarMonthSelect>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarMonthSelect
      aria-label="Month"
      render={renderCalendarSelect}
      {...props}
      class={cn("absolute inset-0 bg-popover opacity-0", props.class)}
    />
  )
}

export function CalendarYearSelect(
  props: Omit<ComponentProps<typeof SdkCalendarYearSelect>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarYearSelect
      aria-label="Year"
      render={renderCalendarSelect}
      {...props}
      class={cn("absolute inset-0 bg-popover opacity-0", props.class)}
    />
  )
}

export function CalendarGrid(
  props: Omit<ComponentProps<typeof SdkCalendarGrid>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarGrid
      {...props}
      class={cn("w-full border-collapse", props.class)}
    />
  )
}

export function CalendarWeekday(
  props: Omit<ComponentProps<typeof SdkCalendarWeekday>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarWeekday
      {...props}
      class={cn(
        "text-xs h-(--cell-size) font-normal text-muted-foreground",
        props.class
      )}
    />
  )
}

export function CalendarDayButton(
  props: Omit<ComponentProps<typeof SdkCalendarDay>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarDay
      {...props}
      class={cn(
        "size-(--cell-size) rounded-(--cell-radius) text-center text-sm outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring data-outside:text-muted-foreground data-range-end:not-data-range-start:rounded-s-none data-range-middle:rounded-none data-range-start:not-data-range-end:rounded-e-none data-today:font-bold data-[selected]:bg-primary data-[selected]:text-primary-foreground data-disabled:opacity-40",
        props.class
      )}
    />
  )
}

export function CalendarMonth(props: { offset?: number }) {
  return (
    <CalendarGrid offset={props.offset ?? 0}>
      <SdkCalendarWeekdays>
        {(index) => <CalendarWeekday index={index} />}
      </SdkCalendarWeekdays>
      <SdkCalendarWeeks>
        {(cell) => <CalendarDayButton value={cell.date} />}
      </SdkCalendarWeeks>
    </CalendarGrid>
  )
}

export function Calendar(
  props: ComponentProps<typeof CalendarRoot> & {
    captionLayout?: "label" | "dropdown"
  }
) {
  const rest = omit(props, "children", "captionLayout")
  return (
    <CalendarRoot {...rest}>
      {props.children ?? (
        <>
          <div class="flex items-center">
            <CalendarPrevious />
            <Show
              when={props.captionLayout === "dropdown"}
              fallback={<CalendarHeading />}
            >
              <div class="flex flex-1 items-center justify-center gap-1.5">
                <CalendarMonthSelect />
                <CalendarYearSelect />
              </div>
            </Show>
            <CalendarNext />
          </div>
          <div class="flex gap-4">
            <For each={Array.from({ length: props.months ?? 1 }, (_, i) => i)}>
              {(offset) => <CalendarMonth offset={offset} />}
            </For>
          </div>
        </>
      )}
    </CalendarRoot>
  )
}
```

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</CodeTabs>

## Usage

```tsx showLineNumbers
import { Calendar } from "~/components/ui/calendar"
```

```tsx showLineNumbers
<Calendar aria-label="Select a date" />
```

Dates use ISO strings, such as `"2026-11-17"`. Set `mode` to `single`, `multiple`, or `range`. `onValueChange` receives the ISO value. Use `months` for multiple grids and `min`, `max`, or `unavailable` for restrictions. The SDK renders focusable table cells, so days do not contain extra buttons.

See the [UI SDK calendar API](https://ui-sdk.dev/docs/solid/components/calendar) for native options and keyboard behavior.

## About

The `Calendar` component styles the grid, day cells, and navigation from [UI SDK Calendar](https://ui-sdk.dev/docs/solid/components/calendar).

## Date Picker

You can use the `<Calendar>` component to build a date picker. See the [Date Picker](/docs/components/date-picker) page for more information.

## Persian / Hijri / Jalali Calendar

The upstream example uses a Persian calendar with right-to-left layout.

## Selected Date (With TimeZone)

The Calendar component accepts a `timeZone` prop to ensure dates are displayed and selected in the user's local timezone.

**Note:** If you notice a selected date offset (for example, selecting the 20th highlights the 19th), make sure the `timeZone` prop is set to the user's local timezone.

The SDK uses `timeZone` to determine today. Without it, the SDK reads the browser time zone after hydration.

## Basic

A basic calendar styled with `class="rounded-lg border"`.

```tsx
import { Calendar } from "~/components/ui/calendar"

export default function CalendarBasic() {
  return <Calendar aria-label="Select a date" class="rounded-lg border" />
}
```

## Range Calendar

Use the `mode="range"` prop to enable range selection.

```tsx
import { Calendar } from "~/components/ui/calendar"
export default function CalendarRange() {
  return (
    <Calendar
      mode="range"
      defaultValue={["2026-11-17", "2026-11-22"]}
      defaultMonth="2026-11"
      today="2026-11-17"
      months={2}
      class="max-w-full overflow-auto rounded-md border"
    />
  )
}
```

## Month and Year Selector

Set `captionLayout="dropdown"` to change the visible month with month and year dropdowns.

```tsx
import { Calendar } from "~/components/ui/calendar"

export default function CalendarCaption() {
  return (
    <Calendar
      aria-label="Choose date"
      defaultMonth="2026-11"
      captionLayout="dropdown"
      class="rounded-lg border"
    />
  )
}
```

## Presets

```tsx
import { createSignal, For } from "solid-js"

import { Button } from "~/components/ui/button"
import { Calendar } from "~/components/ui/calendar"

const presets = [
  { label: "Today", days: 0 },
  { label: "Tomorrow", days: 1 },
  { label: "In 3 days", days: 3 },
  { label: "In a week", days: 7 },
  { label: "In 2 weeks", days: 14 }
]
const today = "2026-11-18"

export default function CalendarPresets() {
  const [value, setValue] = createSignal<string | null>(today)
  const [month, setMonth] = createSignal(today.slice(0, 7))
  const choose = (days: number) => {
    const date = new Date(today)
    date.setUTCDate(date.getUTCDate() + days)
    const next = date.toISOString().slice(0, 10)
    setValue(next)
    setMonth(next.slice(0, 7))
  }

  return (
    <div class="flex flex-col items-stretch gap-2 rounded-lg border p-2">
      <Calendar
        aria-label="Choose date"
        value={value()}
        month={month()}
        onMonthChange={setMonth}
        onValueChange={(next) =>
          setValue(typeof next === "string" ? next : null)
        }
      />
      <div class="flex max-w-72 flex-wrap gap-1">
        <For each={presets}>
          {(preset) => (
            <Button
              variant="outline"
              size="sm"
              onClick={() => choose(preset.days)}
            >
              {preset.label}
            </Button>
          )}
        </For>
      </div>
    </div>
  )
}
```

## Date and Time Picker

```tsx
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.

import { Calendar } from "~/components/ui/calendar"
import { Field, FieldGroup, FieldLabel } from "~/components/ui/field"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput
} from "~/components/ui/input-group"

export default function CalendarTime() {
  return (
    <div class="grid max-w-64 gap-3 rounded-lg border p-3">
      <Calendar
        aria-label="Appointment date"
        defaultValue="2026-11-18"
        defaultMonth="2026-11"
      />
      <FieldGroup>
        <Field>
          <FieldLabel for="time-from">Start Time</FieldLabel>
          <InputGroup>
            <InputGroupInput id="time-from" type="time" defaultValue="10:30" />
            <InputGroupAddon>
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <circle cx="12" cy="12" r="10" />
                <path d="M12 6v6l4 2" />
              </svg>
            </InputGroupAddon>
          </InputGroup>
        </Field>
        <Field>
          <FieldLabel for="time-to">End Time</FieldLabel>
          <InputGroup>
            <InputGroupInput id="time-to" type="time" defaultValue="12:30" />
            <InputGroupAddon>
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <circle cx="12" cy="12" r="10" />
                <path d="M12 6v6l4 2" />
              </svg>
            </InputGroupAddon>
          </InputGroup>
        </Field>
      </FieldGroup>
    </div>
  )
}
```

## Booked dates

```tsx
import { Calendar } from "~/components/ui/calendar"

const booked = ["2026-11-07", "2026-11-15", "2026-11-21", "2026-11-28"]

export default function CalendarBookedDates() {
  return (
    <div class="grid gap-2">
      <Calendar
        aria-label="Book an appointment"
        unavailable={booked}
        defaultMonth="2026-11"
        class="rounded-lg border"
      />
      <p class="text-center text-xs text-muted-foreground">
        Booked dates are unavailable.
      </p>
    </div>
  )
}
```

## Custom Cell Size

```tsx
import {
  CalendarWeeks as SdkCalendarWeeks,
  CalendarWeekdays as SdkCalendarWeekdays
} from "@ui-sdk/solid/calendar"

import {
  Calendar,
  CalendarDayButton,
  CalendarGrid,
  CalendarHeading,
  CalendarNext,
  CalendarPrevious,
  CalendarWeekday
} from "~/components/ui/calendar"

function isWeekend(date: string) {
  return [0, 6].includes(new Date(date).getUTCDay())
}

export default function CalendarCustomDays() {
  return (
    <Calendar
      mode="range"
      defaultValue={["2026-11-15", "2026-11-22"]}
      defaultMonth="2026-11"
      class="rounded-lg border"
    >
      <div class="flex items-center">
        <CalendarPrevious />
        <CalendarHeading />
        <CalendarNext />
      </div>
      <CalendarGrid>
        <SdkCalendarWeekdays>
          {(index) => <CalendarWeekday index={index} />}
        </SdkCalendarWeekdays>
        <SdkCalendarWeeks>
          {(cell) => (
            <CalendarDayButton
              value={cell.date}
              class={isWeekend(cell.date) ? "text-destructive" : ""}
            />
          )}
        </SdkCalendarWeeks>
      </CalendarGrid>
    </Calendar>
  )
}
```

Set `--cell-size` to a fixed value or use responsive utilities such as `[--cell-size:2rem] sm:[--cell-size:2.5rem]`.

## Week Numbers

Add a column to the calendar grid to display ISO week numbers.

```tsx
import { For, Show } from "solid-js"

import {
  Calendar,
  CalendarDayButton,
  CalendarGrid,
  CalendarHeading,
  CalendarNext,
  CalendarPrevious,
  CalendarWeekday
} from "~/components/ui/calendar"
import { Card, CardContent } from "~/components/ui/card"

function weekNumber(date: string | undefined) {
  if (!date) return
  const thursday = new Date(date)
  thursday.setUTCDate(thursday.getUTCDate() + 4 - (thursday.getUTCDay() || 7))
  const newYear = Date.UTC(thursday.getUTCFullYear(), 0, 1)
  return Math.ceil((thursday.getTime() - newYear + 86_400_000) / 604_800_000)
}

export default function CalendarWeekNumbers() {
  return (
    <Card class="mx-auto w-fit p-0">
      <CardContent class="p-0">
        <Calendar
          defaultMonth="2026-02"
          defaultValue="2026-02-03"
          weekStartsOn={1}
        >
          <div class="flex items-center">
            <CalendarPrevious />
            <CalendarHeading />
            <CalendarNext />
          </div>
          <CalendarGrid>
            {(grid) => (
              <>
                <thead>
                  <tr>
                    <th scope="col" class="w-(--cell-size)">
                      <span class="sr-only">Week number</span>
                    </th>
                    <For each={grid.weekdays} keyed={false}>
                      {(_, index) => <CalendarWeekday index={index} />}
                    </For>
                  </tr>
                </thead>
                <tbody>
                  <For each={grid.weeks} keyed={(week) => week[0]?.date}>
                    {(week) => (
                      <tr>
                        <th
                          scope="row"
                          class="text-xs font-normal text-muted-foreground"
                        >
                          {weekNumber(week()[0]?.date)}
                        </th>
                        <For each={week()} keyed={(day) => day.date}>
                          {(day) => (
                            <Show when={!day().hidden} fallback={<td />}>
                              <CalendarDayButton value={day().date} />
                            </Show>
                          )}
                        </For>
                      </tr>
                    )}
                  </For>
                </tbody>
              </>
            )}
          </CalendarGrid>
        </Calendar>
      </CardContent>
    </Card>
  )
}
```

## API Reference

See the [UI SDK Calendar API](https://ui-sdk.dev/docs/solid/components/calendar) for supported options and slot states.

## Changelog
