CSS Columns
In this page:
selector {
column-count: number;
column-gap: length;
column-rule: width style color;
}
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.
- Three columns is a comfortable default for body text on a typical desktop-width container, adjust from there based on your content.
- Accepted values:
- column-count — number of columns, or auto
- column-width — ideal width such as 200px
- column-gap — length, or normal
- column-rule — line between columns, like 1px solid #ccc
- column-span — none | all
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.
- column-width is naturally responsive, since the number of columns adjusts automatically as the container gets wider or narrower.
- Accepted values:
- column-width: auto — default, no minimum width
- column-width: <length> — the ideal minimum column width
- columns: 200px 3 — shorthand for width and count
- column-count — the two combine, count acts as a maximum
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
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.
- A column-gap between 24px and 40px is a comfortable range that keeps columns feeling distinct without wasting too much horizontal space.
- Accepted values:
- column-gap: normal — default, 1em in multi-column
- column-gap: <length> — fixed gap
- column-gap: <percentage> — relative to the container
- gap — sets row-gap and column-gap; also applies to multi-column
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
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.
- A thin, light-colored column-rule is usually enough, it just needs to be visible, not bold.
- Accepted values:
- column-rule: <width> <style> <color> — shorthand
- column-rule-width: thin | medium | thick | <length> — line thickness
- column-rule-style: solid | dashed | dotted | none — line style
- column-rule-color: <color> — line color
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
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.
- 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.
- Accepted values:
- break-inside: avoid — keep an item within one column
- break-before: column — force a new column before
- break-after: column — force a new column after
- column-span: all — spans across all columns
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