Files
reference/note/javascript/misc/detect-dark-mode.md
T
2022-10-18 11:37:51 +08:00

384 B

title, tags, layout
title tags layout
How to detect dark mode in JavaScript
JavaScript
one-line
js
note

In this Article we will go through how to detect dark mode only using single line of code in JavaScript.

Let's define this short function:

const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;