Menu

1 / 2

5 CSS Tricks for Firefox Extension Dark Mode

DEV Community·Weather Clock Dash·6 months ago
#eWqaHwkG
#css#firefox#webdev#browserextensions#dark
Reading 0:00
15s threshold

5 CSS Tricks for Firefox Extension Dark Mode

Building a browser extension that looks great in both light and dark mode is harder than it sounds. Here are 5 techniques from the Weather & Clock Dashboard Firefox extension.

1. CSS Custom Properties as Your Single Source of Truth

:root { --bg-primary : #ffffff ; --text-primary : #1a1a1a ; --accent : #4a90e2 ; }

[ data-theme = "dark" ] { --bg-primary : #1a1a2e ; --text-primary : #e8e8e8 ; --accent : #64b5f6 ; }

Enter fullscreen mode

Exit fullscreen mode

Switching themes is a single attribute change on <html> . Use var(--bg-primary) everywhere.

2. Don't Use Pure Black

#000000 feels harsh. Real dark UIs use:

--bg : #1 a1a2e ; /* slight blue tint */ --bg : #121212 ; /* Material Design dark */

Enter fullscreen mode

Exit fullscreen mode

3.…

Continue reading — create a free account

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