Theme Toggle Switch
A switch that flips a card between light and dark themes.
Requires Bootstrap 5. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><div class="card border-0 shadow-sm" id="tpCard" style="max-width:300px"><div class="card-body text-center">
<h6 class="fw-bold mb-2" id="tpTitle">Light theme</h6>
<p class="small text-secondary mb-3" id="tpDesc">Click below to switch themes.</p>
<div class="form-check form-switch d-inline-block"><input class="form-check-input" type="checkbox" id="tpSwitch" style="transform:scale(1.4)"></div>
</div></div>var card=document.getElementById('tpCard'),sw=document.getElementById('tpSwitch'),title=document.getElementById('tpTitle'),desc=document.getElementById('tpDesc');
sw.onchange=function(){var d=sw.checked;card.classList.toggle('text-bg-dark',d);title.textContent=d?'Dark theme':'Light theme';desc.textContent=d?'Easier on the eyes at night.':'Click below to switch themes.';desc.classList.toggle('text-secondary',!d);desc.classList.toggle('text-light',d)};Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.