How to use Media Queries In Bootstrap

To implement a custom theme in Bootstrap 5, set the data-bs-theme attribute to a custom value, such as `”gfg”`, on the <html> element. Then, define your custom theme using CSS variables within a style block, overriding Bootstrap’s default variables. This allows you to tailor the appearance of elements according to your desired color scheme and aesthetics.

Example: In this example we demonstrates Bootstrap custom theme by setting data-bs-theme=”gfg”, altering text color to black and background to dark green, providing a unique visual experience.

HTML
<!DOCTYPE html>

<!-- Custom theme -->
<html lang="en"
    data-bs-theme="gfg">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <title>Bootstrap Dark Mode</title>
    <link href=
"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
        rel="stylesheet"
        integrity=
"sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
        crossorigin="anonymous">
    <style>
        [data-bs-theme="gfg"] {
            --bs-body-color: black; /* Change text color to black */
            --bs-body-bg: rgba(34, 36, 35, 0.7); /* Change background color to dark green */
        }
    </style>
</head>

<body>
    <div class="container text-center">
        <div class="mt-1">
            <h2 class="text-success">
                w3wiki
            </h2>
            <h2>It's custom theme!</h2>
        </div>
    </div>
    <script src=
"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
            integrity=
"sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
            crossorigin="anonymous">
    </script>
</body>

</html>

Output:



Bootstrap Dark Mode

Bootstrap Dark Mode is a feature that allows websites or web applications built with Bootstrap to switch to a dark color scheme, enhancing readability in low-light environments and providing a modern aesthetic option for users.

To implement Dark Mode in Bootstrap 5, utilize its built-in dark mode utility classes like ‘bg-dark’, ‘text-white’, and ‘bg-dark’ for backgrounds, text, and borders, respectively.

We have the following approaches to implement the dark mode in Bootstrap 5:

Table of Content

  • Using Global Color Mode Toggle
  • Using Component-Level Color Mode
  • Using Media Queries

Similar Reads

Using Global Color Mode Toggle

To enable dark mode globally, simply add data-bs-theme=”dark” to the element. This attribute will apply the dark color mode to all components and elements unless overridden by specific data-bs-theme attributes....

Using Component-Level Color Mode

For component-level color mode control, add the data-bs-theme attribute to specific elements. This allows you to apply different color modes to different parts of your website....

Using Media Queries

To implement a custom theme in Bootstrap 5, set the data-bs-theme attribute to a custom value, such as `”gfg”`, on the element. Then, define your custom theme using CSS variables within a style block, overriding Bootstrap’s default variables. This allows you to tailor the appearance of elements according to your desired color scheme and aesthetics....

Contact Us