Bootstrap’s grid system is a responsive, 12‑column layout that uses container, row, and column classes to arrange content. It adapts automatically to screen size by applying CSS media queries for predefined breakpoints.
Background and History
Bootstrap was launched by Twitter engineers in 2011 as an internal tool to standardise UI components. The grid was one of the first features added, borrowing the concept of a 12‑column layout from the 960 Grid System. Over successive releases, Bootstrap evolved from a 2‑column, 12‑column, and 16‑column grid to a single 12‑column system that remains the core of the framework.
How the Grid System Works
At its core the grid is built on three structural classes:
- .container – sets a fixed width (or full width on small screens) and centers the content.
- .row – creates a horizontal group of columns and applies negative margins to counteract the column padding.
- .col‑* – defines a column width that spans a certain number of the 12 available units. The asterisk is replaced by a breakpoint and a number, such as
.col-md-4for medium screens.
(number / 12) × 100%. For example, .col-6 occupies 50% of the row width.
Responsive Breakpoints and Utility Classes
Bootstrap defines five standard breakpoints:
xs– < 576px (auto‑generated, no class needed)sm– ≥576pxmd– ≥768pxlg– ≥992pxxl– ≥1200pxxxl– ≥1400px (added in Bootstrap 5)
.col-12 .col-sm-6 .col-md-4 .col-lg-3
This tells the element to take the full width on extra‑small screens, half the width on small screens, one‑third on medium, and one‑quarter on large screens.
Choosing the Right Container
Bootstrap offers three container types:
.container– fixed width that changes at each breakpoint..container-fluid– full width across all viewports..container-xxl– similar to.containerbut with a maximum width that matches thexxlbreakpoint.
.container when you want consistent padding and a maximum width that matches the design system. Use .container-fluid for full‑width sections such as hero banners or background images.
Common Problems and How to Fix Them
1. Gutters disappear after nesting rows. The negative margin on rows only applies to direct children. When a row is nested inside a column, add .row inside the column and use .g-0 if you want to remove gutters.
2. Columns collapse on small screens. If you use .col-* without specifying a breakpoint, the column will stack on all screens. Add a breakpoint, e.g., .col-sm-4, to keep columns side by side on small screens.
3. Overflow due to fixed width content. Images or tables that exceed the column width can break the layout. Use .img-fluid or .table-responsive to make them adapt.
4. Unintended horizontal scrolling. This often occurs when the total column width exceeds 12 units in a row. Check that the sum of all .col‑* classes equals 12 or less.
Comparisons with Other Layout Systems
Bootstrap’s grid is built on flexbox, which offers flexible alignment, order, and wrapping. Compared to the older float‑based grid, flexbox provides easier vertical alignment and reordering without extra CSS.
CSS Grid, introduced in modern browsers, allows two‑dimensional layouts (rows and columns) with more expressive syntax. While Bootstrap’s grid is one‑dimensional, it is still widely adopted because it is simple, well‑documented, and works out of the box with many UI components.
Alternatives to Bootstrap Grid
Other frameworks and native CSS solutions can replace Bootstrap’s grid:
- Foundation – offers a 12‑column flexbox grid with similar breakpoints.
- Bulma – uses a flexbox grid with a 12‑column system and no JavaScript.
- Tailwind CSS – utility‑first framework that lets you compose grid layouts with
grid-cols-12and responsive prefixes. - Pure CSS Grid – write
display: grid;and definegrid-template-columns: repeat(12, 1fr);for a 12‑column layout.
Frequently Asked Questions
How many columns does Bootstrap’s grid have?
The system uses 12 equal‑width columns. Each column’s width is a fraction of the total, so .col-6 is 50% and .col-3 is 25%.
Can I change the number of columns in Bootstrap?
Bootstrap’s core grid is fixed at 12 columns. To modify it, you would need to customize the Sass variables and rebuild the CSS, which is not recommended for most projects.
What happens if I add more than 12 column units in a row?
Bootstrap will wrap the excess columns onto a new line. However, this can create visual gaps and unexpected spacing, so keep the total units at 12 or less.
How do I create equal‑height columns?
Because the grid uses flexbox, columns automatically stretch to the height of the tallest sibling. If you need equal height without flexbox, you can use .h-100 or custom CSS.
Is the Bootstrap grid mobile‑first?
Yes. The default .col-* classes apply to all screen sizes unless a breakpoint is specified, which means styles are defined for the smallest screens first and then overridden at larger breakpoints.
Can I use the grid without loading the entire Bootstrap library?
Bootstrap’s grid CSS can be extracted from the full library or built from its source files. This allows developers to include only the grid classes and reduce file size.