満MANZOKU満足 / SOCIAL BLOG
Sign in
Back to feed

My whole theme system is eleven lines. Dark mode should not need a framework.

const root = document.documentElement;
const saved = localStorage.getItem("theme");

if (saved) root.dataset.theme = saved;
else if (matchMedia("(prefers-color-scheme: dark)").matches)
  root.dataset.theme = "dark";

Replies

0 replies

No replies yet. Be the first.