here's how to add a light/dark mode toggle on your site that will stay persistent throughout the entire site, even when refreshing the cache.
most guides will teach you how to swap palettes but not apply it to your entire site. the query prefers-color-scheme is great and all, but not every OS uses this feature.
in order to keep a theme palette, you need to use localStorage and store the user's preferred theme. then you have to add the script on the pages you want applicable to ask for the stored variable before loading the page.
this unfortunately means you have to put the script on every page you want it on, but it's a universal solution. it is preferred that you use a static website generator like Jekyll so you don't have to update every layout to include this script manually.
you have to put your default data-theme in your <body> element that you want to display when your user first visits your website.
the script MUST be at the bottom of your body element and preferably BEFORE any scripts that take a while to load (e.g: a layout inject script) or there is going to be a buffer.
set up your palettes. note that you may even change image urls using variables. button style is not included for simplicity.
put this in a .js file in your code assets folder.
to clear your saved theme, it's as simple as Inspect, go to Console, then type in localStorage.clear(); then Run the script.