Skip to content

Function: getPrefersColorScheme() ​

ts
function getPrefersColorScheme(): ColorScheme;

Returns the user's preferred color scheme according to the prefers-color-scheme CSS media feature.

Returns 'dark' only when the user has actively expressed a preference for dark; returns 'light' otherwise, including in non-browser environments (e.g. SSR) where the media query cannot be evaluated.

Returns ​

ColorScheme

The current preferred color scheme.

Example ​

ts
getPrefersColorScheme()
// => 'dark'

Since ​

1.3.0

Released under the MIT License.