Rather than using a manual toggle for dark theme you could check if the user agent prefers dark theme automatically.
Aside from that, avoid storing the preference of dark/light theme in cookies as you currently seem to be doing as they're sent to the server on every request (unless you somehow need this information server side?), localStorage or sessionStorage are just fine for this purpose (and probably easier codewise too)
Thanks for the recommendations. I really like the idea of checking the user agent for color scheme preferences. At least for the default, then they could override it.
Right now I don't have routing set up on the client's side, so the pages render on the server via PHP. I used the cookie to allow PHP to know the user's preference so it could add a class and avoid a "white flash" if I changed it on load via JS. I need to work on that and replace the cookie with localStorage.
Rather than using a manual toggle for dark theme you could check if the user agent prefers dark theme automatically.
Aside from that, avoid storing the preference of dark/light theme in cookies as you currently seem to be doing as they're sent to the server on every request (unless you somehow need this information server side?), localStorage or sessionStorage are just fine for this purpose (and probably easier codewise too)
Thanks for the recommendations. I really like the idea of checking the user agent for color scheme preferences. At least for the default, then they could override it.
Right now I don't have routing set up on the client's side, so the pages render on the server via PHP. I used the cookie to allow PHP to know the user's preference so it could add a class and avoid a "white flash" if I changed it on load via JS. I need to work on that and replace the cookie with localStorage.
if the pages are rendered on the server side and the data is used there, then a cookie is the approperiate use case :)