Implement Dark mode on your website

ajaykumbhare

Ajay kumbhare

Posted on August 11, 2020

Implement Dark mode on your website

How to implement dark mode on your website?

Alt Text

I will use darkreader npm library which has more than 7.5K stars.

You can use Dark Reader to enable dark mode on your website.

Install the package from NPM

npm install darkreader
Enter fullscreen mode Exit fullscreen mode

you can import es modules in your main file from darkreader.

import { enable, disable } from 'darkreader';
Enter fullscreen mode Exit fullscreen mode

enable - Enables dark mode for current web page
disable - Disables dark mode for current web page

to enable dark mode on your website add just call enable() function in your file.

also, you can customize some filters by passing parameters in the enable method.

for example,

enable({
    brightness: 100,
    contrast: 90,
    sepia: 10,
});
Enter fullscreen mode Exit fullscreen mode

It supports the following parameters which you can use it.

  • mode: 0 | 1
    • 1 - dark mode, 0 - dimmed mode
  • [ brightness | grayscale | contrast | sepia ] : number
    • value (0 - 100+)
    • Default [ 100 | 0 | 100 | 0 ]
  • useFont: boolean
    • Specifies if custom font should be used
    • Default false
  • fontFamily: string
    • Font family to use
  • textStroke: number
    • Makes text look bolder (0 - 1px)
    • Default 0
  • darkSchemeBackgroundColor: string
    • Background color to use for dark mode
    • Default #181a1b
  • darkSchemeTextColor: string
    • Text color to use for dark mode
    • Default #e8e6e3
  • lightSchemeBackgroundColor: string
    • Background color to use for light mode
    • Default #dcdad7
  • lightSchemeTextColor: string
    • Text color to use for light mode
    • Default #181a1b
  • scrollbarColor: string
    • Scrollbar color
    • Default auto
  • selectionColor: string
    • Selection color
    • Default auto

Resources

https://github.com/darkreader/darkreader

💖 💪 🙅 🚩
ajaykumbhare
Ajay kumbhare

Posted on August 11, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

React Design Patterns (Part 1)
javascript React Design Patterns (Part 1)

January 23, 2021

React design patterns (part 2)
javascript React design patterns (part 2)

January 23, 2021

Implement Dark mode on your website
javascript Implement Dark mode on your website

August 11, 2020