Files
reference/source/_posts/note/javascript/misc/detect-dark-mode.md
T
2022-11-16 14:10:09 +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;