Open In App

Bootstrap 4 | Grid System

Bootstrap Grid System allows up to 12 columns across the page. You can use each of them individually or merge them together for wider columns. All combinations of values summing up to 12 can be used.


Grid Classes: Bootstrap grid system contains five classes which are listed below:



Components of Grid System:

Example 1: This example uses bootstrap to create an equal width column grid on all devices and screen widths.






<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Grid System</title>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
    <style>
        .col {
            text-align: center;
            border: 1px solid black;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col">
                column 1
            </div>
            <div class="col">
                column 2
            </div>
            <div class="col">
                column 3
            </div>
        </div>
    </div>
</body>
</html>

Output:

Example 2: This example uses bootstrap to create equal width responsive column grid. When the screen size is less than 576px the column automatically stack to each other.




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Grid System</title>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <div class="container"><br>
        <div class="row">
            <div class="col-sm-4"
                style="background-color:green;">
                column 1
            </div>
            <div class="col-sm-4"
                style="background-color:yellow;">
                column 2
            </div>
            <div class="col-sm-4"
                style="background-color:red;">
                column 3
            </div>
        </div>
    </div>
</body>
</html>

Output:


Example 3: This example uses bootstrap to create unequal width responsive column grid. When the screen size is less than 576px the column automatically stack to each other.




<!DOCTYPE html>
<html lang="en">
<head>
    <title>Bootstrap Grid System</title>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href=
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <div class="container"><br>
        <div class="row">
            <div class="col-sm-4"
                style="background-color:green;">
                column 1
            </div>
            <div class="col-sm-8"
                style="background-color:yellow;">
                column 2
            </div>
        </div>
    </div>
</body>
</html>

Output:


Supported Browser:


Article Tags :