Skip to content

Instantly share code, notes, and snippets.

@sombriks
Created June 25, 2025 23:08
Show Gist options
  • Save sombriks/c2e5a7710a6830695d4b688e3a598baf to your computer and use it in GitHub Desktop.
Save sombriks/c2e5a7710a6830695d4b688e3a598baf to your computer and use it in GitHub Desktop.
bootstrap color scheme
// <script defer src="base.js"></script>
const setTheme = e => {
if (e.matches) document.querySelector(":root").dataset.bsTheme = "dark";
else document.querySelector(":root").dataset.bsTheme = "light";
}
const matchMedia = window.matchMedia('(prefers-color-scheme: dark)');
matchMedia.onchange = setTheme;
setTheme(matchMedia);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment