Back to Blog
Code on computer screen
Design
9 min read

Tailwind Calendar Component: Style a JS Calendar With Tailwind

By SimpleCalendarJS Team

SimpleCalendarJS~14 KB gzipped · Zero dependencies · Any framework
Short answer

Calendar components render their own DOM, so Tailwind utility classes can't reach the elements inside them. Map your Tailwind v4 theme variables onto the calendar's CSS custom properties instead. Load its stylesheet unlayered so Preflight can't override it, and keep the utilities for the wrapper, the toolbar and the page around it.

You've built the whole app in Tailwind, and then the calendar shows up with its own fonts, its own blue and its own border radius. Searching for a tailwind calendar component gets you three kinds of answer: hand-built markup with no date logic, React-only components you style through a classNames prop, and full calendar libraries with their own CSS. This guide shows how to make the third kind look like it belongs in a Tailwind v4 design system. You share theme tokens, put the stylesheets in the right cascade layer and sync dark mode, with complete code you can paste.

Three Ways to Get a Tailwind Calendar Component

Before styling anything, pick the right kind of component. The options make different trade-offs:

ApproachExampleHow Tailwind styling worksGood forWatch out for
Hand-built from utility markupYour own grid or a UI kit's static layoutUtility classes on every elementSmall, read-only month gridsYou write the date maths, navigation, overlaps and accessibility yourself
Headless or class-mapped componentshadcn/ui Calendar, built on React DayPickerA classNames prop maps parts to utility stringsReact apps that need a date pickerReact only; a date picker, not an event calendar
Tailwind-flavoured pickerFlowbite Datepicker (MIT, a fork of Vanilla JS Datepicker)Ships with Tailwind classesVanilla JS date and range inputsNo week or day views, no events
Full calendar library with its own CSSSimpleCalendarJS, FullCalendar and othersCSS custom properties mapped to Tailwind tokensMonth, week, day and list views with eventsYou theme through variables, not utility classes

React DayPicker's styling docs show the class-mapping approach: you pass Tailwind class strings into classNames (for example selected: 'bg-amber-500 text-white') and can keep the defaults with getDefaultClassNames(). If you only need a date picker in a React app, that's often the cleanest route. For a comparison of React options, see Best React Calendar Components in 2026.

The rest of this post covers the last row: an event calendar that renders its own DOM, themed so it reads as part of your Tailwind UI.

Why Utility Classes Don't Reach Inside a Calendar

Tailwind works by putting classes on elements you write. A calendar library creates its day cells, time slots and event chips at runtime, so you never write that markup and can't add bg-indigo-50 to today's cell.

Tailwind's own docs point to the fix. Its theme variables compile to ordinary CSS custom properties: every token in @theme ends up as a variable you can read with var(), in custom CSS or inline styles. A calendar that exposes its colors, radii and fonts as CSS variables can read those same tokens. You end up with one source of truth: change --color-brand-600 and the buttons, links and calendar all follow.

The pieces that make this work:

  1. Theme tokens in @theme, so they produce utilities (bg-brand-600) and CSS variables.
  2. A mapping rule that points the calendar's variables at those tokens.
  3. Cascade layers in the right order, so Tailwind's Preflight reset doesn't fight the calendar's stylesheet.
  4. One dark-mode switch that drives Tailwind's dark: variant and the calendar's dark theme together.

Need a calendar in your app?

SimpleCalendarJS: ~14 KB gzipped, zero dependencies, works in any framework. Free for personal use.

Step 1: Load the Calendar CSS in the Right Cascade Layer

Tailwind v4 uses native CSS cascade layers. Its docs show the layer order as theme, base, components, utilities, with Preflight imported into the base layer. Preflight sets border: 0 solid and box-sizing: border-box on every element, removes default margins and padding, and makes images display: block.

The cascade rule that matters here comes from MDN: "Styles that are not defined in a layer always override styles declared in named and anonymous layers." If you import the calendar's stylesheet without a layer, every property it sets beats Preflight, whatever the specificity. That's what you want for a component whose internals you don't control.

The simplest setup imports both stylesheets from one CSS entry file, which also makes the load order predictable:

/* app.css */ @import "tailwindcss"; @import "simple-calendar-js/dist/simple-calendar-js.min.css";

Tailwind's layers stay layered, and the calendar's CSS stays unlayered, so it wins over Preflight. Your own overrides go after it, also unlayered.

When to put it in a layer instead

Standard CSS lets you import a stylesheet straight into a layer with @import "file.css" layer(name). Tailwind's docs use this syntax to load Preflight. They also recommend the components layer for styling third-party widgets, so utility classes can still override those rules.

If you import the calendar CSS with layer(components), it still beats Preflight, because components comes after base. But your theme overrides then have to live in the same layer or come later, or they'll lose. Custom properties follow the cascade like any other property: an unlayered default --cal-primary on .uc-calendar beats a layered override on the same selector. Keep the library CSS and your overrides at the same layer level. For most projects, both unlayered is easiest.

Step 2: Share Tailwind Theme Tokens With the Calendar

Define semantic tokens once in @theme. They give you utilities such as bg-surface, text-ink and border-line, plus CSS variables the calendar can read.

One caveat from Tailwind's docs: "By default only used CSS variables will be generated in the final CSS output." The docs don't say whether a var() reference in your own CSS counts as "used". To make sure the calendar never reads an empty variable, declare its tokens with @theme static, which always emits them.

/* app.css */ @import "tailwindcss"; @import "simple-calendar-js/dist/simple-calendar-js.min.css"; @custom-variant dark (&:where(.dark, .dark *)); @theme static { --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif; --radius-card: 0.75rem; --color-brand-50: #eef2ff; --color-brand-100: #e0e7ff; --color-brand-600: #4f46e5; --color-brand-700: #4338ca; --color-on-brand: #ffffff; --color-surface: #ffffff; --color-surface-muted: #f9fafb; --color-line: #e5e7eb; --color-line-strong: #d1d5db; --color-ink: #111827; --color-ink-muted: #6b7280; } /* Dark values: utilities and calendar both read these */ .dark { --color-brand-50: #1e1b4b; --color-brand-100: #312e81; --color-brand-600: #818cf8; --color-brand-700: #a5b4fc; --color-on-brand: #1e1b4b; --color-surface: #111827; --color-surface-muted: #1f2937; --color-line: #374151; --color-line-strong: #4b5563; --color-ink: #f9fafb; --color-ink-muted: #9ca3af; } /* Map the calendar's variables to the Tailwind tokens */ .uc-calendar, .uc-dark .uc-calendar { --cal-font-family: var(--font-sans); --cal-font-size: 0.875rem; --cal-radius: var(--radius-card); --cal-event-border-radius: 0.375rem; --cal-bg: var(--color-surface); --cal-bg-secondary: var(--color-surface-muted); --cal-toolbar-bg: var(--color-surface); --cal-hover: var(--color-surface-muted); --cal-text: var(--color-ink); --cal-text-secondary: var(--color-ink); --cal-text-muted: var(--color-ink-muted); --cal-text-subtle: var(--color-ink-muted); --cal-border: var(--color-line); --cal-border-strong: var(--color-line-strong); --cal-primary: var(--color-brand-600); --cal-primary-dark: var(--color-brand-700); --cal-primary-light: var(--color-brand-100); --cal-today-bg: var(--color-brand-50); --cal-today-text: var(--color-brand-700); --cal-selected-bg: var(--color-brand-100); --cal-event-bg: var(--color-brand-600); --cal-event-text: var(--color-on-brand); --cal-now-color: #ef4444; --cal-tooltip-bg: var(--color-ink); --cal-tooltip-text: var(--color-surface); }

Some notes on why it's written this way:

  • @theme, not @theme inline. Without inline, the generated utilities reference the variable (background-color: var(--color-surface)). That means overriding the variable under .dark flips bg-surface and the calendar together. Tailwind's docs say to use inline when a theme variable references another variable, which isn't the case here.
  • Hex values for the brand tokens. Tailwind v4's default palette uses oklch(). That's fine for CSS variables, but the hex values are useful when you need the same colors in JavaScript event data (see the pitfalls below).
  • The .uc-dark .uc-calendar selector. The calendar's built-in dark theme sets its own variable values when uc-dark is present. Listing that selector next to .uc-calendar gives your mapping the same specificity, and since it loads later, your tokens should win. If a color still looks wrong, inspect the element in DevTools: the Styles panel shows which rule set each --cal-* variable.
  • Only documented variables. The --cal-* names above are the calendar's whole theming surface. For a deeper look at each variable, see Customising Your JavaScript Calendar: Themes, Dark Mode & CSS Variables.

Step 3: Dark Mode That Follows Tailwind's dark Variant

By default Tailwind's dark: variant follows prefers-color-scheme. The @custom-variant dark (&:where(.dark, .dark *)); line above switches it to a class strategy, so dark:* utilities apply whenever a dark class sits higher up the tree. Tailwind's dark-mode docs suggest a small inline script in the head that reads localStorage and falls back to the system setting, so the page doesn't flash the wrong theme.

SimpleCalendarJS's dark theme is a separate class, uc-dark, on the calendar container or any parent. It isn't automatic. The easiest way to keep the two in sync is to toggle both classes on the html element at the same moment:

function applyTheme(dark) { const root = document.documentElement; root.classList.toggle('dark', dark); // Tailwind dark: variant + token overrides root.classList.toggle('uc-dark', dark); // SimpleCalendarJS dark theme }

If you keep Tailwind's default media-query strategy instead, mirror the system setting yourself:

const media = window.matchMedia('(prefers-color-scheme: dark)'); const sync = () => document.documentElement.classList.toggle('uc-dark', media.matches); sync(); media.addEventListener('change', sync);

In that case, wrap the .dark { ... } token overrides in @media (prefers-color-scheme: dark) { :root { ... } } instead of a class selector. Event colors, contrast and system-versus-toggle trade-offs are covered in more depth in JavaScript Calendar Dark Mode.

Building a Tailwind Calendar Component With SimpleCalendarJS

SimpleCalendarJS fits this pattern well. It has zero dependencies, its classes are prefixed (.uc-calendar, .uc-dark) so they don't collide with utilities, and its theming is done entirely with CSS custom properties. It's about 14 KB gzipped for the JS and about 19 KB with the CSS. It also lets you hide its built-in toolbar (showToolbar: false) and drive it through methods. That means the toolbar, often the most visible part, can be plain Tailwind markup that matches your other buttons exactly.

Here's a complete page, using the app.css from Step 2.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Team calendar</title> <script> { const dark = localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches); document.documentElement.classList.toggle('dark', dark); document.documentElement.classList.toggle('uc-dark', dark); } </script> <script type="module" src="/main.js"></script> </head> <body class="bg-surface-muted font-sans text-ink"> <main class="mx-auto max-w-6xl p-4 sm:p-8"> <section class="overflow-hidden rounded-card border border-line bg-surface shadow-sm"> <header class="flex flex-wrap items-center gap-3 border-b border-line px-4 py-3"> <h1 id="cal-title" class="mr-auto text-lg font-semibold"></h1> <div class="flex items-center gap-1"> <button data-action="prev" aria-label="Previous" class="rounded-md px-2.5 py-1.5 text-sm hover:bg-surface-muted">&larr;</button> <button data-action="today" class="rounded-md border border-line px-3 py-1.5 text-sm font-medium hover:bg-surface-muted">Today</button> <button data-action="next" aria-label="Next" class="rounded-md px-2.5 py-1.5 text-sm hover:bg-surface-muted">&rarr;</button> </div> <div class="inline-flex rounded-lg bg-surface-muted p-1" role="group" aria-label="View"> <button data-view="month" aria-pressed="true" class="rounded-md px-3 py-1 text-sm text-ink-muted aria-pressed:bg-surface aria-pressed:text-ink aria-pressed:shadow-sm">Month</button> <button data-view="week" aria-pressed="false" class="rounded-md px-3 py-1 text-sm text-ink-muted aria-pressed:bg-surface aria-pressed:text-ink aria-pressed:shadow-sm">Week</button> <button data-view="day" aria-pressed="false" class="rounded-md px-3 py-1 text-sm text-ink-muted aria-pressed:bg-surface aria-pressed:text-ink aria-pressed:shadow-sm">Day</button> <button data-view="list" aria-pressed="false" class="rounded-md px-3 py-1 text-sm text-ink-muted aria-pressed:bg-surface aria-pressed:text-ink aria-pressed:shadow-sm">List</button> </div> <button id="theme-toggle" class="rounded-md bg-brand-600 px-3 py-1.5 text-sm font-medium text-on-brand hover:bg-brand-700"> Toggle theme </button> </header> <!-- Inline height: required for a fixed-height month view with "+N more" --> <div id="calendar" style="height: 640px"></div> </section> </main> </body> </html>
// main.js import SimpleCalendarJs from 'simple-calendar-js'; import './app.css'; // Hex values for event colors (the event `color` field takes hex) const colors = { brand: '#4f46e5', emerald: '#059669', amber: '#d97706', rose: '#e11d48', }; const events = [ { id: 1, title: 'Design review', start: new Date(2026, 11, 3, 10, 0), end: new Date(2026, 11, 3, 11, 0), color: colors.brand, description: 'Review the new onboarding flow' }, { id: 2, title: 'Sprint planning', start: new Date(2026, 11, 7, 9, 30), end: new Date(2026, 11, 7, 11, 0), color: colors.emerald }, { id: 3, title: 'Release freeze', start: new Date(2026, 11, 14), end: new Date(2026, 11, 16), allDay: true, color: colors.rose }, { id: 4, title: 'Customer call', start: '2026-12-09T15:00', end: '2026-12-09T15:45', color: colors.amber }, ]; const titleEl = document.querySelector('#cal-title'); const monthTitle = new Intl.DateTimeFormat(undefined, { month: 'long', year: 'numeric' }); titleEl.textContent = monthTitle.format(new Date()); function setActiveView(view) { document.querySelectorAll('[data-view]').forEach((btn) => { btn.setAttribute('aria-pressed', String(btn.dataset.view === view)); }); } const calendar = new SimpleCalendarJs('#calendar', { defaultView: 'month', enabledViews: ['month', 'week', 'day', 'list'], showToolbar: false, // the Tailwind header above replaces it showBorder: false, // the section already has a border weekStartsOn: 1, autoContrastText: true, // readable text on every event color fetchEvents: async () => events, onNavigate: (rangeStart, rangeEnd) => { // The middle of the visible range always falls in the "current" month const mid = new Date((new Date(rangeStart).getTime() + new Date(rangeEnd).getTime()) / 2); titleEl.textContent = monthTitle.format(mid); }, onViewChange: (view) => setActiveView(view), onEventClick: (event) => { console.log('Open your own dialog for', event.id, event.title); }, }); document.querySelector('header').addEventListener('click', (e) => { const btn = e.target.closest('button'); if (!btn) return; if (btn.dataset.action === 'prev') calendar.navigate(-1); if (btn.dataset.action === 'next') calendar.navigate(1); if (btn.dataset.action === 'today') calendar.goToToday(); if (btn.dataset.view) { calendar.setView(btn.dataset.view); setActiveView(btn.dataset.view); } }); document.querySelector('#theme-toggle').addEventListener('click', () => { const dark = !document.documentElement.classList.contains('dark'); document.documentElement.classList.toggle('dark', dark); document.documentElement.classList.toggle('uc-dark', dark); localStorage.theme = dark ? 'dark' : 'light'; });

What this gives you:

  • The toolbar is all Tailwind. It uses the same rounded-md, hover: and aria-pressed: utilities as the rest of your app, and navigate(), goToToday() and setView() move the calendar.
  • The grid uses your tokens. Backgrounds, borders, today's highlight and default event color all come from @theme, so a brand change in one place reaches everything.
  • One theme switch. Toggling dark flips the token values for utilities and calendar alike, and uc-dark turns on the calendar's own dark styles.

When events change (a user saves your form, or a websocket message arrives), update the events array or your API, then call calendar.refresh(). There's no addEvent method: fetchEvents is the single data path, and refresh() clears the cache and calls it again.

The same thing in a React component

The CSS doesn't change in a framework. In React, create the core class in an effect and destroy it on unmount. A style prop renders as an inline style, so it counts as a fixed height:

import { useEffect, useRef } from 'react'; import SimpleCalendarJs from 'simple-calendar-js'; export default function TeamCalendar({ events }) { const elRef = useRef(null); useEffect(() => { const calendar = new SimpleCalendarJs(elRef.current, { enabledViews: ['month', 'week', 'day', 'list'], autoContrastText: true, fetchEvents: async () => events, }); return () => calendar.destroy(); }, [events]); return ( <div className="rounded-card border border-line bg-surface shadow-sm"> <div ref={elRef} style={{ height: 640 }} /> </div> ); }

Some honest limits before you commit. SimpleCalendarJS covers month, week, day and list views, plus date-picker and range-picker modes. It has no resource or timeline views, no built-in recurring events (RRULE) and no timezone option. If you need a resource scheduler, compare the options in Best JavaScript Scheduler Libraries in 2026. On licensing, it's free for personal, educational and open source projects, while commercial use (client sites, SaaS, internal tools) needs a paid license; see pricing. You can try the theming variables live in the sandbox before installing, and the docs list every option.

Need a calendar in your app?

SimpleCalendarJS: ~14 KB gzipped, zero dependencies, works in any framework. Free for personal use.

Common Pitfalls When Styling a Calendar With Tailwind

A height utility class doesn't fix the height

h-[640px] or h-screen on the calendar container looks right, but SimpleCalendarJS only treats an inline style as a fixed height. Without one, month view grows to fit every event instead of showing "+N more". Use style="height: 640px". For a responsive height, set element.style.height in JavaScript, based on matchMedia, before you create the calendar. Wrapper elements around the container can use any utilities you like.

Event colors need hex, not utility classes or oklch

An event's color, textColor and borderColor fields take hex values, so bg-emerald-600 or var(--color-emerald-600) won't work there. Keep a small hex map next to your tokens, as main.js does, and turn on autoContrastText so the calendar picks readable text for each background. For events with no color, --cal-event-bg and --cal-event-text apply, and those can use CSS variables.

Variables that resolve to nothing

If a calendar surface turns transparent, the Tailwind variable it points at probably wasn't emitted. Tailwind only outputs theme variables it considers used. Declaring calendar tokens in @theme static (or giving var() a fallback, such as var(--color-surface, #fff)) removes the guesswork.

Overrides that silently lose

If your .uc-calendar { --cal-primary: ... } rule has no effect, check two things in DevTools. First, is the rule in a cascade layer while the library CSS isn't? Unlayered rules win. Second, does the library's dark-mode rule have higher specificity than yours? Fix it by matching specificity and load order, not with !important. With cascade layers, !important declarations behave in reverse (MDN notes that important declarations inside layers beat unlayered important ones), which makes debugging harder.

Preflight side effects on wrapper markup

Preflight removes list bullets and margins from everything, including any HTML you inject into tooltips or event titles (both allow sanitized HTML by default). If a tooltip list loses its bullets, style it explicitly, for example with list-disc list-inside on the list you render.

Sources & Further Reading

Image Credits

Image free to use under the Pexels License.

Frequently Asked Questions

How do I use Tailwind v3 theme colors in a calendar's CSS variables?

Tailwind v3 doesn't turn your theme into CSS variables by default. Use the theme() function in your stylesheet instead, for example `--cal-primary: theme('colors.indigo.600');` inside a `.uc-calendar` rule. The build replaces it with the literal color. It works, but you lose the runtime switching that v4's real CSS variables give you.

Will Tailwind purge or tree-shake a calendar library's CSS?

No. Tailwind only generates utility classes from the files it scans. Ordinary CSS you import, such as a calendar's stylesheet, is passed through as it is. You don't need to safelist the library's class names. The one thing that can be left out is a Tailwind theme variable nothing uses, which is why `@theme static` helps.

Can I use @apply on a third-party calendar's classes?

Yes, you can write a selector for a class the library renders and use `@apply` inside it, but it ties you to the library's internal markup, which can change between releases. If the library exposes CSS custom properties, set those instead. They're the documented theming surface, so they keep working after an upgrade.

Do Tailwind's class names conflict with SimpleCalendarJS classes?

No. SimpleCalendarJS uses prefixed class names such as `.uc-calendar` and `.uc-dark`, so they don't clash with Tailwind utilities. You can use Tailwind's `prefix()` option for your own utilities if you like, and the calendar doesn't need any changes either way.

Is there a free Tailwind calendar for date picking only?

Flowbite Datepicker is MIT-licensed and styles itself with Tailwind utility classes. It's a fork of Vanilla JS Datepicker and includes a date range picker. It's a picker, though, not an event calendar, so it has no week view, day view or event rendering.

Why does my calendar ignore the Tailwind h-[600px] class?

SimpleCalendarJS only treats an inline style as a fixed height. Height from a stylesheet or a utility class counts as no height, so month view grows to fit every event. Write `style="height: 600px"` on the container, or set `element.style.height` in JavaScript before you create the calendar.

Add a calendar to your app today

Free for personal projects. $49/year or $199 lifetime per commercial project.

Keep Reading