CSS Variables in Bootstrap
Bootstrap 5 uses CSS custom properties (variables) such as --bs-primary and --bs-body-bg. You can change them with a few lines of CSS, without needing Sass.
Components also have their own variables, for example a button:
Color Modes (Dark Mode)
Since Bootstrap 5.3 you can switch between light and dark themes by adding data-bs-theme to any element.
data-bs-theme="dark"on<html>changes the whole page- Put it on a single card or navbar to make only that part dark
- Use
bg-body,text-bodyandbg-body-tertiaryinstead of fixed colors so they adapt to the theme
Dark Mode Toggle with Memory
Clicking the button switches the whole page between light and dark colors. After refreshing, the page remembers your choice.
Follow the System Preference
Tips
- Put the theme script in the
<head>to avoid a white flash before dark mode applies - Test images and logos in both themes
- Avoid hard-coded colors like
bg-whitewhen you support dark mode. Usebg-body
Conclusion
CSS variables and color modes make Bootstrap customization simple. You can create a brand theme and a dark mode without compiling anything.

