Open In App

Bootstrap 5 Color Modes

Bootstrap 5 Color Modes is a new feature included in Bootstrap v5.3.0. It now has color modes or themes, and users can choose between the default light mode and the new dark mode. They can also make their own color mode or theme by using the styles that are already there as a model. 

Bootstrap 5 Color Modes Options:



Example 1: In this example, we will see the implementation of Dark Mode on a Collapse Button.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link href=
          rel="stylesheet"
        integrity=
"sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" 
          crossorigin="anonymous" />
</head>
  
<body class="m-3">
    <center>
        <h1 class="text-success">GeeksforGeeks</h1>
        <strong>Bootstrap 5 Dark Mode Collapse Button</strong> <br />
  
        <div class="dropdown my-2 d-inline-block" 
             data-bs-theme="light">
            <button class="btn btn-success" type="button" 
                    data-bs-toggle="collapse"
                data-bs-target="#GFGdefaultcollapse">
                Default Collapse Button
            </button>
  
            <div class="collapse" id="GFGdefaultcollapse">
                <div class="card card-body mt-2 mb-2">
                    GFG is a Computer Science portal for geeks.
                </div>
            </div>
  
            <div class="dropdown d-inline-block" data-bs-theme="dark">
                <button class="btn btn-success" type="button" 
                        data-bs-toggle="collapse"
                        data-bs-target="#GFGdarkcollapse">
                    Dark Collapse Button
                </button>
  
                <div class="collapse" id="GFGdarkcollapse">
                    <div class="card card-body mt-2 text-light">
                        GFG is a Computer Science portal for geeks.
                    </div>
                </div>
  
                <script src=
                    integrity=
"sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
                    crossorigin="anonymous"></script>
            </div>
        </div>
    </center>
</body>
  
</html>

Output:



Dark Mode with Collapse Button

Example 2: In this example, we will see the implementation of Nesting Color Modes, in which we will create an outer dark mode with a nested light mode.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link href=
          rel="stylesheet"
        integrity=
"sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
          crossorigin="anonymous" />
</head>
  
<body class="m-3">
    <center>
        <div data-bs-theme="dark" 
             class="p-2 mt-2 text-body bg-body">
            <h1 class="text-success">GeeksforGeeks</h1>
            <strong>Bootstrap 5 Nesting Color Modes</strong> <br />
            <p>
                <strong>dark</strong> theme in background.
            </p>
  
            <div class="dropdown mb-4" data-bs-theme="dark">
                <button class="btn btn-success" type="button" 
                        data-bs-toggle="collapse"
                        data-bs-target="#GFGdefaultcollapse">
                    Light Collapse Button
                </button>
  
                <div class="collapse" data-bs-theme="light" 
                     id="GFGdefaultcollapse">
                    <div class="card card-body mt-2 mb-2 text-dark">
                        GFG is a Computer Science portal for geeks.
                    </div>
                </div>
            </div>
  
            <!--This is the div with nested light mode.-->
            <div data-bs-theme="light" 
                 class="p-3 text-body bg-body rounded">
                <h1 class="text-success">GeeksforGeeks</h1>
                <p>
                    <strong>light</strong> theme in background.
                </p>
  
                <div class="dropdown" data-bs-theme="light">
                    <button class="btn btn-success" type="button" 
                            data-bs-toggle="collapse"
                        data-bs-target="#GFGdarkcollapse">
                        Dark Collapse Button
                    </button>
  
                    <div class="collapse" data-bs-theme="dark" 
                         id="GFGdarkcollapse">
                        <div class="card card-body mt-2 text-light">
                            GFG is a Computer Science portal for geeks.
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script src=
            integrity=
"sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
            crossorigin="anonymous"></script>
    </center>
</body>
  
</html>

Output:

Nesting Color Modes

Reference: https://getbootstrap.com/docs/5.3/customize/color-modes/


Article Tags :