Calendar Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Let the user pick a date from a month grid. value holds the picked date in ISO 8601, like 2026-10-29, and the valuechange event fires after each pick.
value:
<div class="calendar-basic"> <sv-calendar aria-label="Date"></sv-calendar> <p> value: <code></code> </p></div>
<script type="application/x-typescript" module> const calendar = document.querySelector<Calendar>(".calendar-basic sv-calendar")!; const valueOutput = document.querySelector(".calendar-basic code")!;
calendar.addEventListener("valuechange", () => { valueOutput.textContent = JSON.stringify(calendar.value); });
valueOutput.textContent = JSON.stringify(calendar.value);</script>
<style> .calendar-basic { display: grid; gap: 1em; place-content: center; justify-items: center;
p { margin: 0; font-size: 0.9em; color: var(--sv-gray-3); } }</style>Limits
Stop the user from picking past dates, dates too far ahead, or weekends. min and max set the range of dates the user can pick and move to, and the isDateDisabled function blocks single days.
Since new Date("2026-10-29") is midnight UTC, the weekday check reads it with getUTCDay().
<div class="calendar-limits"> <sv-calendar aria-label="Appointment date"></sv-calendar></div>
<script type="application/x-typescript" module> const calendar = document.querySelector<Calendar>(".calendar-limits sv-calendar")!;
const now = new Date(); const today = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()));
function getDateAfterToday(dayCount: number) { const date = new Date(today); date.setUTCDate(date.getUTCDate() + dayCount); return date.toISOString().slice(0, 10); }
calendar.min = getDateAfterToday(1); calendar.max = getDateAfterToday(45);
calendar.isDateDisabled = date => { const weekday = new Date(date).getUTCDay(); return weekday === 0 || weekday === 6; };</script>
<style> .calendar-limits { display: grid; place-content: center; }</style>Marked Days
Highlight holidays or show a dot on days with events. The getDayParts function adds part names to a day, and ::part(day holiday) or ::part(day deadline)::after styles them.
Since the calendar cannot tell when the data behind getDayParts changes, assign the function again after a change.
- Holiday
- Deadline
<div class="calendar-marked-days"> <sv-calendar aria-label="Team calendar"></sv-calendar> <ul> <li class="holiday-key">Holiday</li> <li class="deadline-key">Deadline</li> </ul></div>
<script type="application/x-typescript" module> const calendar = document.querySelector<Calendar>(".calendar-marked-days sv-calendar")!;
const now = new Date(); const today = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()));
function getDateAfterToday(dayCount: number) { const date = new Date(today); date.setUTCDate(date.getUTCDate() + dayCount); return date.toISOString().slice(0, 10); }
const holidayDates = [-3, 9, 23].map(getDateAfterToday); const deadlineDates = [2, 6, 13, 20, 34].map(getDateAfterToday);
calendar.getDayParts = date => { const dayPartNames = [ holidayDates.includes(date) && "holiday", deadlineDates.includes(date) && "deadline", ];
return dayPartNames.filter(Boolean).join(" "); };</script>
<style> .calendar-marked-days { display: grid; gap: 1em; justify-items: center;
sv-calendar::part(day holiday) { color: var(--sv-error); }
sv-calendar::part(day deadline) { position: relative; }
sv-calendar::part(day deadline)::after { position: absolute; inset-block-end: 0.1em; inset-inline-start: calc(50% - 0.125em); inline-size: 0.25em; block-size: 0.25em; content: ""; background-color: var(--sv-accent); border-radius: 50%; }
sv-calendar::part(day deadline selected)::after { background-color: currentcolor; }
ul { display: flex; gap: 1.5em; padding: 0; margin: 0; font-size: 0.85em; color: var(--sv-gray-3); list-style: none; }
li::before { display: inline-block; inline-size: 0.6em; block-size: 0.6em; margin-inline-end: 0.4em; content: ""; border-radius: 50%; }
.holiday-key::before { background-color: var(--sv-error); }
.deadline-key::before { background-color: var(--sv-accent); } }</style>Custom Looks
Restyle the calendar as a bordered card with round day cells and a range pick. selection-mode="range" picks a range of days, the --sv-calendar-* tokens set the radius, colors, and cell gap, and ::part(header), ::part(weekday), and ::part(today) style the rest.
<div class="calendar-variants"> <sv-calendar aria-label="Date" selection-mode="range" weekday-format="narrow"></sv-calendar></div>
<style> .calendar-variants { display: grid; justify-items: center;
sv-calendar { --sv-calendar-bdr-rad: 999px; --sv-calendar-active-bg: var(--sv-gray-1); --sv-calendar-active-clr: var(--sv-gray-7); --sv-calendar-range-bg: var(--sv-gray-5); --sv-calendar-cell-gap: 0;
padding: 0.5em; background-color: var(--sv-gray-7); border: 1px solid var(--sv-gray-5); border-radius: var(--sv-bdr-rad-lg);
&::part(header) { padding-block-end: 0.5em; border-block-end: 1px solid var(--sv-gray-5); }
&::part(weekday) { font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
&::part(today) { text-decoration: underline 2px; text-underline-offset: 0.3em; } } }</style>Animation
Slide the new month in from the direction the user moved. A @starting-style rule on ::part(grid) animates the new grids in, and the --forward and --backward states give the direction.
This animation will not play for you because your system is set to reduce motion.
<div class="calendar-month-slide"> <sv-calendar aria-label="Date"></sv-calendar></div>
<style> .calendar-month-slide { display: grid; place-content: center;
sv-calendar::part(body) { overflow: clip; }
sv-calendar::part(grid) { transition: opacity 250ms, translate 300ms cubic-bezier(0.16, 1, 0.3, 1);
@starting-style { opacity: 0; } }
sv-calendar:state(--forward)::part(grid) { @starting-style { translate: 2em 0; } }
sv-calendar:state(--backward)::part(grid) { @starting-style { translate: -2em 0; } }
@media (prefers-reduced-motion: reduce) { sv-calendar::part(grid) { transition: none; } } }</style>