Multi-column layout
Definition and purpose
Multi-column layout fragments a continuous flow into columns, unlike Grid which places independent items in tracks. column-count requests the number of columns; column-width suggests an ideal column width, and the actual number and width depend on available space. column-gap separates columns, and column-rule paints a divider without consuming additional track width.
Balanced columns
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { width: 300px; column-gap: 20px; column-count: 2; } #a > div { height: 40px; break-inside: avoid; background: #dbeafe; } #a { column-fill: balance; } </style> </head> <body> <article id="a"> <div id="x">First</div> <div id="y">Second</div> <div id="z">Third</div> <div id="w">Fourth</div> </article> </body></html>Four equal blocks balance into two columns of two blocks each.
Syntax and mental model
For two columns in 300px with a 20px gap, each column is 140px wide. column-fill: balance attempts to distribute content across columns, respecting break constraints. column-fill: auto fills sequentially when the block size is constrained. A column-span: all element can interrupt the columns with a spanning heading. Keep reading order in the DOM; very tall columns can be hard to read on screen.
Sequential constrained columns
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { width: 300px; column-gap: 20px; column-count: 2; } #a > div { height: 40px; break-inside: avoid; background: #dbeafe; } #a { height: 120px; column-fill: auto; } </style> </head> <body> <article id="a"> <div id="x">First</div> <div id="y">Second</div> <div id="z">Third</div> <div id="w">Fourth</div> </article> </body></html>Three blocks fill the first 120px column; the fourth begins the next.
Common mistakes
Do not expect columns to reorder content row by row like a grid. Avoid fixed multi-column counts for narrow viewports when they make lines too short; use suitable column-width or media queries for readable prose.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Table layout algorithms. Next lesson: Fragmentation and breaks.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Multi-column layout — knowledge check
Five questions on multi-column layout.
How does multicol distribute content?
What width is each of two columns in 320px with a 24px gap?
What does column-rule consume beyond the gap?
Which value attempts to equalize column heights?
Which value can make a heading span columns?