Skip to content

Instantly share code, notes, and snippets.

@joelmichael
Created September 3, 2021 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelmichael/a9720f3e923238a79670fb48450be0af to your computer and use it in GitHub Desktop.
Save joelmichael/a9720f3e923238a79670fb48450be0af to your computer and use it in GitHub Desktop.
document.addEventListener('DOMContentLoaded', function(event) {
var changeColorScheme = function() {
var html = document.querySelector('html');
if (this.matches)
html.classList.add('dark');
else
html.classList.remove('dark');
}
var mm = window.matchMedia('(prefers-color-scheme: dark)');
mm.addEventListener('change', changeColorScheme);
changeColorScheme.call(mm);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment