Card Theme Switcher
A button that toggles 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="tsCard" style="max-width:320px"><div class="card-body text-center">
<h6 class="fw-bold" id="tsTitle">Light mode</h6>
<p class="text-secondary small" id="tsText">Toggle to switch the card theme.</p>
<button class="btn btn-outline-primary btn-sm" id="tsBtn">🌙 Switch theme</button>
</div></div>var card=document.getElementById('tsCard'),btn=document.getElementById('tsBtn'),title=document.getElementById('tsTitle'),dark=false;
btn.onclick=function(){dark=!dark;card.classList.toggle('text-bg-dark',dark);card.classList.toggle('border-0',true);title.textContent=dark?'Dark mode':'Light mode';btn.textContent=dark?'☀️ Switch theme':'🌙 Switch theme'};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.