Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
Post image 6
Post image 7
Post image 8
1 / 8
0

I Thought Dark Mode Was a 30-Minute Task. It Turned Into a Full Refactor

DEV Community·Marsha Teo·27 days ago
#dHIjqj8P
Reading 0:00
15s threshold

I thought adding dark mode would take 30 minutes. It broke my website. Problem 1: Hardcoded colours I didn’t even use that many colours. How hard could it be? Turns out, very. My colours were hardcoded directly into Tailwind utility classes. A heading had a specific hex value, and a paragraph had another. To change the theme, I would have had to update each of these individually. No, thank you. The fix I introduced CSS variables and defined colours by role, not value. My first attempt had variables like hover-dark and hover-darker . That worked until I tried to invert the theme for dark mode. What would hover-darker even mean in dark mode? Instead of asking "What color should this element be?" , I had to ask "What role does this color play?" So I switched to variable names that were semantic, rather than literal: --text-primary --text-secondary --background --border With this, a heading wasn’t “black” anymore. It was text-primary . A background wasn’t “white”. It was background-primary .…

Continue reading — create a free account

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

Read More