Bootstrap

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

March 18, 2026

download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!

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 ?

Work with our skilled bootstrap developers to accelerate your project and boost its performance.
**Hire now**Hire Now**Hire Now**Hire now**Hire now

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

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>