Files
30-seconds-of-code/snippets/prefersLightColorScheme.md
2020-09-15 21:52:00 +03:00

442 B

title, tags
title tags
prefersLightColorScheme browser,intermediate

Returns true if the user color scheme preference is light, false otherwise.

  • Use window.matchMedia() with the appropriate media query to check the user color scheme preference.
const prefersLightColorScheme = () =>
  window && window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches;
prefersLightColorScheme(); // true