Overview
Excalidraw supports light and dark themes out of the box. You can control the theme programmatically or let users toggle between themes.Theme Basics
Available Themes
Excalidraw provides two built-in themes:light- Light color scheme optimized for bright environmentsdark- Dark color scheme optimized for low-light environments
Setting the Theme
1
Import Excalidraw
2
Pass the theme prop
3
Optional: Enable theme toggle
Omit the
theme prop to show the theme toggle button:Dynamic Theme Switching
User-Controlled Theme
Let users switch between themes:System Theme Detection
Sync with the user’s system theme preference:Persisting Theme Preference
Save the user’s theme choice:Theme Toggle Button
Automatic Toggle
When you don’t pass thetheme prop, Excalidraw shows a built-in theme toggle:
From the source code at
packages/excalidraw/index.tsx:82-87, when UIOptions.canvasActions.toggleTheme is null and theme is undefined, the toggle button is automatically enabled.Disabling the Toggle
Explicitly disable the theme toggle button:Export with Theme
Dark Mode Export
Control the theme used when exporting:Theme and App State
Initial Theme in AppState
Set the initial theme throughinitialData:
Tracking Theme Changes
Monitor theme changes with theonChange callback:
Internationalization and Theme
RTL Support with Themes
Excalidraw automatically handles right-to-left (RTL) languages with themes:From
packages/excalidraw/i18n.ts:92-95, when setting a language, Excalidraw automatically sets document.documentElement.dir to "rtl" or "ltr" based on the language’s RTL property.Advanced Theming
Custom Background Colors
Customize the view background color:Theme-Aware Components
Create custom UI components that adapt to the theme:Theme Constants
Using Theme Enums
Import theme constants from Excalidraw:@excalidraw/common:
THEME.LIGHT- “light”THEME.DARK- “dark”
Best Practices
1
Default to system preference
Respect the user’s system theme preference by default.
2
Persist user choice
Save the user’s theme preference to localStorage.
3
Smooth transitions
Add CSS transitions for a smooth theme switching experience.
4
Test both themes
Ensure your custom UI components work well in both light and dark themes.
Next Steps
Customization
Learn about other customization options
i18n
Add internationalization support
Export
Export with theme settings
Storage
Persist theme preferences