Get to know MDN better
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The User Preferences API allows page authors to programmatically override user preference-related media query settings.
Supporting user agents define values for the CSS media queries prefers-color-scheme, prefers-contrast, prefers-reduced-motion, prefers-reduced-transparency, and prefers-reduced-data. The PreferenceManager object provides programmatic access to these preferences, allowing page authors to listen for preference changes and override them.
The following code implements a minimal dark mode toggle.
The HTML features a form containing three radio buttons. These radio buttons set the color-scheme field to either system, light, or dark.
The JavaScript registers change event listeners for all elements named color-scheme. If the value is system, the handler clears the color scheme override. Otherwise, it requests a color scheme override with the value of the input element.
| Media Queries Level 5 # preferences-attribute |
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
This page was last modified on Mar 23, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.