https://github.com/willhackett/is-dark
Detect whether or not the system is in dark mode from the browser.
https://github.com/willhackett/is-dark
Last synced: 9 months ago
JSON representation
Detect whether or not the system is in dark mode from the browser.
- Host: GitHub
- URL: https://github.com/willhackett/is-dark
- Owner: willhackett
- License: mit
- Created: 2019-05-28T05:36:40.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T05:25:28.000Z (over 2 years ago)
- Last Synced: 2025-08-27T21:19:57.015Z (9 months ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# is-dark
Detect whether or not the system is in dark mode from the browser.

## Rationale
The choice of whether to enable a light or dark appearance is an aesthetic one for most users, and might not relate to ambient lighting conditions. Websites should support both appearances and react to changes at the system level.
## Installation
Install the package using `npm` or `yarn`
```bash
npm install -S is-dark
```
```bash
yarn add is-dark
```
## Usage
### Check Once
To check once, simply call the default export from `is-darkmode`.
```typescript
import isDarkMode from 'is-darkmode'
isDarkMode() // true | false
```
### Subscribe to System Changes
To subscribe to system UI changes, call the `onChange` method.
```typescript
import { subscribeToColorScheme } from 'is-darkmode'
let textColor = 'black'
let bgColor = 'white'
subscribeToColorScheme((scheme) => {
switch(scheme) {
case 'dark':
textColor = 'white'
bgColor = 'black'
break;
case 'light':
textColor = 'black'
bgColor = 'white'
break;
}
})
```