CSS Columns
In this page:
column-count
column-count splits a container's content into a specific number of columns, letting the browser handle wrapping the flow automatically from one column into the next. This is the CSS multi-column layout module, distinct from flexbox or grid, and is best suited for long flowing text like articles.
Note: Three columns is a comfortable default for body text on a typical desktop-width container, adjust from there based on your content.
Warning: On a narrow screen, a high column-count can squeeze columns down to an uncomfortably narrow, hard-to-read width.
Example: column-count
<style>
.text {
column-count: 3;
background: #f5f5f5;
padding: 12px;
}
</style>
<div class="text">Long flowing text automatically wraps from one column into the next.</div>
column-width
column-width sets a target width per column instead of a fixed count, letting the browser fit as many columns of roughly that width as the container allows. Because the column count adapts to the container's size, this property is naturally responsive without any media queries.
Note: column-width is naturally responsive, since the number of columns adjusts automatically as the container gets wider or narrower.
Warning: column-width is a minimum target, not an exact value, so actual rendered column widths can vary slightly to fill the available space evenly.
Example: column-width
<style>
.text {
column-width: 200px;
background: #f5f5f5;
padding: 12px;
}
</style>
<div class="text">Fits as many 200px columns as the container allows, no media queries needed.</div>
column-gap
column-gap sets the space between adjacent columns, controlling how much breathing room separates one column of text from the next. Without enough gap, text in adjacent columns can visually run together and become harder to read.
Note: A column-gap between 24px and 40px is a comfortable range that keeps columns feeling distinct without wasting too much horizontal space.
Warning: A very small column-gap can make columns feel like a single confusing block, especially without a visible rule line to separate them.
Example: column-gap
<style>
.text {
column-count: 2;
column-gap: 40px;
background: #f5f5f5;
padding: 12px;
}
</style>
<div class="text">Generous space between the two columns</div>
column-rule
column-rule draws a dividing line between columns, using the same style, width, and color syntax as the border shorthand, purely as a visual separator. This rule sits inside the gap between columns and never affects the column width itself, only the visual divider.
Note: A thin, light-colored column-rule is usually enough, it just needs to be visible, not bold.
Warning: column-rule only draws a line, it does not add any spacing on its own, pair it with column-gap for a well-balanced look.
Example: column-rule
<style>
.text {
column-count: 2;
column-rule: 1px solid #ccc;
background: #f5f5f5;
padding: 12px;
}
</style>
<div class="text">A thin dividing line between columns</div>
Preventing Awkward Breaks
break-inside: avoid keeps a specific element, like a heading or a card, from being awkwardly split across two columns. column-span: all lets an element, like a title, stretch across every column instead of sitting inside just one.
Note: Apply break-inside: avoid to any self-contained block, like an image caption or a small card, that would look broken if split mid-way.
Warning: column-span: all removes an element from the normal column flow entirely, so use it deliberately for section titles, not for regular flowing content.
Example: Preventing Awkward Breaks
<style>
.text {
column-count: 2;
background: #f5f5f5;
padding: 12px;
}
h2 {
column-span: all;
}
.card {
break-inside: avoid;
background: white;
border: 1px solid #ccc;
padding: 8px;
margin-bottom: 8px;
}
</style>
<div class="text">
<h2>Spans all columns</h2>
<div class="card">Never split mid-way</div>
</div>
- Using columns for layout regions that need independent, unrelated content (like a sidebar), rather than for flowing a single block of text.
- Forgetting that column-count is a target, not a guarantee, since narrow viewports may render fewer columns than requested.
- Letting headings or images split awkwardly across a column break without setting break-inside: avoid.
- column-count and column-width both create a multi-column flow, automatically wrapping content from column to column.
- column-gap and column-rule control the spacing and dividing line between columns.
- break-inside: avoid and column-span: all prevent awkward mid-element column breaks and let an element span every column.
CSS Multi-column Layout properties are supported by all modern browsers.
Chapter Quiz — Complete all 22 topics to unlock
0/22 topics done
Complete these topics first:
- CSS Gradients
- CSS Shadows
- CSS Filters
- CSS Blend Modes
- CSS Transforms
- CSS 2D Transforms
- CSS 3D Transforms
- CSS Transitions
- CSS Animations
- CSS Image Styling
- CSS Image Effects
- CSS Hover Overlays
- CSS Image Modal
- CSS Image Centering
- CSS Image Shapes
- CSS Buttons
- CSS Columns
- CSS Clip Path
- CSS Shapes
- CSS Scroll Snap
- CSS Architecture: BEM
- CSS Custom Properties