I have the following code available: And also this javascript code; var swapStyleSheet = function (sheet) { document.getElementById('pagestyle').setAttribute('href', sheet); storebackground(sheet); } var storebackground = function (swapstylesheet) { localStorage.setItem("sheetKey", swapstylesheet); //you need to give a key and value } var loadbackground = function () { document.getElementById('pagestyle').setAttribute('href', localStorage.getItem('sheetKey')); } window.loadbackground(); It works smoothly in the following usage. When the Dark Style Sheet CSS changes, all other codes first display the old CSS and then the new one comes in, but in this case, the new one appears as if it hasn't changed at all. However, the issue is that when I run this code, the site goes themeless until a theme is selected. How can we set this as default, what code should we add?