Add a dark-mode / night-mode to your website in a few seconds. This library uses the css mix-blend-mode in order to bring Dark-mode to any of your websites. Just copy paste the snippet and you will get a widget to turn on and off the dark-mode.
Darkmode.js is a lightweight VanillaJS library created by Sandoche that uses CSS mix-blend-mode to add a dark mode or night mode toggle to any website in seconds.
The main features and capabilities of Darkmode.js include:
Automatic Widget & Programmatic Control: Displays an automatic, floating toggle widget on the webpage or allows toggling dark mode programmatically using the toggle() method and checking activation state via isActivated().
LocalStorage & OS Preference Detection: Automatically remembers user choice using localStorage by default and detects system-level dark themes via prefers-color-scheme media queries.
CSS Inversion & Style Overrides: Uses mix-blend-mode: difference for color inversion without requiring a dedicated dark-mode stylesheet. It applies a .darkmode--activated class to the body element for custom CSS overrides and supports .darkmode-ignore or isolation: isolate to exclude specific elements.
Configurable Appearance & Behavior: Provides customizable options for button placement (bottom, left, right), transition duration, blend and button colors, custom button labels, and cookie saving.
CMS & Framework Integration: Installs easily via JSDelivr CDN snippets or npm, with dedicated plugins and modules available for WordPress, Drupal, and Nuxt.js.