Menu

Post image 1
Post image 2
1 / 2
0

Dark Mode in Firefox Extensions: Respecting System Preferences

DEV Community·Weather Clock Dash·29 days ago
#5rHVVjZg
Reading 0:00
15s threshold

Dark Mode in Firefox Extensions: Respecting System Preferences Firefox users who prefer dark mode shouldn't have to manually toggle it in every extension. Here's how to automatically respect the system preference. The CSS Media Query /* Default: light mode */ :root { --bg : #ffffff ; --text : #1a1a1a ; --card-bg : #f5f5f5 ; --border : #e0e0e0 ; } /* Auto dark mode from system */ @media ( prefers-color-scheme : dark ) { :root { --bg : #1a1a2e ; --text : #e0e0e0 ; --card-bg : #16213e ; --border : #2d3561 ; } } Enter fullscreen mode Exit fullscreen mode Using CSS custom properties makes this effortless — one block of overrides handles the whole page. JavaScript Detection For dynamic behavior based on the current theme: const isDark = window . matchMedia ( ' (prefers-color-scheme: dark) ' ). matches ; // Listen for changes (user switches system theme) window . matchMedia ( ' (prefers-color-scheme: dark) ' ). addEventListener ( ' change ' , e => { const newScheme = e . matches ?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More