Bootstrap
Bootstrap

How to implement dark mode using Bootstrap’s new features?

March 18, 2026

Bootstrap 5.3's built-in color modes flip your site to dark theme instantly—just toggle one data-bs-theme="dark" attribute and every button, card, and nav switch smoothly with zero extra CSS.​

Bootstrap finally nailed dark mode in v5.3: drop data-bs-theme="dark" on the HTML tag or any component, and CSS variables handle the rest—backgrounds darken, text lightens, perfect contrast everywhere. Pair it with a simple toggle button that swaps the attribute via JS, saves the choice in localStorage, and even respects your system's prefers-color-scheme. No compiling Sass, no duplicate stylesheets, just pure, native-feeling theme switching that loads fast and works on any element.

Code

<html data-bs-theme="light">
<body>
  <div class="container py-4">
    <button class="btn btn-outline-secondary mb-3" onclick="flipTheme()"> Dark Mode</button>
    <div class="card">
      <div class="card-body">Watch this switch colors!</div>
    </div>
  </div>

  <script>
    function flipTheme() {
      const root = document.documentElement;
      const isDark = root.getAttribute('data-bs-theme') === 'dark';
      root.setAttribute('data-bs-theme', isDark ? 'light' : 'dark');
    }
  </script>
</body>
      
Hire Now!

Need Help with Bootstrap Development ?

Ready to leverage the power of conversational AI? Start your project with Zignuts expert AI developers.
bg-image
download-image
Company Deck
PDF, 3MB
© 2026 Zignuts Technolab. All Rights Reserved.
branch imagesbranch imagesbranch imagesbranch imagesbranch imagesbranch images