HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
ColinEspinas
darken
JavaScript2020–2020
ColinEspinas / darken

darken

🌑 Dark mode made easy

2Distinct people
2Mentions
0Explicit recommenders
606GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

🌑 Dark mode made easy

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 5:04:57 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by hour2 dated mentions

Observed mentions: 2020-01-16 23:02:29 UTC to 2020-01-17 02:05:08 UTC.

012020-01-16 23:00:00 UTC to 2020-01-17 00:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 commentsJan 16, 23:002020-01-17 00:00:00 UTC to 2020-01-17 01:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsJan 17, 00:002020-01-17 01:00:00 UTC to 2020-01-17 02:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2020-01-17 02:00:00 UTC to 2020-01-17 03:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 commentsJan 17, 02:00

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Jan 16, 23:002020-01-16 23:00:00 UTC2020-01-17 00:00:00 UTC110
Jan 17, 00:002020-01-17 00:00:00 UTC2020-01-17 01:00:00 UTC000
Jan 17, 01:002020-01-17 01:00:00 UTC2020-01-17 02:00:00 UTC000
Jan 17, 02:002020-01-17 02:00:00 UTC2020-01-17 03:00:00 UTC101

What Hacker News says

2 sources
The actual code behind this is short and straightforward: https://github.com/ColinEspinas/darken/blob/master/src/index.... For myself, I think it gets the balance of complexity wrong: it focuses on shifting various things into JavaScript, rather than doing it all in CSS using the (prefers-color-scheme) media query, and rewriting media queries to achieve manual switching. As a demonstration of the alternative approach I advocate, see what I came up with for my own website: https://chrismorgan.info/blog/dark-theme-implementation/. This uses native CSS techniques, working completely without JavaScript, merely using JavaScript to allow the user to manually switch, retaining that preference for future page loads and optimising page loading just about as far as is possible when doing it client-side to minimise the probability of a flash of inve
Read the rest
rted content if you manually switched to the opposite of what (prefers-color-scheme) would have chosen. The main thing that my approach doesn’t do that this thing does is dispatching an event, so that other JavaScript could conveniently be notified of a theme change. This is fairly deliberate on my part (I deliberately do all theme switching with CSS, and have no JavaScript that needs to change anything for dark mode), but could readily be added to what I wrote if desired. With my approach (for which I will also clarify that the JavaScript is deliberately written for compactness, not some theoretical notion of maintainability or extensibility), the example: <button id="dm-toggle">Toggle darkmode</button> <script> const darkmode = new darken({ toggle: "#dm-toggle", variables: { "--primary-color": ["#ffffff", "#000000"], "--secondary-color": ["#000000", "#ffffff"], } }); </script> … would be written more like this: <script> // (Add the button to the document in JS, // since it’ll only work if this JS runs anyway.) </script> <style> body { --primary-color: #ffffff; --secondary-color: #000000; } </style> <style media="screen and (prefers-color-scheme: dark)"> body { --primary-color: #000000; --secondary-color: #ffffff; } </style> (Two style blocks because my thing doesn’t deal with `@media … { … }` inline in CSS, because I don’t need it. You could make it do it if you really wanted to.) I find this approach much more manageable, and it allows adding custom CSS rules for dark mode (which I definitely use), rather than just setting CSS custom properties.
In Show HN: Darken – Darkmode Made Easy

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.