if (window.matchMedia('(prefers-color-scheme: dark)').matches) { console.log('User prefers dark mode on his device'); }