Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 58 ยท Layout

Responsive Columns

Learn how Bootstrap 5.3 columns change width at each breakpoint with col-sm to col-xxl classes, how to mix them, and how row-cols sets equal card counts.

A grid that always looks the same is not much help on the web. A phone is 360 pixels wide, a laptop is 1,400, and a good layout needs to rearrange itself for both. Bootstrap solves this by letting you attach a column width to a breakpoint: "stack on phones, sit side by side from tablets up".

In this lesson you will use the responsive column classes (col-sm-* to col-xxl-*), mix several breakpoints on one column, and use row-cols-* to control how many equal columns a row holds. If the grid itself is new to you, start with The Grid System, and keep the table of widths from Breakpoints and Responsive Design handy.

The responsive column classes

A plain col-6 takes six of twelve columns at every screen size. Add a breakpoint name in the middle and the width only applies from that screen size upward:

Class Applies from Viewport width
col-* always (extra small and up) 0 px and up
col-sm-* small 576 px and up
col-md-* medium 768 px and up
col-lg-* large 992 px and up
col-xl-* extra large 1200 px and up
col-xxl-* extra extra large 1400 px and up

Bootstrap is mobile-first: the classes are min-width media queries. A column with no matching class at the current width has no width of its own, and since a .row is a flex container with wrapping, each such column takes the full row. That is why a layout "stacks" on phones without you writing anything.

Here is the most common pattern: three equal columns on medium screens and larger, stacked below that.

Stack on phones, three across from md

Make your browser window narrower than 768 pixels and the three boxes pile up into one column; widen it and they line up again. The preview takes its width from your window, so resizing the window is how you test breakpoints here. The gy-2 class adds vertical spacing between the stacked rows; you will meet it properly in Gutters, Alignment and Ordering.

flowchart LR
  A["Viewport under 768 px"] --> B["col-md-4 not active<br/>each column fills the row"]
  C["Viewport 768 px or more"] --> D["col-md-4 active<br/>three columns, 4 of 12 each"]

The same markup, two layouts: the breakpoint decides which rule applies.

Mixing breakpoints

One column can carry several width classes. Each class takes over at its breakpoint and stays in force until a larger one replaces it. This is the real power of the grid, because a single element can describe its width at every size.

HTML
<div class="col-12 col-sm-6 col-lg-4 col-xl-3">...</div>

Read that left to right as a story:

  1. Under 576 px: col-12, a full row.
  2. From 576 px: col-sm-6, half a row (two per row).
  3. From 992 px: col-lg-4, a third of a row (three per row).
  4. From 1200 px: col-xl-3, a quarter of a row (four per row).
One column, four widths

The little script is not part of Bootstrap; it only reads the width and prints which breakpoint is active, so you can see the classes switch as you resize.

You rarely need every breakpoint. Start with the smallest layout (usually just col-12, or nothing), then add a class only where the design should change. Two or three classes per column is typical. Skipping breakpoints is fine: col-md-6 col-xl-4 leaves lg using the md width.

Different layouts at different sizes

Widths do not have to be equal, and they do not have to match between rows. A classic content-plus-sidebar page gives the main column more room on large screens and lets both stack on small ones:

Main column and sidebar

Notice the semantic elements. Columns are just boxes, so <main>, <aside>, <section> and <article> work as well as <div>. Prefer the element that describes the content.

Equal columns without numbers

Sometimes you want "equal columns" without counting to twelve. A bare col-md (no number) gives every column in the row an equal share from that breakpoint upward:

HTML
<div class="row">
  <div class="col-md">Equal</div>
  <div class="col-md">Equal</div>
  <div class="col-md">Equal</div>
</div>

Add or remove a column and the rest share the row again. You can also give one column a number and let the others split what is left, as in col-md-6 next to two plain col-md columns.

Equal card counts with row-cols-*

Repeating the same col-md-4 on every card gets tiresome, and it is easy to forget one. The row-cols-* classes go on the row instead and say how many columns fit per line. Every direct child then becomes a column automatically, with no col class needed.

Class Meaning
row-cols-1 to row-cols-6 that many columns per row (up to six)
row-cols-auto each column is as wide as its content
row-cols-md-3 three per row from the md breakpoint

The numbers go up to 6 because 6 divides 12 nicely, and seven or more per row would be too tight for most content. All six breakpoints have their own version, such as row-cols-sm-2 or row-cols-xl-4, and you can combine them on one row.

row-cols: 1, then 2, then 4 per row

Resize the window: one card per line on phones, two from 576 px, four from 992 px. The seventh card simply starts a new line, and it keeps the same width as the others instead of stretching, which is the other big advantage of row-cols over per-column numbers.

Inside a row-cols row you can still override a single column: <div class="col-lg-6"> ignores the row's count for that one item. And .col items inside a row-cols-auto row shrink to their content, which is handy for tag lists and button groups.

Common mistakes

  • Forgetting the row. Columns belong inside .row, which belongs inside a container. See Containers.
  • Thinking col-md-6 means "only at md". It means "md and up". To change the layout again at a larger size, add another class such as col-xl-4.
  • Adding up to more than 12. Extra columns do not break the layout; they wrap to a new line. That is sometimes useful, and the next lessons use it on purpose.
  • Testing only at one size. Resize through every breakpoint, not just the one you are developing on.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the class col-lg-4 do?

    Bootstrap's breakpoint classes use min-width media queries, so the width applies at the named breakpoint and every larger size.
  2. 2. A column has the classes col-12 col-md-6. How wide is it at 600 px?

    600 px is below the md breakpoint (768 px), so only col-12 applies and the column fills the row.
  3. 3. Where do you put row-cols-md-3?

    The row-cols classes belong on the .row, and they set how many direct-child columns fit per line from that breakpoint.
  4. 4. How many columns can row-cols-* request per row?

    row-cols-1 through row-cols-6 exist. For finer control use individual col-* classes.

Summary

  • Column classes take a breakpoint infix: col-sm-*, col-md-*, col-lg-*, col-xl-*, col-xxl-*.
  • They are min-width rules, so a width applies at that size and above; below it, columns stack.
  • One column can combine several breakpoint classes, each one taking over at its size.
  • col-md with no number shares the row equally; row-cols-* on the row sets how many equal columns fit per line.
  • Resize your window to test every breakpoint.

Next lesson: Gutters, Alignment and Ordering.