ThisCalculator

Everyday

Count Visible Columns: How Many Fit on Screen

Updated · Standard formula, shown below

Columns that fit 5
Used width
1,080 px
Result
Leftover width
120 px
Result
Total width
1200 px
You entered

This calculator works out how many columns of a given width fit across your screen or container. You enter the total width, the column width, and any gap between columns, and it returns the maximum number of columns that fit in one row. The result is a whole number, because you cannot show a partial column.

Formula

The number of columns that fit is given by:

n = floor((T + G) / (C + G))

Where:

  • T = total available width (px, em, rem, or any consistent unit)
  • C = width of one column
  • G = gap (gutter) between columns
  • n = maximum whole number of columns

The floor function rounds down to the nearest integer. The formula adds one gap to the total width because the last column does not need a trailing gap.

Worked Example

Using the default values: total width = 1200 px, column width = 200 px, gap = 20 px.

  1. Add the gap to the total width: 1200 + 20 = 1220
  2. Add the gap to the column width: 200 + 20 = 220
  3. Divide: 1220 / 220 = 5.545
  4. Round down: floor(5.545) = 5 columns

Check the used width: 5 × 200 + 4 × 20 = 1000 + 80 = 1080 px. Leftover = 1200 − 1080 = 120 px. So 5 columns fit, with 120 px of unused space on the right.

Why This Matters for Responsive Design

Knowing how many columns fit is the first step in building a grid layout. CSS frameworks like Bootstrap and Tailwind use a 12-column grid, but you often need to know how many of your own cards, product tiles, or text columns can sit side by side at a given screen width. This is especially useful when you are designing without a framework, or when you want to avoid horizontal scrolling on mobile devices.

The same calculation applies to print layouts, spreadsheet column widths, and even physical shelves or storage bins. As long as you use the same unit for all three inputs, the result is unit-agnostic.

How to Choose Column Width and Gap

The right column width depends on your content. Text columns should be roughly 45–75 characters per line for comfortable reading; that usually translates to about 450–750 px on a desktop screen. For image galleries or dashboards, the column width is driven by the smallest acceptable size of the content inside.

  • Start with the content: measure the minimum width a card or text block needs.
  • Add a comfortable gap: 16–24 px is common for web layouts.
  • Test at several screen widths: 360 px (phone), 768 px (tablet), 1280 px (laptop), 1920 px (desktop).
  • Use CSS media queries to change the number of columns at each breakpoint.

Common Mistakes and Misconceptions

One frequent error is forgetting to add the gap to the total width. If you simply divide 1200 by 220, you get 5.45, which still rounds to 5, but the leftover calculation will be wrong. The correct formula includes the extra gap because the last column does not have a gap after it.

Another mistake is mixing units: entering total width in pixels and column width in ems will produce nonsense. Always convert to the same unit first. Also, remember that the result is a maximum; you may choose to show fewer columns for aesthetic reasons.

Finally, note that this formula assumes equal-width columns and equal gaps. If you have a first column that is wider or a gap that varies, the calculation becomes a more complex packing problem that this simple formula cannot solve.

Limits of the Formula

This calculation is purely mathematical. It does not account for scrollbars, padding, borders, or margins that may reduce the actual available width. In a web page, the total width should be the content area width, not the viewport width, unless you are using box-sizing: border-box and no extra padding.

It also assumes you are placing columns in a single row. If you want multiple rows, the vertical dimension matters too, but this calculator only answers the horizontal question. For responsive grids with different numbers of columns at different breakpoints, you still need to run the calculation separately for each breakpoint.

Frequently Asked Questions

Does the gap count after the last column?

No. In a typical grid, there is no gap after the last column. That is why the formula adds one gap to the total width before dividing. If you do want a trailing gap, subtract it from the total width first, or simply ignore the leftover space.

Can I use percentages instead of pixels?

Yes, as long as all three values are in the same unit. Percentages work if the total width is 100% and each column is, say, 30% with a 2% gap. The formula still applies, but the result will be the number of columns that fit within 100%.

What if my columns have different widths?

This calculator assumes equal-width columns. For a mixed layout, you would need to sum the widths of each column plus the gaps and compare to the total width. There is no single formula for arbitrary widths; you would typically use a layout engine or a more complex algorithm.

Why does the calculator round down?

Because you cannot display a partial column. If 5.5 columns fit mathematically, you can only show 5 full columns. Rounding down is the correct behavior for layout purposes. Rounding up would cause the last column to overflow.

Does this work for CSS Grid or Flexbox?

Yes, the math is the same. CSS Grid and Flexbox both need to know how many items fit in a row, and the formula gives you that number. However, CSS Grid can also use auto-fill and minmax() to automatically determine the number of columns, which uses a similar underlying calculation.

What about scrollbars?

Scrollbars take up space, typically 15–20 px on desktop. If your layout has a vertical scrollbar, subtract its width from the total width before using the calculator. On mobile, scrollbars are usually overlay and do not affect layout.

Related

Formula used
in t | Total width | px | 1200 | 0
in c | Column width | px | 200 | 0
in g | Gap between columns | px | 20 | 0
out n | Columns that fit | - | floor((t + g) / (c + g)) | 0
out used | Used width | px | n * c + (n - 1) * g | 0
out leftover | Leftover width | px | t - used | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.