CSS column-count Property
The column-count property specifies the desired number of columns into which an element's content should be divided.
It is part of the CSS Multi-column Layout module, which allows text and other content to flow automatically from one column to the next. This is useful for newspaper-style articles, informational content, and layouts that benefit from shorter lines of text.
The browser calculates the column widths and distributes content based on the available space, the specified column count, and related properties such as column-width and column-gap.
column-count Syntax
The column-count property accepts auto or a positive integer specifying the desired number of columns.
selector {
column-count: 3;
}
General Syntax
selector {
column-count: auto | <integer [1,∞]>;
}
Automatic Column Count
.content {
column-count: auto;
}
Two Columns
.content {
column-count: 2;
}
Three Columns
.content {
column-count: 3;
}
Four Columns
.content {
column-count: 4;
}
CSS-Wide Keywords
.content {
column-count: inherit;
}
.content {
column-count: initial;
}
.content {
column-count: unset;
}
.content {
column-count: revert;
}
.content {
column-count: revert-layer;
}
Zero, negative numbers, fractions, percentages, and length values are not valid column-count values.
Property Values
The property has two types of values: the keyword auto and positive integers.
| Value | Description |
|---|---|
auto |
Allows the number of columns to be determined by other layout constraints, particularly column-width. |
1 |
Specifies a single column. |
2 |
Specifies a desired count of two columns. |
3 |
Specifies a desired count of three columns. |
4 |
Specifies a desired count of four columns. |
<integer> |
Any positive integer representing the desired number of columns. |
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Uses the computed value of the parent element. |
initial |
Resets the property to auto. |
unset |
Resets the property to auto because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | No |
| Applies to | Block containers, except table wrapper boxes |
| Computed value | Specified keyword or integer |
| Animation type | Integer |
| Percentages | Not applicable |
| Primary use | Creating multi-column content layouts |
The specified column count is a layout constraint rather than an absolute guarantee that every column will contain content. The actual layout also depends on available space and other multi-column properties.
How It Works
When column-count is applied to a suitable container, the browser establishes a multi-column formatting context and distributes its content into columns.
Step 1: Create a Content Container
<div class="article-content">
<p>First paragraph of article content.</p>
<p>Second paragraph of article content.</p>
<p>Third paragraph of article content.</p>
</div>
Step 2: Specify the Column Count
.article-content {
column-count: 3;
}
Step 3: Calculate Column Widths
The browser divides the available inline space among the columns while accounting for column gaps and any specified column-width.
Step 4: Flow Content into Columns
Content flows sequentially through the columns. In a left-to-right writing direction, columns normally progress from left to right.
Step 5: Balance or Fill Columns
The column-fill property influences how content is distributed among the columns. The default balance value attempts to distribute content evenly in common unconstrained-height layouts.
Result
The content appears in multiple columns without requiring separate HTML containers for each column.
auto Value
The auto value allows the browser to determine the number of columns using other multi-column layout constraints.
.content {
column-count: auto;
}
Default Behavior
auto is the initial value. When column-width is also auto, the element does not request multiple columns.
Combine with column-width
.content {
column-count: auto;
column-width: 220px;
}
The browser determines how many columns of approximately the requested width can fit in the available space.
Responsive Behavior
As the container becomes wider, additional columns may fit. When the container becomes narrower, the browser may reduce the number of columns.
When to Use auto
Use auto with column-width when you prefer to control approximate column width rather than specify a fixed number of columns.
Integer Values
A positive integer specifies the desired number of columns.
One Column
.content {
column-count: 1;
}
This requests a single column and can be useful when disabling a multi-column layout at smaller screen sizes.
Two Columns
.content {
column-count: 2;
}
Three Columns
.content {
column-count: 3;
}
Four Columns
.content {
column-count: 4;
}
Invalid Values
.content {
column-count: 0;
}
.content {
column-count: -2;
}
.content {
column-count: 2.5;
}
.content {
column-count: 50%;
}
These declarations are invalid and are ignored by the browser.
Important Limitation
A positive integer does not guarantee a particular column width. When the container is narrow, columns may become too small for comfortable reading unless the layout is adjusted responsively.
column-width Interaction
The column-count and column-width properties work together to determine the number and size of columns.
Column Count Only
.content {
column-count: 3;
}
The browser creates up to three columns and calculates their widths from the available space.
Column Width Only
.content {
column-width: 220px;
}
The browser determines the number of columns that can fit while using the specified width as a target.
Both Properties
.content {
column-count: 3;
column-width: 220px;
}
The browser uses the count as a maximum and the width as a preferred minimum when determining how many columns fit. It may create fewer than three columns if the available width is insufficient.
columns Shorthand
.content {
columns: 220px 3;
}
The columns shorthand sets column-width and column-count in one declaration.
Choosing an Approach
Use column-count when the number of columns matters most. Use column-width when maintaining a comfortable reading width is more important.
Column Spacing
The column-gap property controls the spacing between adjacent columns.
Default Column Gap
.content {
column-count: 3;
column-gap: normal;
}
For multi-column layout, the normal gap is generally equivalent to 1em.
Custom Column Gap
.content {
column-count: 3;
column-gap: 30px;
}
Relative Spacing
.content {
column-count: 3;
column-gap: 2rem;
}
Column Rules
The column-rule property adds a decorative line between columns without changing the column gap calculation.
.content {
column-count: 3;
column-gap: 30px;
column-rule: 1px solid #cccccc;
}
Readable Spacing
Choose a gap large enough to distinguish adjacent columns. Narrow gaps can make it difficult to identify where one column ends and the next begins.
Column Balancing
Column balancing determines how content is distributed vertically across the columns.
Balanced Columns
.content {
column-count: 3;
column-fill: balance;
}
The browser attempts to distribute content so the columns have approximately equal heights.
Sequential Filling
.content {
column-count: 3;
column-fill: auto;
height: 250px;
}
With a constrained height, column-fill: auto fills columns sequentially rather than balancing their content.
Default Behavior
The initial value of column-fill is balance.
Content Length
If there is not enough content to fill every requested column, some columns may contain little or no content.
Layout Constraints
Column balancing can be affected by fixed heights, fragmentation rules, content that cannot be split, and spanning elements.
When to Adjust Balancing
Use column-fill when you need greater control over how content is distributed vertically. For most ordinary multi-column text layouts, the default balancing behavior is appropriate.
Content Flow
Multi-column layout changes the visual arrangement of content without changing its order in the HTML document.
Sequential Reading Order
Content flows through the first column before continuing into the next, according to the writing direction.
Paragraphs and Headings
Paragraphs, headings, lists, and other content can flow through columns. Some elements may be fragmented across column boundaries.
Avoid Breaking an Element
.content .important-box {
break-inside: avoid;
}
The break-inside property can request that an element remain together within a column when possible.
Span All Columns
.content h2 {
column-span: all;
}
The column-span: all declaration allows a suitable element to span across all columns.
Right-to-Left Content
For right-to-left writing directions, columns normally progress from right to left.
Screen Readers
Because the underlying HTML order remains unchanged, assistive technologies generally follow the document's logical content sequence.
Layout Limitations
Multi-column layout is designed for flowing content, not for independently positioned columns. Use CSS Grid or Flexbox when each column needs separate layout control.
Responsive Layouts
A fixed column count may produce narrow columns on smaller screens. Responsive styles can adjust the count to maintain readability.
Desktop Layout
.article-content {
column-count: 3;
column-gap: 30px;
}
Tablet Layout
@media (max-width: 900px) {
.article-content {
column-count: 2;
}
}
Mobile Layout
@media (max-width: 600px) {
.article-content {
column-count: 1;
}
}
Complete Responsive Example
.article-content {
column-count: 3;
column-gap: 30px;
}
@media (max-width: 900px) {
.article-content {
column-count: 2;
}
}
@media (max-width: 600px) {
.article-content {
column-count: 1;
}
}
Automatic Responsive Columns
.article-content {
column-width: 240px;
column-gap: 30px;
}
Using column-width without a fixed count allows the browser to adjust the number of columns based on available space.
Container Queries
Container queries can adjust the column count based on the available width of a component rather than the viewport.
.article-wrapper {
container-type: inline-size;
}
.article-content {
column-count: 1;
}
@container (min-width: 600px) {
.article-content {
column-count: 2;
}
}
For reusable components, container queries can provide more appropriate behavior than viewport-based media queries.
column-count Example
The following example demonstrates how the same content can be displayed in one, two, or three columns using column-count.
<div class="column-count-demo">
<div class="column-example one-column">
<h3>One Column</h3>
<p>HTML provides the structure of a web page.</p>
<p>CSS controls its visual presentation.</p>
<p>JavaScript adds interactive behavior.</p>
</div>
<div class="column-example two-columns">
<h3>Two Columns</h3>
<p>HTML provides the structure of a web page.</p>
<p>CSS controls its visual presentation.</p>
<p>JavaScript adds interactive behavior.</p>
</div>
<div class="column-example three-columns">
<h3>Three Columns</h3>
<p>HTML provides the structure of a web page.</p>
<p>CSS controls its visual presentation.</p>
<p>JavaScript adds interactive behavior.</p>
</div>
</div>
.column-count-demo {
display: grid;
gap: 20px;
}
.column-count-demo .column-example {
padding: 15px;
border: 1px solid #cccccc;
background-color: #f8f9fa;
}
.column-count-demo h3 {
margin: 0 0 12px;
font-size: 1.125rem;
}
.column-count-demo p {
margin: 0 0 10px;
}
.column-count-demo .one-column {
column-count: 1;
}
.column-count-demo .two-columns {
column-count: 2;
column-gap: 20px;
}
.column-count-demo .three-columns {
column-count: 3;
column-gap: 20px;
}
.column-count-demo h3 {
column-span: all;
}
@media (max-width: 600px) {
.column-count-demo .three-columns {
column-count: 1;
}
}
One Column
HTML provides the structure of a web page.
CSS controls its visual presentation.
JavaScript adds interactive behavior.
Two Columns
HTML provides the structure of a web page.
CSS controls its visual presentation.
JavaScript adds interactive behavior.
Three Columns
HTML provides the structure of a web page.
CSS controls its visual presentation.
JavaScript adds interactive behavior.
The first example uses a single column. The second divides content into two columns, and the third requests three columns.
The column-span: all declaration keeps each heading across the full width of its example, while the paragraphs flow through the columns below it.
On smaller screens, the media query changes the three-column example to a single column to maintain readability.
Accessibility
Multi-column layouts can improve readability when used carefully, but narrow columns and excessive fragmentation can make content difficult to follow.
Maintain Readable Column Widths
Avoid creating so many columns that text wraps into very short lines.
Use Responsive Layouts
Reduce the number of columns on smaller screens to prevent cramped text and unnecessary horizontal scrolling.
Preserve Logical Content Order
Keep HTML content in its intended reading order. CSS columns change the visual layout without changing the document structure.
Avoid Excessive Fragmentation
Use break-inside: avoid where appropriate to keep related content together, while recognizing that browsers may still need to fragment oversized content.
Consider Reading Direction
Column progression follows the writing direction. Test layouts with right-to-left languages when applicable.
Test Zoom and Reflow
Verify that content remains usable at increased text sizes and browser zoom levels.
Choose the Right Layout System
Use multi-column layout for flowing content. Use CSS Grid or Flexbox when content needs independent positioning or a more predictable visual arrangement.
Important Considerations
Keep the following points in mind when using column-count:
- Purpose: Specifies the desired number of columns in a multi-column layout.
- Initial value:
auto. - Inheritance: The property is not inherited.
- Valid values:
autoor a positive integer. - Invalid values: Zero, negative numbers, fractions, percentages, and lengths.
- Column count: The requested number of columns is subject to layout constraints.
- Column width: The browser calculates widths based on available space and related properties.
- column-width: Can limit the number of columns that fit.
- column-gap: Controls spacing between columns.
- column-rule: Adds decorative separators between columns.
- column-fill: Controls balancing or sequential filling.
- column-span: Allows suitable elements to span across all columns.
- Content flow: Content flows sequentially through columns.
- Fragmentation: Elements may be split between columns unless fragmentation rules prevent it.
- Responsive design: Reduce column counts or use
column-widthon narrow screens. - Reading order: CSS columns do not change the underlying HTML order.
- Layout choice: Multi-column layout is intended for flowing content, not independent grid tracks.
- Animation: Integer values can animate by discrete integer steps.
- Accessibility: Maintain readable line lengths and test zoom and reflow behavior.
For the best results, combine column-count with appropriate column spacing and responsive rules. When consistent column widths are more important than a fixed count, consider using column-width instead.
Browser Support
The column-count property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.
Multi-column layouts are a well-established CSS feature. Basic column counting works across current major browsers, although detailed fragmentation and balancing behavior can vary in complex layouts.
Widely Supported Example
.content {
column-count: 3;
}
Responsive Example
.content {
column-count: 3;
}
@media (max-width: 600px) {
.content {
column-count: 1;
}
}
Compatibility Considerations
Test layouts containing complex nested elements, fixed heights, spanning elements, and fragmentation rules across your target browsers.
For current compatibility information, visit Can I Use? and search for column-count.
Specifications
The column-count property is defined in the CSS Multi-column Layout specification.
CSS Multi-column Layout Module Level 1
The specification defines how column counts interact with column widths, available space, and other multi-column layout properties.
