PreferenceManager: colorScheme property
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The colorScheme read-only property of the PreferenceManager interface returns a PreferenceObject used to override the user's preference for the color scheme of the site.
Valid colorScheme PreferenceObject.value settings are dark and light.
Value
A PreferenceObject used to override the user's preference for the color scheme of the site.
Examples
>Basic usage
This example demonstrates how to query the user's preferred color scheme.
js
if (navigator.preferences.colorScheme.value === "dark") {
// The user prefers a dark color scheme.
} else {
// The user prefers a light color scheme.
}
Specifications
| Specification |
|---|
| Media Queries Level 5> # color-scheme-attribute> |