Menu
Bootstrap 5 Dark Mode
Dark Mode
By default, bootstrap pages have a white (light) background color.
If you want to change the whole page to a darker color, you can add data-bs-theme="dark" to the <html> element:
Example
<!DOCTYPE html>
<html lang=”en” data-bs-theme=”dark”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h1>My Page</h1>
<p>Lorem ipsum text.</p>
<div>
<div>A card.</div>
</div>
<p>Some buttons:</p>
<button type=”button”>Primary</button>
<button type=”button”>Secondary</button>
<button type=”button”>Success</button>
</div>
</body>
</html>
Dark Mode For Components
If you don’t want the whole page to have a darker color, but only specific components, you can add the data-bs-theme="dark" attribute to the specified component.
For example, add dark mode to a table:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h2>Dark Mode Table</h2>
<table data-bs-theme=”dark”>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Or for example, add dark mode to a dropdown menu:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h2>Dark Mode Dropdown</h2>
<p>Click on the dropdown menu to see the effect.</p>
<div data-bs-theme=”dark”>
<button type=”button” data-bs-toggle=”dropdown”>
Dropdown button
</button>
<ul>
<li><a href=”#”>Link 1</a></li>
<li><a href=”#”>Link 2</a></li>
<li><a href=”#”>Link 3</a></li>
</ul>
</div>
</div>
</body>
</html>