Standalone calendar display with events, multi-select, range picking, date constraints, form integration, multi-month view, and expressive theming.
Overview
The <calendar-wc> component displays a month grid for viewing events, availability, or annotations on dates. It supports single, range, and multi-date selection, date constraints, form integration via ElementInternals, multi-month display, and locale-aware rendering.
12345
<calendar-wc data-month="4" data-year="2026" data-events='{"2026-04-10":"Sprint review","2026-04-15":"Deadline"}' data-selection="single"></calendar-wc>
Attributes
| Attribute |
Type |
Default |
Description |
data-month |
number (1-12) |
current |
Month to display. Observed: changing it re-renders. The component reflects the visible month back here as you navigate. |
data-year |
number |
current |
Year to display. Observed, and reflected like data-month. |
data-events |
JSON |
— |
Event data keyed by start ISO date. Values: string, object { label, color, icon, time, end, days }, or array. See Multi-day events. Observed: changing it re-renders and fires calendar-wc:events-changed with source: 'attribute'. |
data-selection |
string |
"none" |
Selection mode: "none", "single", "range", or "multi". |
data-disabled-dates |
string |
— |
Comma-separated ISO dates to disable. |
data-highlight-dates |
string |
— |
Comma-separated ISO dates to highlight, optionally with :category. |
data-size |
string |
"default" |
Size variant: "compact", "default", or "large". |
data-min-date |
ISO date |
— |
Earliest selectable/navigable date. |
data-max-date |
ISO date |
— |
Latest selectable/navigable date. |
data-months |
number (1-12) |
1 |
Number of months to display side by side. |
data-year-range |
number (0-200) |
10 |
Years listed either side of the current year in the year select. data-min-date and data-max-date bound a side instead, and the displayed year is always listed. Use a larger range for birth dates or archives. |
data-heading-level |
number (1-6) |
— |
In multi-month views, render each month title as <h1>–<h6> at this level. Without it the titles are plain text (each grid is still labelled by its month), because the component cannot know where it sits in your page outline. |
data-label-prev, data-label-next, data-label-year, data-label-close |
string |
English |
Accessible names for the previous/next buttons, the year select, and the day-detail close button. See Localization. |
data-label-more |
string |
"+{n} more" |
Large-view overflow text; {n} is replaced with the hidden event count. |
name |
string |
— |
Form field name. When set with a selection mode, the calendar participates in native form submission. |
data-month, data-year and data-events are observed. The other attributes are read when the element connects (and again if it is moved or re-inserted); change them, then call refresh() or re-insert the element.
Selection Modes
Single selection
Click a date to select it. Fires calendar:select with the selected ISO date.
1
<calendar-wc data-selection="single"></calendar-wc>
Range selection
Click two dates to define a range. A hover preview shows between start and cursor. The value uses ISO 8601 interval format: YYYY-MM-DD/YYYY-MM-DD. During selection, the host element gets a data-tentative attribute with the start date.
12345
<calendar-wc data-selection="range" data-min-date="2026-04-01" data-max-date="2026-04-30"></calendar-wc>
Multi-select
Click dates to toggle them on or off. Selected dates are returned as space-separated ISO strings.
1234567
<calendar-wc data-selection="multi"></calendar-wc> <script> cal.addEventListener('calendar:select', (e) => { console.log(e.detail.values); });</script>
Date Constraints
Use data-min-date and data-max-date to constrain navigation and disable out-of-range dates. Navigation buttons and the year dropdown respect these boundaries. Constraints work alongside data-disabled-dates and the isDateDisallowed callback — all three are additive.
12345
<calendar-wc data-min-date="2026-04-01" data-max-date="2026-06-30" data-disabled-dates="2026-05-01,2026-05-25"></calendar-wc>
Multi-Month Display
Set data-months (1–12) to show multiple months in a responsive grid. Navigation shifts by one month at a time. All features (selection, events, highlights) work across all visible months.
Grid Layouts
The grid adapts its column count based on the number of months. On narrow containers, columns reduce responsively.
| data-months | Layout | Use case |
2 | 2 columns | Range picker |
3 | 3 columns | Quarter preview |
4 | 2×2 grid | Quarter view |
6 | 3×2 grid | Half-year |
12 | 4×3 grid | Yearly overview |
12345678
<calendar-wc data-months="2" data-selection="range"></calendar-wc> <calendar-wc data-months="4" data-selection="multi"></calendar-wc> <calendar-wc data-months="12" data-size="compact"></calendar-wc>
Form Integration
When a name attribute is set and a selection mode is active, the calendar participates in native form submission via ElementInternals. No hidden input needed.
123456789101112
<form> <calendar-wc name="event-date" data-selection="single"></calendar-wc> <button type="submit">Submit</button></form> <script> form.addEventListener('submit', (e) => { e.preventDefault(); const data = new FormData(e.target); console.log(data.get('event-date')); });</script>
JavaScript Properties
| Property | Type | Description |
.value |
string | null |
Selected value. ISO date (single), ISO interval (range), space-separated ISOs (multi), or null. |
.isDateDisallowed |
(date: Date) => boolean |
Callback to dynamically disable dates. Called per cell during render. Additive with attribute-based constraints. |
.getDayParts |
(date: Date) => string | string[] | null |
Inject custom data-day-part attributes per cell for CSS targeting. |
.events |
{ [iso]: Event[] } | Event[] |
Live event data. Accepts the date-keyed object that data-events uses, OR a flat array of events with a date field (auto-grouped). Triggers re-render and fires calendar-wc:events-changed with source: 'property'. Reading always returns the date-keyed shape. Once set, a later reconnect does not re-read data-events over it. |
Methods
| Method | Description |
refresh() |
Re-render the current view. Setting .isDateDisallowed, .getDayParts or .events already re-renders; call this when the data a callback reads has changed. |
Reactive events (JS-first)
12345678910111213141516
const cal = document.querySelector('calendar-wc'); await new Promise(r => cal.addEventListener('calendar-wc:upgraded', r, { once: true })); cal.events = [ { id: 'mtg-1', date: '2026-04-10', label: 'Standup', time: '09:00' }, { id: 'mtg-2', date: '2026-04-10', label: 'Review', time: '14:00' }, { id: 'mtg-3', date: '2026-04-12', label: 'All-hands', time: '15:30' },]; cal.addEventListener('calendar-wc:events-changed', (e) => { if (e.detail.source === 'attribute') syncStore(e.detail.events);});
See the Data API concepts guide for the dual-mode contract.
isDateDisallowed
12345
const cal = document.querySelector('calendar-wc');cal.isDateDisallowed = (date) => { const day = date.getDay(); return day === 0 || day === 6; };
getDayParts
Return a string or array of strings to add as data-day-part on the cell's <td>. Style with attribute selectors in CSS.
123456
cal.getDayParts = (date) => { const parts = []; if (date.getDay() === 0 || date.getDay() === 6) parts.push('weekend'); if (date.getDate() === 15) parts.push('payday'); return parts.length ? parts : null;};
123456
calendar-wc td[data-day-part~="weekend"] button { background: oklch(from var(--color-primary) l c h / 0.08);}calendar-wc td[data-day-part~="payday"] button { border: 2px solid var(--color-success);}
Events
| Event |
Detail |
Description |
calendar:select |
{ value, date } (single), { value, start, end } (range), { values, dates } (multi) |
Fired when selection changes. |
calendar:navigate |
{ year, month } |
Fired on month navigation. |
calendar:day-open |
{ date, events } |
Fired when day detail overlay opens (display-only mode). |
calendar-wc:events-changed |
{ events, source } |
Fired after the event data changes. source is 'property' (the .events setter) or 'attribute' (data-events changed). |
calendar-wc:upgraded |
— |
Fired once the calendar has rendered (every connect). |
Size Variants
Three sizes adapt the calendar to different contexts.
| Size | Max Width | Events | Use Case |
compact | 16rem | Dot indicators | Sidebars, cards |
default | 22rem | Dot indicators | Standard display |
large | 56rem | Labels with icons | See Large View below |
Large View
Large mode (data-size="large") transforms the calendar into a full-page schedule view with rich event display. Instead of dot indicators, events render as labeled chips with icons and times. Container queries drive responsive cell sizing with near-square proportions.
Event Labels
In large mode, each cell shows up to 2 event chips inline. Events beyond 2 collapse into a "+N more" overflow indicator. Each chip displays the label, optional time, and optional icon.
1234567
<calendar-wc data-size="large" data-events='{ "2026-04-10": [ {"label": "Standup", "time": "09:00", "icon": "users"}, {"label": "Demo day", "time": "15:00", "icon": "presentation"}, {"label": "Team dinner", "time": "18:30", "icon": "utensils"} ]}'></calendar-wc>
Day Detail Overlay
In display-only mode (data-selection="none"), clicking a date with events — or pressing Enter / Space on it — opens a positioned, non-modal dialog showing the full event list. If any events have a time property, an hour-grid timeline (<day-view> of <calendar-event>s) renders instead. Focus moves to the dialog's close button when it opens. Escape (while focus is inside the calendar) or the close button closes it and returns focus to the day; clicking outside closes it without moving focus.
Watermark Day Numbers
Large cells display a subtle background day number (watermark) via ::before. Control its appearance with these tokens:
| Token | Default | Purpose |
--cal-watermark-opacity | 0.05 | Background number opacity |
--cal-watermark-color | var(--color-text) | Background number color |
--cal-watermark-size | 3rem | Background number font size |
--cal-watermark-weight | 800 | Background number font weight |
Multi-day Events
Add end (inclusive ISO date) or days (a count of 1 or more) to an event object to make it span several days. end wins if both are present. In data-size="large" spans render as continuous bars across each week row; in compact and default sizes they add a dot to every day they cover, and every covered day opens the span in the day detail.
1234
<calendar-wc data-size="large" data-month="4" data-year="2026" data-events='{ "2026-04-06": { "label": "Sprint 12", "end": "2026-04-17" }, "2026-04-13": { "label": "QA conference", "days": 3 }}'></calendar-wc>
Event Dots
Pass event data as JSON to show dot indicators on dates. Each date can have a string, object with label/color/icon/time, or array of those.
12345678
<calendar-wc data-events='{ "2026-04-10": "Team meeting", "2026-04-15": { "label": "Tax deadline", "color": "var(--color-error)" }, "2026-04-21": [ { "label": "Morning standup", "time": "09:00", "icon": "users" }, { "label": "Sprint review", "time": "14:00" } ]}'></calendar-wc>
Localization
The locale is the nearest lang attribute (on the element or an ancestor), falling back to the browser language. It drives weekday headers, month names, grid labels, the day-detail title, time labels, and the first day of the week (from Intl.Locale week info).
1234567
<calendar-wc lang="fr" data-label-prev="Mois précédent" data-label-next="Mois suivant" data-label-year="Année" data-label-close="Fermer" data-label-more="+{n} de plus"></calendar-wc>
The few built-in UI strings (button names, the "+N more" overflow) default to English; translate them with the data-label-* attributes.
Keyboard
| Key | Action |
| Arrow Left / Arrow Right | Move focus one day (mirrored in right-to-left layouts). Disabled days are skipped; the view follows into adjacent months. |
| Arrow Up / Arrow Down | Move focus one week. |
| Home / End | Move focus to the first or last day of the week row within the month. |
| Page Up / Page Down | Move focus to the same day in the previous or next month. The day is clamped to the length of the month. |
| Shift + Page Up / Page Down | Move focus to the same day in the previous or next year. |
| Enter / Space | Select the focused date, or in display mode open its day detail. |
| Escape | Close the day detail and return focus to the day. |
Calendar vs Date Picker
| Component | Purpose | Form input? |
<date-picker> |
Pick a single date via popover input |
Yes (ElementInternals) |
<calendar-wc> |
Display events, availability, ranges, multi-select |
Yes (when name attribute is set) |
Theming
The calendar exposes 27 CSS custom properties for expressive theming — from paper wall calendars to bold geometric styles. Every token defaults to transparent or the base appearance, so they are fully opt-in. Themes set them via [data-theme~="name"] calendar-wc { ... } selectors.
Banner
| Token | Default | Purpose |
--cal-banner-height | 0px | Banner strip height (0 hides it) |
--cal-banner-bg | transparent | Background color or gradient |
--cal-banner-image | none | Background image |
--cal-banner-size | cover | Background-size |
--cal-banner-position | center | Background-position |
Header and Week Rows
| Token | Default | Purpose |
--cal-header-bg | var(--color-surface-raised) | Navigation header background |
--cal-header-color | inherit | Navigation header text |
--cal-week-bg | transparent | Week row background |
--cal-week-bg-alt | transparent | Alternating even-row tint |
Day Cells
| Token | Default | Purpose |
--cal-day-bg | transparent | Day cell background |
--cal-day-image | none | Decoration layer image (stickers) |
--cal-day-image-size | contain | Decoration background-size |
--cal-day-image-opacity | 1 | Decoration opacity |
Today, Disabled, Outside
| Token | Default | Purpose |
--cal-today-bg | var(--color-surface-raised) | Today cell background |
--cal-today-border | var(--color-border-strong) | Today cell border |
--cal-today-shadow | none | Today cell glow or shadow |
--cal-disabled-opacity | 0.5 | Disabled day opacity |
--cal-outside-opacity | 0.35 | Outside-month day opacity |
--cal-outside-color | var(--color-text-muted) | Outside-month text color |
Highlight
| Token | Default | Purpose |
--cal-highlight-bg | interactive tint | Highlighted date background |
--cal-highlight-border | interactive tint | Highlighted date border |
Accessibility
- Each month is a
<table role="grid"> labelled with its localized month and year; each day is a <button> inside the gridcell.
- Exactly one day button across all visible months is in the tab order (roving
tabindex): the last focused day, else the selection, else today, else the first enabled day.
- Today carries
aria-current="date"; disabled days are disabled buttons with aria-disabled="true".
- In selection modes,
aria-selected is set on the gridcell (<td>) — true for selected or in-range days, false otherwise — and multi/range grids carry aria-multiselectable="true". Display-only grids have no selection state.
- The month header uses
aria-live="polite" for navigation announcements.
- The day detail is a non-modal
role="dialog" named by its date heading; focus moves in on open and back to the day on close.