Auto Dark Mode
Add a dark mode toggle to your WordPress site with automatic theme switching based on visitor system preferences. A floating button allows visitors to manually switch between light and dark modes.
This module is currently in beta. It applies generic dark mode styles that work with most themes, but results may vary depending on your specific theme’s CSS structure.
Use Cases
- Offer accessibility and comfort options for visitors
- Respect user system preferences (OS dark mode setting)
- Reduce eye strain for visitors browsing at night
- Provide a modern website experience
How It Works
- Enable the module in Switchboard
- Configure position and default behavior
- A floating toggle button appears on your site
- Visitors click to switch between light/dark modes
- The choice is optionally saved in their browser
Settings
| Setting | Type | Default | Description |
|---|---|---|---|
| Toggle Button Position | Select | Bottom Right | Where the floating button appears |
| Default Mode | Select | Auto | Starting theme mode for new visitors |
| Remember User Choice | Toggle | On | Save preference in browser localStorage |
| Transition Speed | Select | Normal | Animation speed when switching modes |
Default Mode Options
| Mode | Behavior |
|---|---|
| Auto (Recommended) | Detects user’s system dark mode preference |
| Light | Always starts in light mode |
| Dark | Always starts in dark mode |
Transition Speeds
| Speed | Duration | Best For |
|---|---|---|
| Fast | 0.2s | Snappy, immediate feel |
| Normal | 0.3s | Balanced, smooth transition |
| Slow | 0.5s | Dramatic, noticeable change |
Toggle Button Positions
Choose where the floating toggle button appears:
- Bottom Right - Most common, doesn’t interfere with content
- Bottom Left - Alternative if you have bottom-right widgets
- Top Right - Visible immediately, near header
- Top Left - Alternative top position
Bottom right is recommended as it’s the most common position for floating action buttons and doesn’t obstruct primary navigation or content.
Dark Mode Styles
The module applies automatic dark mode styles to common elements:
| Element | Dark Mode Style |
|---|---|
| Body background | #1a1a1a |
| Text color | #e0e0e0 |
| Links | #6ea8fe (blue) |
| Headings | #f8f9fa |
| Buttons | #404040 background |
| Inputs | #2d2d2d background |
| Tables | #242424 background |
| Code blocks | #0d0d0d background |
Images are slightly dimmed (90% opacity) in dark mode to reduce glare.
System Preference Detection
When “Default Mode” is set to “Auto”, the module detects the visitor’s operating system preference:
- macOS: System Preferences → General → Appearance
- Windows: Settings → Personalization → Colors
- iOS: Settings → Display & Brightness
- Android: Settings → Display → Dark theme
The module listens for system preference changes in real-time, so if a visitor changes their OS theme while on your site, the site theme updates automatically (unless they’ve manually toggled).
Remember User Choice
When enabled, the module saves the user’s manual toggle selection in their browser’s localStorage. This means:
- Their preference persists across page loads
- Their preference persists across browser sessions
- Manual choice overrides system preference detection
- Clearing browser data resets the preference
Accessibility Features
The toggle button includes proper accessibility attributes:
aria-labeldescribing the current actiontitleattribute for tooltip- High contrast focus states
- Keyboard accessible (Tab + Enter)
- Appropriate button semantics
Theme Compatibility
Dark mode works by adding a dark-mode class to the body element and applying CSS overrides. Most themes will display reasonably well, but some considerations:
Works Best With
- Themes using standard HTML elements
- Themes with minimal custom background colors
- Themes without complex CSS gradients
- Light-colored default themes
May Require Adjustments For
- Themes with many custom-colored elements
- Themes with image backgrounds
- Themes with complex layered designs
- Already-dark themes
Customizing Dark Mode Styles
For advanced users who want to customize dark mode colors, you can add CSS to your theme:
body.dark-mode {
--custom-background: #1a1a2e;
--custom-text: #ffffff;
}
body.dark-mode .my-custom-element {
background-color: var(--custom-background);
color: var(--custom-text);
}FAQ
Can I hide the toggle button and only use system preferences?
Currently, the toggle button is always visible when the module is enabled. If you only want system preference detection without a toggle, you would need to hide the button with CSS:#switchboard-dark-mode-toggle { display: none !important; }My theme already has dark mode. Will this conflict?
Possibly. If your theme has its own dark mode implementation, you should use your theme’s feature instead of this module to avoid conflicts. This module is designed for themes without built-in dark mode support.Some elements don’t change color in dark mode. Why?
The module applies generic styles that work for most themes. Elements with inline styles, very specific CSS selectors, or!important rules in your theme may not be overridden. You can add custom CSS to handle specific elements.Can visitors disable the toggle button?
The toggle button cannot be disabled by visitors. However, their choice (light or dark) is remembered so they only need to toggle once.Get access to all 147 modules with a single license