Back to Blog
Html code on computer screen in dark mode
Design
9 min read

JavaScript Calendar Dark Mode: System, Toggle and Event Colors

By SimpleCalendarJS Team

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

JavaScript calendar dark mode needs three parts: the OS preference (prefers-color-scheme, read with matchMedia), a manual choice saved to localStorage and applied before first paint, and the calendar's own theme switch. In SimpleCalendarJS that switch is the uc-dark class, and you change colors with --cal-* CSS variables.

Calendars break more easily in dark mode than most UI. A calendar has dense grid lines, a "today" highlight, a now-line, tooltips, and dozens of event colors that someone picked for a white background. This guide covers JavaScript calendar dark mode from start to finish: following the OS setting, a saved light/dark/system toggle that doesn't flash on load, brand colors for both themes, and event colors that stay readable in both.

The techniques are standard web platform features (prefers-color-scheme, matchMedia, color-scheme), so they apply to any calendar library. The full example uses SimpleCalendarJS, and the next section shows how other libraries handle the same switch.

How JavaScript Calendar Libraries Handle Dark Mode

Each library exposes dark mode differently, and that decides how you wire up a toggle. Here's what the official docs say as of late 2026:

LibraryHow you enable dark modeFollows the OS automatically?
SimpleCalendarJSAdd the uc-dark class to the calendar container or any parentNo. Toggle the class from matchMedia
FullCalendar v7colorScheme: 'dark' option, or data-color-scheme="dark" on an ancestorNot out of the box. A media-query or custom-class setup means forking the palette file
Schedule-XisDark: true in the calendar config (default false)Not documented on the configuration page
flatpickrLoad the separate dark.css theme stylesheetNo. You swap stylesheets yourself

These approaches have one thing in common: dark mode is a switch you control, not something the browser does for you. FullCalendar's v7 docs say all stock themes support dark mode. They also note that overriding a dark-mode palette variable such as --fc-monarch-background only works with the [data-color-scheme=dark] attribute selector, unless you fork the palette. A class-based switch, like SimpleCalendarJS's uc-dark, can go on <html> next to your site's own dark class, so the whole page flips at once.

The Three Parts of a Dark Theme

A complete dark mode has three parts. Most broken implementations skip one of them.

1. The system preference

The prefers-color-scheme media feature reports whether the user asked for a light or dark theme in their OS or browser. It's Baseline widely available, supported across browsers since January 2020, according to MDN. In CSS it's an @media (prefers-color-scheme: dark) block. In JavaScript you read it with window.matchMedia(), which returns a MediaQueryList. Its matches property gives the current state, and its change event fires when the user switches. Use addEventListener('change', …), because the older addListener() is deprecated.

2. A manual override

Some users want a dark app on a light OS, or the other way round. Give them three choices, System, Light and Dark, and save the choice in localStorage. "System" stays live: if the OS switches at sunset, the calendar switches too.

3. The browser chrome

Your CSS doesn't control everything on the page. The color-scheme property tells the browser which schemes an element supports, so it can adapt the canvas background, scrollbars and form controls. Without it, a dark calendar can end up with a bright scrollbar in week view. MDN also documents <meta name="color-scheme" content="light dark"> in the <head>. This tells the browser early which schemes the page supports, which helps prevent a flash of the wrong colors while the page loads.

Need a calendar in your app?

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

Building JavaScript Calendar Dark Mode With SimpleCalendarJS

SimpleCalendarJS ships a built-in dark theme that you turn on with one class: uc-dark on the calendar container or any parent element. That last part matters. You can put the class on <html>, so one class flip changes your page and the calendar together. The library doesn't follow the OS by itself, so the steps below add that.

Step 1: The HTML and a theme script that runs before paint

The inline script runs before the stylesheets load, so the first paint already uses the right theme. Keep it tiny and dependency-free.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="color-scheme" content="light dark"> <script> (function () { var pref = 'system'; try { pref = localStorage.getItem('theme') || 'system'; } catch (e) {} var dark = pref === 'dark' || (pref === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches); var root = document.documentElement; root.classList.toggle('dark', dark); // your site styles root.classList.toggle('uc-dark', dark); // SimpleCalendarJS dark theme root.style.colorScheme = dark ? 'dark' : 'light'; })(); </script> <link rel="stylesheet" href="https://unpkg.com/simple-calendar-js/dist/simple-calendar-js.min.css"> <link rel="stylesheet" href="theme.css"> </head> <body> <header> <label> Theme <select id="theme-select"> <option value="system">System</option> <option value="light">Light</option> <option value="dark">Dark</option> </select> </label> </header> <div id="calendar" style="height: 640px"></div> <script src="https://unpkg.com/simple-calendar-js/dist/simple-calendar-js.min.js"></script> <script src="app.js"></script> </body> </html>

The try block is there because localStorage can throw in some locked-down browser modes. A theme script must never stop the page from loading. The container's height is an inline style on purpose: SimpleCalendarJS only treats an inline height as a fixed layout. In a fixed layout, month view shows "+N more" instead of growing to fit every event.

Step 2: The theme controller and the calendar

app.js keeps the class, the saved preference and the OS listener in sync, and creates the calendar. Events come from fetchEvents. Each event has a semantic category in place of a hard-coded color, and Step 4 explains why.

const STORAGE_KEY = 'theme'; const root = document.documentElement; const media = window.matchMedia('(prefers-color-scheme: dark)'); const select = document.querySelector('#theme-select'); // Event colors per theme: deeper hues on light, lighter tints on dark. const palettes = { light: { meeting: '#4338ca', deadline: '#b91c1c', personal: '#15803d' }, dark: { meeting: '#a5b4fc', deadline: '#fca5a5', personal: '#86efac' }, }; const events = [ { id: 1, title: 'Sprint planning', category: 'meeting', start: new Date(2026, 11, 1, 9, 30), end: new Date(2026, 11, 1, 10, 30) }, { id: 2, title: 'Invoice run', category: 'deadline', start: new Date(2026, 11, 2, 14, 0), end: new Date(2026, 11, 2, 15, 0), description: 'Send November invoices' }, { id: 3, title: 'Dentist', category: 'personal', start: new Date(2026, 11, 3, 8, 0), end: new Date(2026, 11, 3, 9, 0) }, { id: 4, title: 'Release freeze', category: 'deadline', allDay: true, start: new Date(2026, 11, 4), end: new Date(2026, 11, 4) }, ]; function getPreference() { try { return localStorage.getItem(STORAGE_KEY) || 'system'; } catch { return 'system'; } } function isDark() { return root.classList.contains('uc-dark'); } const calendar = new SimpleCalendarJs('#calendar', { defaultView: 'week', defaultDate: new Date(2026, 11, 1), enabledViews: ['month', 'week', 'day', 'list'], weekStartsOn: 1, autoContrastText: true, fetchEvents: async () => { const palette = palettes[isDark() ? 'dark' : 'light']; return events.map((e) => ({ ...e, color: palette[e.category] })); }, }); function applyTheme(pref) { const dark = pref === 'dark' || (pref === 'system' && media.matches); if (dark === isDark()) return; // nothing changed root.classList.toggle('dark', dark); root.classList.toggle('uc-dark', dark); root.style.colorScheme = dark ? 'dark' : 'light'; calendar.refresh(); // re-run fetchEvents with the new palette } select.value = getPreference(); select.addEventListener('change', () => { try { localStorage.setItem(STORAGE_KEY, select.value); } catch {} applyTheme(select.value); }); // Only follow the OS while the user has "System" selected. media.addEventListener('change', () => { if (getPreference() === 'system') applyTheme('system'); });

The script stays short for three reasons:

  1. One source of truth. The class on <html> is the current theme, and isDark() reads it, so the head script and app.js can't disagree.
  2. The OS listener respects the user. If someone picked "Dark", a system change at sunrise does nothing.
  3. refresh() only runs on a real change. It clears the calendar's cache and calls fetchEvents again, which is how SimpleCalendarJS picks up changed event data. That includes event colors that depend on the theme.

Step 3: Brand colors for both themes

The built-in dark theme gives you sensible defaults. To match your brand, override the CSS custom properties. The SimpleCalendarJS docs use .uc-calendar for light overrides and the pair .uc-dark .uc-calendar, .uc-calendar.uc-dark for dark ones. Load this file after the calendar's stylesheet.

/* theme.css — light (default) */ .uc-calendar { --cal-font-family: system-ui, sans-serif; --cal-primary: #0f766e; --cal-primary-dark: #115e59; --cal-primary-light: #ccfbf1; --cal-today-bg: #ccfbf1; --cal-today-text: #115e59; } /* Dark: class on a parent, or on the calendar element itself */ .uc-dark .uc-calendar, .uc-calendar.uc-dark { --cal-bg: #0f172a; --cal-bg-secondary: #131d33; --cal-toolbar-bg: #0f172a; --cal-text: #e2e8f0; --cal-text-muted: #94a3b8; --cal-text-secondary: #cbd5e1; --cal-border: #1e293b; --cal-border-strong: #334155; --cal-hover: #1e293b; --cal-primary: #2dd4bf; --cal-primary-dark: #14b8a6; --cal-primary-light: #134e4a; --cal-today-bg: #134e4a; --cal-today-text: #99f6e4; --cal-selected-bg: #115e59; --cal-now-color: #f87171; --cal-tooltip-bg: #e2e8f0; --cal-tooltip-text: #0f172a; } /* Your own page, keyed off the same switch */ html.dark body { background: #0b1120; color: #e2e8f0; }

A few dark-palette rules that suit calendars in particular:

  • Avoid pure black and pure white. A near-black slate background with off-white text is easier on the eyes in a dense grid of lines and labels.
  • Lower the contrast of borders, not text. Week and day views have a lot of hour lines. If --cal-border is too bright, the grid gets in the way of the events.
  • Make the primary color lighter, not darker. A teal that works as #0f766e on white gets muddy on slate, so step up to a lighter shade for dark mode.
  • Flip the tooltip. A light tooltip over a dark calendar stands out without needing a shadow.

The full list of variables, plus ready-made light themes, is in Customising Your JavaScript Calendar: Themes, Dark Mode & CSS Variables. You can also try values live in the sandbox.

Need a calendar in your app?

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

Event Colors That Survive Dark Mode

Event colors are where calendar dark modes usually fail. Colors often come straight from a database (color: '#4f46e5' on every row) and were chosen against white. On a dark background, deep saturated blocks look like holes in the grid. Pastel blocks glow and push white text below a readable contrast.

The fix in Step 2 is to store meaning, not color. Save a category (or a calendar ID, or a team) with each event, and pick the color when you return events from fetchEvents. The light palette uses deeper hues. The dark palette uses lighter tints of the same hues, so "deadline is red" stays true in both themes.

Two more details matter:

  • Text color follows the background. With autoContrastText: true, SimpleCalendarJS picks a readable text color for each event color, so the lighter dark-mode tints get dark text automatically. If you'd rather control it yourself, set textColor per event inside the same map().
  • Check the numbers. WCAG 2.2 success criterion 1.4.3 asks for 4.5:1 for normal text and 3:1 for large text. Large text means at least 18pt (about 24px) or 14pt bold (about 18.5px). Event titles in a month cell are never "large", so 4.5:1 is the target. Run every palette entry through a contrast checker in both themes.

If your events come from an API, the same pattern holds: fetch the raw rows, then map colors on the way out. Keep the last response in memory so the theme-triggered refresh() doesn't cost an extra network request when only the palette changed. How to Load Calendar Events From a REST API in JavaScript covers the fetching side.

Dark Mode in React (and Other Frameworks)

In a framework, keep the same split: the framework owns the theme state, and the calendar only sees a class on a parent element. With the core class in useEffect, put uc-dark on a wrapper div that React controls. Don't put it on the element the library renders into.

import { useEffect, useRef } from 'react'; import SimpleCalendarJs from 'simple-calendar-js'; import 'simple-calendar-js/dist/simple-calendar-js.min.css'; export default function ThemedCalendar({ dark, events }) { const elRef = useRef(null); const calRef = useRef(null); const eventsRef = useRef(events); eventsRef.current = events; useEffect(() => { calRef.current = new SimpleCalendarJs(elRef.current, { defaultView: 'month', autoContrastText: true, fetchEvents: async () => eventsRef.current, }); return () => { calRef.current.destroy(); calRef.current = null; }; }, []); // New events (or theme-specific colors) -> clear the cache and refetch useEffect(() => { calRef.current?.refresh(); }, [events, dark]); return ( <div className={dark ? 'uc-dark' : undefined}> <div ref={elRef} style={{ height: 600 }} /> </div> ); }

Where dark comes from is up to you. It can be a context fed by the same matchMedia listener, or a prop from your design system. If you subscribe to matchMedia inside a component, remove the listener in the effect's cleanup, just as you destroy the calendar. In Vue, the same structure uses onMounted / onBeforeUnmount and a :class binding on the wrapper. In SSR frameworks, the head script from Step 1 still belongs in the document template, because it has to run before hydration to avoid the flash. For the general setup, see How to Add a Calendar to a React App.

Testing a JavaScript Calendar Dark Mode

You don't need to change your OS setting to test. In Chrome DevTools, open the Rendering tab and set the prefers-color-scheme emulation to light or dark. Then check this list:

  1. Reload in every state. Test System, Light and Dark, each with the OS emulated both ways. There should be no light flash on a dark reload.
  2. Visit every view. Month, week, day and list each use different variables: the today cell, hour lines, the now-line, and the empty-state text in list view.
  3. Hover and open things. Tooltips, the year picker in the toolbar, hover states on slots, and selected days in picker mode.
  4. Drag an event (if enableDragDrop is on) and check that the dragged item is readable against the grid.
  5. Check scrollbars and form controls. If they're still light, color-scheme isn't being set.
  6. Run a contrast checker on event colors, muted text (--cal-text-muted) and the today highlight in both themes.

One more trap: Chrome's Auto Dark Theme can recolor pages that don't declare a scheme. Declaring color-scheme: light dark signals that you handle dark mode yourself. MDN notes that color-scheme: only light can opt an element, or the whole page, out of that automatic recoloring.

Where light-dark() Fits

The CSS light-dark() function returns one of two colors based on the active color scheme, for example color: light-dark(#1e293b, #e2e8f0). MDN says it's been available across browsers since May 2024, and it requires color-scheme to be set (the head script above sets it on <html>). It's a tidy way to write your own page styles without duplicating selectors.

For the calendar itself, the uc-dark class is still the better switch. The library's built-in dark palette hangs off it, so mixing both systems on the same variables makes it harder to work out which value wins. A sensible split: light-dark() for your app shell, uc-dark plus the --cal-* overrides for the calendar, with both driven by the same toggle.

SimpleCalendarJS doesn't detect the OS theme or offer a darkMode option on the core class, so the toggle logic above is yours to own. In practice that's a benefit: it's about 30 lines and works with whatever theme system your app already has. SimpleCalendarJS is free for personal, educational and open source projects, and commercial use needs a license (see pricing).

Sources & Further Reading

Image Credits

Image free to use under the Pexels License.

Frequently Asked Questions

Does SimpleCalendarJS switch to dark mode automatically?

No. Its dark theme turns on when the uc-dark class is on the calendar container or any parent element. To follow the operating system, read matchMedia('(prefers-color-scheme: dark)') and toggle the class when its change event fires. That's a few lines of JavaScript.

Why does my page flash white before dark mode applies?

Your theme script runs after the browser has already painted the page in light colors. Put a small inline script in the head that reads the saved preference and sets your dark classes before any stylesheet loads. Add <meta name="color-scheme" content="light dark"> so the browser knows early that the page supports both schemes.

Can I use the CSS light-dark() function for calendar colors?

Yes, as long as color-scheme is set to light dark (or switched with your theme). MDN reports it has worked in all major browsers since May 2024. It suits your own page styles. For SimpleCalendarJS, the uc-dark class is still the cleaner switch, because the library's built-in dark palette hangs off it.

What contrast ratio do calendar event titles need?

WCAG 2.2 success criterion 1.4.3 (AA) requires 4.5:1 for normal text and 3:1 for large text: at least 18pt (about 24px), or 14pt bold (about 18.5px). Event titles in a calendar grid are almost always small, so plan for 4.5:1 against the event background in both themes.

How do I stop Chrome's Auto Dark Theme from recoloring my calendar?

Declare the color schemes you actually support. If you ship your own dark theme, set color-scheme: light dark on :root. If an element should never be recolored, MDN documents color-scheme: only light, which can turn off Chrome's Auto Dark Theme for that element or the whole page.

Does the SimpleCalendarJS React wrapper support dark mode?

Yes. The React, Vue and Angular wrappers accept a darkMode boolean prop. The core class in a useEffect hook is still the recommended approach, though, because the wrappers only pass through some options. With the core class, put uc-dark on a parent element that your component controls.

Add a calendar to your app today

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

Keep Reading