mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 21:44:45 +03:00
19 lines
384 B
Markdown
19 lines
384 B
Markdown
---
|
|
title: How to detect dark mode in JavaScript
|
|
tags:
|
|
- JavaScript
|
|
- one-line
|
|
- js
|
|
layout: note
|
|
---
|
|
|
|
|
|
|
|
In this Article we will go through how to detect dark mode only using single line of code in JavaScript.
|
|
<br/>
|
|
<br/>
|
|
Let's define this short function:
|
|
|
|
```js {.wrap}
|
|
const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
``` |