when the dark mode is enabled and the page is reloaded for some reason, for example, if the user deliberately reloads the page or submits a form, there’s a flicker of white background all over the page before it turns dark.
It only lasts a fraction of a second. It simply does not appear professional.
all details on codepen: flicker of white background
help me please
html :
<div class='WPmodedark'><input class='check' id='WPmodedark' title='Mode Dark' type='checkbox'/>
<label class='WPim' for='WPmodedark'>
<svg class='WPOM' viewBox='0 0 24 24'><path d='M19.1 17.5c-3.3 1.4-7.1-.2-8.5-3.5-1.4-3.3.2-7.1 3.5-8.5.2-.1.5-.2.7-.3-1.6-.4-3.2-.3-4.8.4C6 7.3 4 12 5.7 16c1.7 4.1 6.4 6 10.5 4.3 1.7-.7 3-1.9 3.8-3.4-.3.3-.6.4-.9.6z'/></svg>
<svg class='WPCM' viewBox='0 0 24 24'><path d='M18.1 5.1c0 .3-.1.6-.3.9l-1.4 1.4-.9-.8 2.2-2.2c.3.1.4.4.4.7zm-.5 5.3h3.2c0 .3-.1.6-.4.9s-.5.4-.8.4h-2v-1.3zm-6.2-5V2.2c.3 0 .6.1.9.4s.4.5.4.8v2h-1.3zm6.4 11.7c-.3 0-.6-.1-.8-.3l-1.4-1.4.8-.8 2.2 2.2c-.2.2-.5.3-.8.3zM6.2 4.9c.3 0 .6.1.8.3l1.4 1.4-.8.9-2.2-2.3c.2-.2.5-.3.8-.3zm5.2 11.7h1.2v3.2c-.3 0-.6-.1-.9-.4s-.4-.5-.4-.8l.1-2zm-7-6.2h2v1.2H3.2c0-.3.1-.6.4-.9s.5-.3.8-.3zM6.2 16l1.4-1.4.8.8-2.2 2.2c-.2-.2-.3-.5-.3-.8s.1-.6.3-.8z'/><circle cx='12' cy='11' r='4'/></svg>
</label>
</div>
<script crossorigin='anonymous' integrity='sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=' src='https://code.jquery.com/jquery-3.6.0.min.js'/>
css :
/*-------- Night Mode Feature --------*/
.WPmodedark {height: 34px;}
.WPmodedark svg { width: 24px; height: 24px;vertical-align: -6px; }
.WPmodedark svg path {fill: $(white.color.wp);}.WPNM .WPmodedark svg path {fill: $(black.color.wp);}
.WPmodedark .check:checked~.NavMenu {opacity: 1; visibility: visible; z-index: 2;}
.WPim { cursor: pointer; display: block; padding: 6px 20px 8px 20px; background-position: center;}
.WPim:hover {background:rgba(0,0,0,0.2)radial-gradient( circle , transparent 2% , rgba( 0 , 0 , 0 , .2 ) 2% );}
.WPmodedark .WPim .WPOM , .WPmodedark .check:checked~.WPim .WPCM {display: block;background: olivedrab;} .check , .WPmodedark .WPim .WPCM ,.WPmodedark .check:checked~.WPim .WPOM {display: none;}
/* -- content --*/
body.WPNM , body.WPNM div.page_body {background:#101a00!important;}
script :
window.addEventListener('DOMContentLoaded', function () {
/*-- DM WP --*/
$("body").toggleClass(localStorage.toggled),
$("#WPmodedark").on("click", function () {
"WPNM" != localStorage.toggled
? ($("body").toggleClass("WPNM", !0), (localStorage.toggled = "WPNM"), $(".section-center").css("display", "block"))
: ($("body").toggleClass("WPNM", !1), (localStorage.toggled = ""), $(".section-center").css("display", ""));
}),
$("body").hasClass("WPNM") ? $("#WPmodedark").prop("checked", !0) : $("#WPmodedark").prop("checked", !1);
});