Nearby lessons

31 of 39

πŸŒ™ BS5 Dark Mode

πŸ“Œ What Is Bootstrap 5 Dark Mode?

Bootstrap 5 supports a color mode via data-bs-theme. Set data-bs-theme="dark" on <html> (or a parent) to switch to dark theme; data-bs-theme="light" for light. Use semantic classes like .bg-body and .text-body so colors follow the theme.

πŸŒ™ Enabling Dark Mode (data-bs-theme)

data-bs-theme="light" or data-bs-theme="dark" – set on <html> to switch the whole page. Bootstrap’s CSS variables (e.g. backgrounds, borders) update automatically. You can toggle it with JavaScript by changing the attribute.

πŸ…±οΈ

bootstrap Designer

Live Component Playground

html Source
Loading...
Built with Bootstrap 5.3 β€’ Enterprise Ready

πŸ”„ Toggling Theme with JavaScript

Read document.documentElement.getAttribute('data-bs-theme') and set document.documentElement.setAttribute('data-bs-theme', 'dark') or 'light' to switch. Use .bg-body and .text-body so content follows the theme.

πŸ…±οΈ

bootstrap Designer

Live Component Playground

html Source
Loading...
Built with Bootstrap 5.3 β€’ Enterprise Ready

βœ… Dark Mode Best Practices

  • Set data-bs-theme on <html> for global theme.
  • Use .bg-body and .text-body so components adapt.
  • Toggle with JS: setAttribute('data-bs-theme', 'dark'|'light').

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!BS5 Flex