Detects the user's preferred color scheme.
Uses the prefers-color-scheme media query to determine if the user prefers a light or dark theme.
prefers-color-scheme
"light" if the user prefers a light theme, "dark" if dark.
"light"
"dark"
const theme = getThemePreference();console.log(theme); // "light" or "dark" Copy
const theme = getThemePreference();console.log(theme); // "light" or "dark"
1.1.0
Detects the user's preferred color scheme.
Uses the
prefers-color-scheme
media query to determine if the user prefers a light or dark theme.