🎞️ Get a user's transparency preference
Prefers reduced transparency is a package that tells you whether a user prefers less transparency. It’s based on the CSS @media (prefers-reduced-transparency)
, which is part of Media Queries Level 5. It’s around 700 bytes minified, 300 bytes gzipped.
Add the dependency from NPM:
npm install prefers-reduced-transparency
Import the package:
import prefersReducedTransparency from "prefers-reduced-transparency";
Then call the function:
const contrastPreference = prefersReducedTransparency();
// Returns "reduce" or "no-preference"
This package only works in browsers that natively support @media (prefers-reduced-transparency)
, so it just returns "no-preference"
in unsupported browsers. Current browser support
By passing false
as the argument, you can get "unsupported"
as the value for unsupported browsers:
const contrastPreference = prefersReducedTransparency(false);
// Returns "reduce", "no-preference", or "unsupported"
Install dependencies:
yarn
Compile Typescript to ES6 before publishing to NPM:
yarn build
prefers-reduced-motion
· GitHub · NPMprefers-color-scheme
· GitHub · NPMprefers-contrast
· GitHub · NPMprefers-reduced-transparency
· GitHub · NPMinverted-colors
· GitHub · NPMenvironment-blending
· GitHub · NPMlight-level
· GitHub · NPMMIT