CSS Multi-Column Layout for Articles and Galleries
Flexbox arranges items along one axis; Grid places them into a two-dimensional track system. Multi-column layout does something neither of them does: it takes a single stream of content â paragraphs, headings, quotes, images in document order â and flows it down one column and across into the next, the way a newspaper or a print magazine does. That distinction matters more than it sounds. Columns are not a row of equal-height boxes you control individually; they are a continuous text flow the browser balances for you. Once that clicks, multi-column becomes the right tool for long-form article typography, sidebar-free feature spreads, and surprisingly robust masonry-style image grids â and the wrong tool the moment you need per-item control, which is where Grid takes over.
When a column flow beats a grid of boxes
Consider a 2,000-word essay. With Grid you would split the text into chunks yourself, decide how many paragraphs go in each cell, and rebalance whenever the font size changes. With multi-column you write the essay as one element and let the browser perform the split, reflowing perfectly when the viewport, zoom level, or user font size shifts. The content order stays linear for screen readers and search engines â a real accessibility advantage over many masonry hacks built with absolute positioning. The trade-off is control: you cannot easily make column two taller than column one, pin an image to the top of the third column, or reorder items. Multi-column is a typesetting engine for continuous content, not a widget layout system.
column-count versus column-width, and the shorthand that mixes them
The two sizing properties encode different intents. column-count: 3 says "give me exactly three columns, whatever width that requires." column-width: 18rem says "make columns at least 18rem wide; use as many as fit." When both are set, the browser satisfies both constraints, so column-width: 16rem; column-count: 4 yields at most four columns of at least 16rem â whichever limit binds first wins. The columns shorthand writes them in the order count then width, mirroring the font shorthand's habit of packing related values:
| Declaration | Intent | Result on a 1,200px container |
|---|---|---|
| column-count: 3 | Fixed count | Three 400px columns |
| column-width: 240px | Fluid, size-driven | Up to five columns |
| columns: 3 240px | Both constraints | Three columns, never below 240px |
| column-count: 3; column-gap: 2rem | Fixed count, custom gutter | Three columns with a 32px rule space |
For responsive articles, column-width alone is usually the better default: no media queries, no breakpoint math, and the column count adapts to whatever space the layout gives you. For a strict three-column feature layout, reach for column-count. The gutter is column-gap, and the column-rule property draws a visible divider between columns using the same syntax as border â note that a rule is decorative and does not take up space, so the gap still governs spacing.
.feature-article {
column-width: 16rem;
column-gap: 2.5rem;
column-rule: 1px solid #e2e8f0;
hyphens: auto;
text-align: justify;
}
.feature-article p {
margin-block-end: 1em;
orphans: 2;
widows: 2;
}
.feature-article h2 {
column-span: all;
margin-block: 1.5em 0.5em;
font-size: 1.75rem;
}
.feature-article blockquote.pull {
column-span: all;
margin-block: 1.5rem;
padding-block: 1rem;
padding-inline: 1.5rem;
border-block: 2px solid #0f172a;
font-size: 1.35rem;
font-style: italic;
text-align: center;
}
The orphans and widows properties set the minimum number of lines that must remain at the bottom of one column or the top of the next when a paragraph is split â the print-typography details that make columned text feel professional rather than chopped.
Balancing, breaks, and column-span
By default, columns are balanced: the browser equalizes their heights so no column is dramatically longer than its neighbors, even for a short last column. column-fill: balance is the default; column-fill: balance-all considers the full height of the container rather than the content's natural height, which matters inside fixed-height scrollers. You almost never need to change it.
column-span: all is the escape hatch for elements that should break the flow and span every column â section headings, pull quotes, hero images, ad slots. A spanning element interrupts the flow at its document position: text before it flows into the columns above, text after it starts fresh below. That interruption is why an over-eager use of column-span: all on many small elements can shatter the layout into thin unusable bands; reserve it for a handful of deliberate interruptions.
Break control uses the same logical properties that govern paged media: break-inside: avoid keeps a card, image, or list item from being sliced across two columns; break-before and break-after force or avoid breaks around specific elements. In screen contexts the column-break-* aliases exist for compatibility, but the break-* family is what you should write today.
Building a masonry-style gallery
The classic CSS masonry trick is multi-column in disguise: a container with column-count, children with break-inside: avoid, and images or cards of natural height flowing top-to-bottom then across. Because the flow order is linear, screen readers read the gallery in a sensible sequence, and no JavaScript measures anything:
.gallery {
column-width: 14rem;
column-gap: 1rem;
padding: 1rem;
}
.gallery figure {
break-inside: avoid;
margin-block-end: 1rem;
border-radius: 12px;
overflow: hidden;
background: #ffffff;
border: 1px solid #e2e8f0;
}
.gallery img {
display: block;
width: 100%;
height: auto;
}
.gallery figcaption {
padding: 0.6rem 0.75rem;
font-size: 0.85rem;
color: #475569;
}
The limitation is ordering: items fill column one completely before starting column two, so a strictly left-to-right reading order is impossible â item four sits below item one, not to its right. If your design requires row-major order, CSS Grid with grid-auto-flow: dense or a small JavaScript masonry script is the honest alternative. For photo walls and card feeds where vertical order is acceptable, the pure-CSS version is hard to beat.
Multi-column versus flex and grid, in one look
The three layout systems overlap in appearance but not in mechanics, and the decision is usually obvious once you state what your content is:
| Question you are asking | Right system | Why |
|---|---|---|
| How do I split one long stream across columns? | Multi-column | The browser fragments a single ordered flow |
| How do I lay out discrete items with equal control? | Grid | Each item gets a cell and explicit placement |
| How do I align a few items along one axis? | Flexbox | Simple distribution without track math |
| How do I keep a strict left-to-right reading order? | Grid or flex | Multicol fills columns top-to-bottom first |
| How do I make a masonry gallery without JavaScript? | Multi-column | break-inside: avoid keeps items whole |
Use this table as a tie-breaker, not a rulebook: hybrid layouts are normal. A magazine spread often uses Grid for the page shell and multi-column for the body text inside the main cell â the systems compose because they operate at different levels of the same layout.
When multi-column is the wrong tool
Three situations rule columns out immediately. First, per-item layout â if each child needs its own placement, spans, or alignment, that is Grid's job. Second, horizontal item order that must read left-to-right, as just described. Third, interactive components where a break lands between a trigger and its dependent UI; a dropdown separated from its button by a column break is a bug you will hunt for an hour. Multi-column also interacts awkwardly with some positioned and transformed descendants, since the fragmentation engine treats columns like pages. When in doubt, prototype quickly: if the content flows naturally as a single stream, columns are likely right; if you find yourself fighting the flow, switch to Grid.
Common Mistakes
An image or card is sliced in half at a column boundary
Fix: Apply break-inside: avoid to the item so the fragmentation engine moves the whole box to the next column
column-span: all on every subheading breaks the layout into unusable slivers
Fix: Reserve column-span for a few deliberate interruptions such as the article title and one pull quote; let normal headings flow inside columns
Multi-column gallery reads in the wrong order for keyboard and screen-reader users
Fix: Remember the flow is top-to-bottom then across; if row-major order matters, use Grid with grid-auto-flow instead
Columns overflow or collapse to one on narrow screens
Fix: Prefer column-width over column-count so the count adapts naturally, and verify the sum of minimum widths fits your smallest breakpoint
Best Practices
- Let column-width drive responsive articles so no media queries are required
- Set orphans and widows on body text for print-quality break control
- Use column-rule plus column-gap for divider lines that never consume layout space
- Keep interactive widgets out of fragmented column flows
- Pair break-inside: avoid with figure elements in galleries so captions never separate from images
Interview Questions
Q1: How do column-count and column-width interact when both are specified?
The browser satisfies both: it creates no more than column-count columns, and each is at least column-width wide. If the container cannot fit column-count columns at the minimum width, the count effectively shrinks â whichever constraint binds first wins.
Q2: What does column-span: all do to the flow?
The spanning element is taken out of the column fragmentation at its position and rendered across the full width of the multicol container. Content before it occupies the columns above; content after it begins below, which is why heavy use of column-span fragments the layout badly.
Q3: Why is multi-column a reasonable masonry implementation?
Because multicol is a linear flow, items fill one column top-to-bottom before moving to the next, and break-inside: avoid keeps each card intact. Screen readers get a sensible single-stream order and no JavaScript measurements are needed â the cost is that visual order is column-major rather than row-major.
Key Takeaways
- Multi-column fragments a single content stream across columns like print typesetting, unlike Flexbox or Grid which place discrete items
- column-count fixes the count, column-width sets a minimum column size, and the columns shorthand combines them
- break-inside: avoid protects cards from splits; column-span: all lifts hero elements across every column
- column-gap spaces columns and column-rule draws a decorative divider without taking space
- Masonry-style galleries come free with break-inside: avoid, but item order is column-major, not row-major