About Lesson
Bootstrap 5 Dark Mode:
Using Bootstrap’s data-bs-theme="dark"
:
Bootstrap 5.3 introduced data-bs-theme
for easy theme switching.
- Adding
data-bs-theme="dark"
on<body>
automatically applies dark mode styles.
Example:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap 5 Dark Theme</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body data-bs-theme="dark">
<div class="container p-5">
<h2>Dark Mode with Bootstrap 5</h2>
<p>This page uses the built-in Bootstrap dark theme.</p>
<button class="btn btn-primary">Primary Button</button>
<button class="btn btn-light">Light Button</button>
</div>
</body>
</html>
Output:
