How to Create Two Column Layout in Bootstrap Easily
To create a two column layout in Bootstrap, use the
row class to create a horizontal group and add two col classes inside it, like col-6 for equal width columns. Bootstrap's grid system automatically handles the layout and responsiveness.Syntax
Bootstrap uses a grid system with rows and columns. A row groups columns horizontally. Columns use classes like col-6 to take half the width (6 out of 12 parts). You can adjust column widths by changing the number after col-.
html
<div class="row"> <div class="col-6">Column 1</div> <div class="col-6">Column 2</div> </div>
Output
Two side-by-side boxes labeled 'Column 1' and 'Column 2', each taking half the container width.
Example
This example shows a simple two column layout where each column takes half the width on all screen sizes. The columns stack vertically on very small screens automatically.
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Two Column Layout</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container mt-4"> <div class="row"> <div class="col-6 bg-primary text-white p-3">Column 1</div> <div class="col-6 bg-secondary text-white p-3">Column 2</div> </div> </div> </body> </html>
Output
A page with two colored boxes side by side labeled 'Column 1' and 'Column 2', each occupying half the width on desktop and stacking on small screens.
Common Pitfalls
- Not wrapping columns inside a
rowcan break the layout. - Using column widths that add up to more than 12 causes wrapping or overflow.
- For responsiveness, use breakpoint prefixes like
col-md-6to control when columns stack.
html
<!-- Wrong: columns not inside a row --> <div class="col-6">Column 1</div> <div class="col-6">Column 2</div> <!-- Right: columns inside a row --> <div class="row"> <div class="col-6">Column 1</div> <div class="col-6">Column 2</div> </div>
Output
The wrong code shows columns stacked vertically without proper spacing; the right code shows two columns side by side.
Quick Reference
| Class | Description |
|---|---|
| row | Container for columns, creates horizontal group |
| col-6 | Column that takes 6/12 (half) width on all screen sizes |
| col-md-6 | Column takes half width on medium screens and up, stacks on smaller |
| container | Centers content and adds horizontal padding |
| p-3 | Padding utility for spacing inside columns |
Key Takeaways
Wrap columns inside a
row to create a proper grid layout.Use
col-6 to create two equal-width columns in Bootstrap's 12-column grid.Add responsive prefixes like
col-md-6 to control layout on different screen sizes.Ensure column widths add up to 12 or less to avoid layout issues.
Use Bootstrap utility classes like
p-3 for spacing inside columns.