Basic Dark mode Demo page

(New verion 03 Feb 2025)

This is a demo page showing the basic functionality required to implement a user switchable Dark mode as described in How to setup a Dark mode switch on a web-site.

The user can overwrite the browser’s light/dark setting, and this can be reset to the browser’s setting if required. The browser setting normally follows the operating system’s mode.

Note that the colors on this page are deliberately garish rather than set for aesthetic sensibility, this is simply to show how the method works.

See How to setup a dark mode switch for your web-site for details of how to implement the method on a website.

You can download copies of the basic demo files here:

To see dark mode implemented with a normally hidden reset button, see the page Simple Dark mode Demo page with Reset message.

The image is to demonstrate image handling on loading.

 Color Wheel

 

This element has preference for light mode, declared in a <style> tag in the HTML head:
  @media (prefers-color-scheme: light) {
    .lightPref {
      color: … ;
      background: … ;
    }
  }
This element changes color by CSS varaibles:
  @media (prefers-color-scheme: dark) {
    :root {
      --text-color: … ;
      --bg-color: … ;
  }