Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
Autumn, 27 Nov 2026 - @243.95
Forum Activity: Three Stars Random | Recent Posts | Guild Recents
News: :defrag: Lo and Behold :defrag: Guild Events: Noir-vember TTRPG game jam
Super News: ++ MelonJam 2026 ~ 1st Dec to 1st Jan! ++
+  MelonLand Forum
|-+  Da Web Revival
| |-+  ✁ ∙ Web Crafting
| | |-+  ☔︎ ∙ I need Help!
| | | |-+  Dark mode flicker...but only on index?


« previous next »
Pages: [1] Print Embed
Author Topic: Dark mode flicker...but only on index?  (Read 21 times)
DrakoTheDragon
Newbie ⚓︎
*
View Profile WWWArt


Running around aimlessly, what about you?
⛺︎ My Room
iMood: DrakoTheDragon
OS: Windows

Guild Memberships:
Artifacts:
Triple HornsDevil Cursor TailJeansKitty T-ShirtStripey Scarfstarry yappin kittay
« on: Today at @147 » Toggle Font Embed

As someone who's recently added a light/dark mode toggle to my site, I'm struck with the issue plaguing many a site: dark mode flickering. But for whatever reason, only my index page flickers upon a reload.

See what (index)
I mean? (my sitemap. But any other page works for this example.)

To witness the bug in action, you need to click on the sun icon, change the colour to purple and then save beforehand. Otherwise it won't persist.

The worst thing is, I think I know what's causing it, too. I just don't know how to fix it.
In my css file, a generic :root is defined so the site displays its light mode colours by default. The flickering goes away if I remove it, but then it breaks my site until one of the radiobuttons is checked. And I can't just make one of the buttons checked by default, because then my save button breaks.

Code
:root {
  /* Background Colors: */
  --background-color: #ff6a6a;
  --content-background-color: #ffc0c0;
  --sidebar-background-color: #1bb6a4;

  /* Text Colors: */
  --text-color: #000000;
  --sidebar-text-color: #000000;
  --link-color: #00565f;
  --link-color-hover: #80bfb8;
  --header-color: black;
  --other-details-colour: black;

  /* Text: */
  --font: Open Sans, sans-serif;
  --heading-font: Chelsea Market, sans-serif;
  --font-size: 16px;

  /* Other Settings: */
  --margin: 10px;
  --padding: 20px;
  --border: 2px solid #083630;
  --round-borders: 10px;
  --sidebar-width: 300px;
}


/* DARK/LIGHT MODE STUFF */


:root:has(#light:checked) {
  /* Background Colors: */
  --background-color: #ff6a6a;  
  --content-background-color: #ffc0c0;
  --sidebar-background-color: #1bb6a4;

  /* Text Colors: */
  --text-color: #000000;
  --sidebar-text-color: #000000;
  --link-color: #00565f;
  --link-color-hover: #80bfb8;
  --header-color: black;
  --other-details-colour: black;

  /* Text: */
  --font: Open Sans, sans-serif;
  --heading-font: Chelsea Market, sans-serif;
  --font-size: 16px;

  /* Other Settings: */
  --margin: 10px;
  --padding: 20px;
  --border: 2px solid #083630;
  --round-borders: 10px;
  --sidebar-width: 300px; 

  .darkmode-only {
    display: none;
  }

  .lightmode-only {
    display: block;
  }
}

:root:has(#dark:checked) {

  /* Background Colors: */
  --background-color: black;
  --content-background-color: #2a145e;
  --sidebar-background-color: #81458F;

  /* Text Colors: */
  --text-color: #D1D1D1;
  --sidebar-text-color: #D1D1D1;
  --link-color: #a708cc;
  /*--link-color-hover: #1bb6a4;*/
  --link-color-hover: #9F7EA8;
  --header-color: white; 

  /* Text: */
  --font: Open Sans, sans-serif;
  --heading-font: Chelsea Market, sans-serif;
  --font-size: 16px;

  /* Other Settings: */
  --margin: 10px;
  --padding: 20px;
  --border: 2px solid #743e80;
  --round-borders: 10px;
  --sidebar-width: 300px;
  --other-details-colour: white;

  .darkmode-only {
    display: block;
  }

  .lightmode-only {
    display: none;
  }
}
.darkmode-only and .lightmode-only are for select elements like the surf club button on my sidebar, and thus aren't too relevant to this.
Not sure if you'd need to see my JavaScript as well, but I'll provide it if so.
Code
var r = document.querySelector(':root');

if(document.getElementById('dark').checked) {
    localStorage.setItem('theme', 'dark');}
if(document.getElementById('light').checked) {
    localStorage.setItem('theme', 'light');}

if(localStorage.getItem('theme') == 'dark'){
    document.getElementById('dark').checked = true;}
if(localStorage.getItem('theme') == 'light'){
    document.getElementById('light').checked = true;}

function savetheme() {
if(document.getElementById('dark').checked) {
    localStorage.setItem('theme', 'dark');
    console.log("Saved Theme: Light");}
if(document.getElementById('light').checked) {
    localStorage.setItem('theme', 'light');
    console.log("Saved Theme: Dark");}  
}
With that in mind...any tips?

Logged

"You don't have to be ready. You just have to do it."

https://64.media.tumblr.com/778f45cbfe9eb3cbad98b689ed000130/9eb06495f8f9f32f-4a/s250x400/ea294f8fe0cf59e5c75a2e81b3ab1f3c661c4e5a.gifv
https://64.media.tumblr.com/2bfb535f7d789033ae3df0112a6ed2fa/81a7afd7695dcc71-b7/s100x200/b277b2408c22f9e1963a9d96aa3fa8624a656592.gifvhttps://64.media.tumblr.com/f40ce174e969e0b423240343c0695df8/e1dd46eba178dc71-51/s100x200/f2ce4c50549d6377d5d2acfd84b9a90d13467271.pnjhttps://64.media.tumblr.com/a1dbb1f8f4b954bd3848593bc2a9ad80/e9a831999458d974-9a/s250x400/6e2a09e794fb5335067f513b07ed80efdff9eeff.gifv

Artifact Swap: oh heck it has a bombStupid wall, MOVE!sunsetChaos rune500 coin
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Guide | Rules | Whos a Mod? | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 Melon
Land
Forum Art Hub Chat Webring Explore Random Recent Tenement Arcade Want to Login or Join ? Web Craft Guide Graphic Catalogue Wiki Help I'm Lost! Link Land Newsletters Image Stream Minecraft: Online
Zap!
Passport Sites tamaNOTchi Asatte Add your site?
Aero Archive Onio Cafe 32 Bit Cafe Status Cafe