mercredi 19 avril 2023

checkbox checked when dark mode is activated / control checkbox via js or other solution

made a html/css website with a toggle switch checkbox that activates dark mode via :root / body:has(.toggleclass:checked)... toggle works fine, but now i want dark mode to appear when someone has enabled dark mode on his device. i know i could put the dark mode values in @media (prefers-color-scheme: dark) {...} and it would work, but then the toggle doesn't work anymore. is there a possibility to check the checkbox when dark mode is activated on a device?

        <div id="toggle-switch">
            <input id="toggle" type="checkbox" class="darkmode">
            <label for="toggle" >
            </label>  
        </div>

i think it only works with js, but my js skills are very poor...




Aucun commentaire:

Enregistrer un commentaire