99

Concurrent visitors over the last 30 minutes. (~)

Peak concurrent visitors -
Yesterday: 0 / Today: 0

The Complete Guide to CSS Multi-Column

The Complete Guide to CSS Multi-Column

CSS multi-column is a layout feature that splits an element's content (such as text) into several columns, like a newspaper or magazine, so you can see more content at a glance and read it more easily.
In the simplest case, you only set the number of columns, but you can also set a variety of styles such as the minimum column width, the gap between columns, divider lines, and other optimizations; in particular, setting a minimum width makes it easy to provide a responsive layout.

You can split the content of a single block element into multiple columns.
It doesn't apply to inline elements.

# Multi-column containers

The basic multi-column properties are used on a single container (a block element).
In the examples that follow, the <article> element is the multi-column container.

Multi-column properties used on the container

# columns

columns is a shorthand property that sets the minimum width (column-width) and the maximum number (column-count) of columns at once.
The default value is auto, which lets the browser decide the width and number of columns; if you don't set a width or number, multi-column layout isn't applied.

Value Meaning Default
auto The browser decides the width and number of columns auto
Value of the column-width property Sets the minimum width of the columns auto
Value of the column-count property Sets the maximum number of columns auto
1
columns: min-width max-count;

Here's an example without multi-column layout applied.

HTML
1
2
3
4
5
6
7
<article> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin rutrum metus lacus, at euismod diam tempus ut. Nulla rutrum neque ut est varius, at semper magna dictum. Curabitur quam sem, auctor et nisl pellentesque, vulputate blandit nunc. Maecenas pharetra tortor vel ante pellentesque mattis. Integer consectetur metus rutrum mattis consectetur. Aenean sit amet mauris enim. Quisque varius eu eros ac dapibus. Nulla finibus dictum tortor a convallis. Integer mi dolor, finibus at mi a, luctus volutpat risus. Suspendisse elit urna, malesuada ut leo eget, tincidunt tristique enim. Vestibulum aliquam aliquam dignissim. Maecenas non placerat purus, vel cursus elit. Etiam molestie pharetra vulputate. Nam vehicula urna velit, sit amet fermentum enim elementum in. Vivamus tempor ultrices odio nec ultricies. Suspendisse ullamcorper blandit ante, quis condimentum libero eleifend nec. Sed a lacinia magna. Nulla et tortor ipsum. Pellentesque mollis libero ac turpis faucibus, vel consequat purus pulvinar. Vestibulum vestibulum elit id luctus auctor. Vestibulum commodo ac eros et maximus. Sed porttitor pellentesque lectus, eu maximus erat faucibus et. Duis iaculis erat ac maximus tincidunt. Cras ornare risus libero, in efficitur ex tincidunt sit amet. Donec lacus urna, ultricies a maximus ac, rhoncus sit amet justo. Suspendisse potenti. Nam at varius leo. Nam ultricies nunc felis, non elementum ligula convallis non. Nullam nunc dolor, mollis quis dictum ac, finibus vel libero. Cras pulvinar eros sit amet orci aliquet, quis consectetur justo ornare. Nulla dignissim ac sem ac bibendum. </p> </article>
CSS
1
2
3
4
5
6
7
8
9
10
article { width: 700px; height: 450px; padding: 20px; border: 1px solid; border-radius: 4px; } p { margin: 0; }

Multi-column layout not applied.

Use the columns property on the container element where you want to apply multi-column layout, as follows.
Each column has a minimum width of 200px, and there are at most 3 columns.

CSS
1
2
3
4
5
6
article { /* ... */ columns: 200px 3; /* column-width: 200px; */ /* column-count: 3; */ }

Multi-column layout applied.

If the container's width shrinks, the number of columns adjusts to fit the minimum width of each column.
Note that the element's height must be large enough for the number of columns to adjust, so in this part only, we set the height property to its default value (auto).
The default value of the height property, which sets the element's height, is auto, and the height can change to fit the size of the content.

From the next heading on, bring the height property back before testing!

CSS
1
2
3
4
5
6
7
article { width: 700px; /* height: 450px; */ padding: 20px; border: 1px solid; border-radius: 4px; }

When the container is 500px wide.

When the container is 300px wide.

# column-width

An individual property of columns that sets the minimum width each column can shrink to.
If a column would become narrower than the minimum width within the element's width, the number of columns changes automatically.

Value Meaning Default
auto Set automatically by the browser auto
Units Set in units such as px, em, and cm
CSS
1
2
3
4
article { /* ... */ column-width: 200px; }

# column-count

An individual property of columns that sets the maximum number of columns to divide the element's content into.
The optimal number of columns changes automatically based on the specified minimum column width (column-width).

Value Meaning Default
auto Set automatically by the browser auto
Number Sets the maximum number of columns
CSS
1
2
3
4
article { /* ... */ column-count: 3; }

# column-gap (gap)

Sets the gap between columns in a multi-column layout.
The default gap is proportional to the font size.

gap is a shorthand for the row-gap and column-gap properties.
Multi-column layout doesn't use row-gap, so gap: 30px; and column-gap: 30px; produce the same result.

Value Meaning Default
normal Sets the default gap (1em) normal
Units Set in units such as px, em, and cm
CSS
1
2
3
4
5
6
article { /* ... */ column-gap: 30px; /* gap: 30px; */ /* gap: 0 30px; */ }

With a gap set between columns.

# column-rule

Sets a divider line between columns in a multi-column layout.
The divider sits in the middle of the gap between columns.

It's easy to understand if you compare it to the border-width, border-style, and border-color properties, which set a line's width, style, and color.

Value Meaning Default
column-rule-width Sets the line's width medium
column-rule-style Sets the line's style none
column-rule-color Sets the line's color Same as the element's text color
CSS
1
2
3
4
article { /* ... */ column-rule: 1px solid; }

With a divider set between columns.

# column-rule-width

An individual property of column-rule that sets the width of the multi-column divider.

Value Meaning Default
medium Medium line medium
thin Thin line
thick Thick line
Units Set in units such as px, em, and cm
CSS
1
2
3
4
article { /* ... */ column-rule-width: 1px; }

# column-rule-style

An individual property of column-rule that sets the style of the multi-column divider.

Value Meaning Default
none No line none
hidden Same as no line (used in table elements)
solid Solid line (a regular line)
dotted Dotted line
dashed Dashed line
double Double line
groove Grooved shape (line)
ridge Raised ridge shape (line, the opposite of groove)
inset The whole element looks sunken (line)
outset The whole element looks raised (line)
CSS
1
2
3
4
article { /* ... */ column-rule-style: solid; }

# column-rule-color

An individual property of column-rule that sets the color of the multi-column divider.

Value Meaning Default
Color Sets the line's color Same as the element's text color
CSS
1
2
3
4
article { /* ... */ column-rule-color: red; }

# column-fill

The column-fill property sets whether content is balanced across the columns or filled in sequence.

Value Meaning Default
balance Fills the columns evenly balance
auto Fills the columns in sequence

When the element's height (height) is set, space may be left at the bottom by default, because the content is balanced (balance) across the columns.

Content is balanced across the columns.

If you want to simply fill the columns in sequence instead of balancing the content, you can use the auto value.

CSS
1
2
3
4
article { /* ... */ column-fill: auto; }

Content fills the columns in sequence, starting from the first column on the left.

# Multi-column items

A container with multi-column layout applied can have several elements as its content (children).
All the properties we'll look at from here on are used on the content elements, not on the container.

# column-span

You can make an element span across all columns.
It can be used to display the title of a multi-column area.

Value Meaning Default
none The element doesn't span none
all The element spans all columns

The multi-column area in the following example has an <h2> element for the area's title and <h3> elements for subheadings of parts of the content, and each paragraph is a <p> element.
The title and paragraphs flow through the columns in order.

HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
<article> <h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin rutrum metus lacus, at euismod diam tempus ut.</p> <p>Nulla rutrum neque ut est varius, at semper magna dictum. Curabitur quam sem, auctor et nisl pellentesque, vulputate blandit nunc.</p> <h3>Aenean sit amet.</h3> <p>Maecenas pharetra tortor vel ante pellentesque mattis. Integer consectetur metus rutrum mattis consectetur.</p> <p>Aenean sit amet mauris enim. Quisque varius eu eros ac dapibus. Nulla finibus dictum tortor a convallis. Integer mi dolor, finibus at mi a, luctus volutpat risus. Suspendisse elit urna, malesuada ut leo eget, tincidunt tristique enim. Vestibulum aliquam aliquam dignissim. Maecenas non placerat purus, vel cursus elit.</p> <h3>Vivamus tempor.</h3> <p>Etiam molestie pharetra vulputate. Nam vehicula urna velit, sit amet fermentum enim elementum in. Vivamus tempor ultrices odio nec ultricies. Suspendisse ullamcorper blandit ante, quis condimentum libero eleifend nec. Sed a lacinia magna. Nulla et tortor ipsum.</p> <p>Pellentesque mollis libero ac turpis faucibus, vel consequat purus pulvinar. Vestibulum vestibulum elit id luctus auctor. Vestibulum commodo ac eros et maximus.</p> </article>
CSS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
article { width: 700px; height: 400px; padding: 20px; border: 1px solid; border-radius: 4px; column-width: 200px; column-count: 3; column-gap: 30px; column-rule: 1px solid; column-fill: auto; } h2 { margin: 0; padding-bottom: 10px; } h3 { margin: 0; padding: 10px 0 5px; } p { margin: 0; }

Multi-column structure without a spanning title (none)

If you want to emphasize the area's title even more, you can create a title that spans all columns, as follows.
Use the column-span: all; property on that heading element.

CSS
1
2
3
4
h2 { /* ... */ column-span: all; }

Multi-column structure with a spanning title (all)

# break-before

You can break to the next column at the start (before) of an element.
By default, auto behaves like avoid.

It's easy to understand if you compare the break-before and break-after properties with the pseudo-element selectors ::before and ::after.

Value Meaning Default
auto Set automatically by the browser auto
column Breaks to the next column at the start of the element
avoid Doesn't break at the start of the element

Each subheading breaks to the next column at its start.
The red line marks where the break happens.

CSS
1
2
3
4
5
h3 { /* ... */ border-top: 1px solid red; break-before: column; }

Each subheading breaks to the next column at its start.

# break-after

You can break to the next column at the end (after) of an element.

Value Meaning Default
auto Set automatically by the browser auto
column Breaks to the next column at the end of the element
avoid Doesn't break at the end of the element

The red line marks where it breaks to the next column.

CSS
1
2
3
4
5
h3 { /* ... */ border-bottom: 1px solid red; break-after: column; }

Each subheading breaks to the next column at its end.

# break-inside

You can set whether an element can break to the next column inside it.
By default, breaks inside an element are allowed.

Value Meaning Default
auto Set automatically by the browser auto
avoid The inside of the element doesn't break to the next column

In the following example, red borders are used to show the areas of the subheadings and paragraphs.
The 4th and 5th paragraphs in the example each break across to the next column.

This example doesn't use the break-before and break-after properties.

CSS
1
2
3
4
5
6
7
8
9
10
11
12
/* ... */ h3 { margin: 0; padding: 10px 0 5px; border: 1px solid red; /* border-bottom: 1px solid red; */ /* break-after: column; */ } p { margin: 0; border: 1px solid red; }

Breaks are allowed inside the content.

If you don't want each paragraph to break between columns, you can disallow breaks inside the element, as follows.
Then, if an element can't be displayed without a break, it's displayed in the next column.

CSS
1
2
3
4
5
/* ... */ p { /* ... */ break-inside: avoid; }

Breaks are not allowed inside the content.