Adding cookies on webpages for persistent dark mode.

Hello there! I hope in times like these, you’re safe.
I have been struggling to achieve persistence dark mode while navigating two pages. The page contents turn back to default color while from navigating from pages. I’m an absolute novice/beginner in javascript. This is my two page sample html gist.github.com/samiuljoy
Could you please help me to add persistent dark mode among these two html pages.
Greatly appreciate this website, keep up the good work c:

You are not storing a value in sessionStorage or cookie. The value get reset after page refresh.

1 Like

Learn more about how to save and load cookies

1 Like

I would suggest localStorqge over sessionStorage, for localStorage persists your selection across multiple browser instances: https://www.kirupa.com/things_to_do_with_data/web_storage.htm

I will try to provide a longer answer this evening, but combining a storage solution with a JS check that sets a dark mode class at the root HTML layer might do the trick.

2 Likes