Open In App

How to create five equal columns in Bootstrap ?

Last Updated : 19 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In Bootstrap, creating five equal columns means dividing a row into five evenly spaced columns. This can be achieved using the Flexbox-based grid system in Bootstrap 4+. Simply add five col elements inside a row, and Flexbox automatically distributes them equally.

Approach:

  • Download the latest Bootstrap files from the official Bootstrap website and include them in your project directory.
  • Create a basic HTML template, linking the Bootstrap CSS and JavaScript files in the <head> section for proper functionality.
  • Inside the <body> tag, create a container div to hold the layout elements, providing structure and alignment to the content.
  • Within the container, create a row div to manage the columns using Bootstrap’s Flexbox grid system for responsive design.
  • Populate the row with 5 div elements, each having the col class to create five equal-width columns automatically.

Example: In this example we creates a Bootstrap-based layout with a row containing five equal-width columns. Each column is styled with a green background, padding, and margin, providing a responsive grid using Flexbox.

html
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1,shrink-to-fit=no">

    <link rel="stylesheet"
          href=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
    <script src=
"https://code.jquery.com/jquery-3.2.1.slim.min.js">
    </script>
    <script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js">
    </script>
    <style>
        .row .col {
            height: 100px;
        }
    </style>
</head>

<body>
    <div class="container px-5 py-5">
        <div class="row">
            <div class="col mx-1 bg-success">1</div>
            <div class="col mx-1 bg-success">2</div>
            <div class="col mx-1 bg-success">3</div>
            <div class="col mx-1 bg-success">4</div>
            <div class="col mx-1 bg-success">5</div>
        </div>
    </div>
</body>

</html>

Note: To distinguish between the columns, a small margin is added to each of the columns.

Output:



Next Article

Similar Reads