Files
30-seconds-of-code/snippets/prefersDarkColorScheme.md
Isabelle Viktoria Maciohsek 52880f08ee Update document, window
2020-10-20 11:46:23 +03:00

437 B

title, tags
title tags
prefersDarkColorScheme browser,intermediate

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

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