Hugo Future Imperfect Slim

Tracey Jaquith · PoohBot Pictures

Technophile · Optimist · Cyclist · Archivist · Design · Video · TV · Nomad · Docker

2-Minute Read

dark -v- light mode

things turning me on this week
☕enjoy with a hot cupa java/script
‘Dark Mode’ is new - and a great relief to our eyes at night. Thankfully it’s also not that hard to setup very effectively.

Basics

If you ideally use either minimal css/style color: and background-color: or neutral colors (eg: middle grays for accents like #888) then your work is a lot simpler because you have less overrides to setup.

Effectively, one easy pass through is to find your darker and lighter colors and invert them for when it is dark mode.

You can then set those overrides into a CSS ‘media query’ eg:

@media (prefers-color-scheme: dark) {
  body {
    color: #ddd;
    background-color: #111;
  }
}

That might override normal defaults (implicit or explict) for your site like:

  body {
    color: #111;
    background-color: #ddd;
  }

The less places that use specific colors - the less you have setup overrides for.

Advanced

At the time of this writing:

  • macosx is Mojave and Catalina comes later this month
    • Mojave has only either everything is dark mode (always) or not
  • iOS latest is v13
    • which has the same ^^ ability to always be light/default, always be dark, or be time-based

So for non-mobile, if you want time-based dark mode, you can use javascript to additionally use the browser’s localtime to do dark mode when it’s evening hours and dark mode is enabled (and otherwise do default/light/day mode).

if (window.matchMedia  &&  window.matchMedia('(prefers-color-scheme: dark)').matches) {
  log('bring on the darkness!')
  const hour = new Date().getHours()
  if (7 <= hour  &&  hour < 19) { // override [7am .. 7pm] localtime
    log('.. but its vampire sleep time - back to day mode')
    $('body').addClass('lite')
  }
}

and you can assign some ‘overrides to the overrides’ in your css rules like:

body.lite {
  color: #333;
  background-color: #f4f4f4;
}

which will basically disable/revert dark mode during the local daylight hours.

Once Catalina macosx hits, I will likely drop the JS and body.lite stuff above.

Feel free to see the ‘dark mode’ CSS and JS I’m using here: CSS JS (presently at the bottom of the files).

Say Something

Comments

Recent Posts

Categories

Tags

#spottheshuttle 1940s 1st person 3d accident aids lifecycle airplane animals appeltart apple pie apple watch architecture arkit art ascii art asia augmented reality baking bali bay area best of biking birthday cafe racer camaro camera video camping candy cars cat pee cat psychology cats cloud coding college colorspaces computer vision cornell crictl css dark mode death valley decaf deinterlace desert design diy docker documentary driving ducting ebgb elbow break emacs endeavour family ffmpeg food games geek gitlab golden gate bridge google cardboard grand canyon gravel bike green magic man h.264 hack health highway 1 home https hugo hyperlapse internet archive ios iphone javascript jeep k3s kubernetes landscapes linux lisp luke battling darth mac macosx markdown mashup metal montclair motion-jpeg motorcycle mountain bike mplayer mt tamalpais nasa new bay bridge news ninja oakland olecranon partioning phoenix php php-htm-mode politics protest rancher recording remaster remix remodel sedona shuttle small town star wars surgery swift tahoe technical thirsty thursday time machine time-lapse timing belt adjustment top end rebuild tracey traefik training ride travel vacation valve job video virtual reality vlog vscode weekend-mechanic work x264 xcode yuvj420p zx6

About

tracey is a nonstop dance party. so you dont have to. dont ask me about containers. thanks for dropping by today. you look nice.