prefers-color-scheme
v1.0.2
Published
Get a user's preferred color scheme using CSS @media prefers-color-scheme
Readme
🎨 Prefers color scheme
Prefers color scheme is a package that tells you a user's preferred color scheme. It's based on the CSS @media (prefers-color-scheme). It's around 700 bytes minified, 300 bytes gzipped.
⭐ Usage
Add the dependency from NPM:
npm install prefers-color-schemeImport the package:
import prefersColorScheme from "prefers-color-scheme";Then call the function:
const colorScheme = prefersColorScheme();
// Returns "light" or "dark"💡 Browser support
This package only works in browsers that natively support @media (prefers-color-scheme), so it just returns "light" in unsupported browsers. Current browser support
By passing false as the argument, you can get "unsupported" as the value for unsupported browsers:
const colorScheme = prefersColorScheme(false);
// Returns "light", "dark", or "unsupported"🛠️ Development
Install dependencies:
yarnCompile Typescript to ES6 before publishing to NPM:
yarn build📀 Media Queries Level 5
- 🙅
prefers-reduced-motion· GitHub · NPM - 🎨
prefers-color-scheme· GitHub · NPM - 🕶️
prefers-contrast· GitHub · NPM - 🎞️
prefers-reduced-transparency· GitHub · NPM - 🌑
inverted-colors· GitHub · NPM - 🧖
environment-blending· GitHub · NPM - 💡
light-level· GitHub · NPM
📝 License
MIT

