How can I make Bootstrap columns all the same height?
Update 2021
Bootstrap 4 + 5
Flexbox is now used by default in Bootstrap 4 (and Bootstrap 5) so there is no need for the extra CSS to make equal height columns: https://www.codeply.com/go/IJYRI4LPwU
Example:
<div class="container">
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6"></div>
</div>
</div>
Bootstrap 3
Best approach for Bootstap 3.x — using CSS flexbox (and requires minimal CSS)…
.equal {
display: flex;
display: -webkit-flex;
flex-wrap: wrap;
}
Bootstrap same height flexbox example
To only apply the same height flexbox at specific breakpoints (responsive), use a media query. For example, here is sm
(768px) and up:
@media (min-width: 768px) {
.row.equal {
display: flex;
flex-wrap: wrap;
}
}
This solution also works well for multiple rows (column wrapping): https://www.codeply.com/go/bp/gCEXzPMehZ
Other workarounds
These options will be recommended by others, but are not a good idea for responsive design. These only work for simple single row layouts w/o column wrapping.
Using huge negative margins & padding
Using
display:table-cell
(this solution also affects the responsive grid, so a@media
query can be used to only applytable
display on wider screens before the columns stack vertically)
LATEST SOLUTION (2022)
Solution 4 using Bootstrap 4 or 5
Bootstrap 4 and 5 use Flexbox by default, so there is no need for extra CSS.
Demo
<div class="container">
<div class="row ">
<div class="col-md-4" style="background-color: red">
some content
</div>
<div class="col-md-4" style="background-color: yellow">
catz
<img width="100" height="100" src="https://placekitten.com/100/100/">
</div>
<div class="col-md-4" style="background-color: green">
some more content
</div>
</div>
</div>
Solution 1 using negative margins (doesn't break responsiveness)
Demo
.row{
overflow: hidden;
}
[class*="col-"]{
margin-bottom: -99999px;
padding-bottom: 99999px;
}
Solution 2 using table
Demo
.row {
display: table;
}
[class*="col-"] {
float: none;
display: table-cell;
vertical-align: top;
}
Solution 3 using flex added August 2015. Comments posted before this don't apply to this solution.
Demo
.row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}