Files
30-seconds-of-code/snippets/prefersLightColorScheme.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

495 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
prefersLightColorScheme browser,intermediate 2020-05-04T12:50:35+03:00 2020-10-22T20:24:04+03:00

Checks if the user color scheme preference is light.

  • 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