CSS Multi-column Layout Module Level 1

W3C Candidate Recommendation Snapshot,

More details about this document
This version:
https://www.w3.org/TR/2024/CR-css-multicol-1-20240506/
Latest published version:
https://www.w3.org/TR/css-multicol-1/
Editor's Draft:
https://drafts.csswg.org/css-multicol/
Previous Versions:
History:
https://www.w3.org/standards/history/css-multicol-1/
Implementation Report:
https://test.csswg.org/harness/results/css-multicol-1_dev/grouped/
Feedback:
CSSWG Issues Repository
Disposition of Comments
Editors:
Florian Rivoal (On behalf of Bloomberg)
(Google)
Former Editor:
(Opera Software)
Suggest an Edit for this Spec:
GitHub Editor
Test Suite:
https://wpt.fyi/results/css/css-multicol/

Abstract

This specification describes multi-column layouts in CSS, a style sheet language for the web. Using functionality described in the specification, content can be flowed into multiple columns with a gap and a rule between them.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

Status of this document

This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

This document was published by the CSS Working Group as a Candidate Recommendation Snapshot using the Recommendation track. Publication as a Candidate Recommendation does not imply endorsement by W3C and its Members. A Candidate Recommendation Snapshot has received wide review, is intended to gather implementation experience, and has commitments from Working Group members to royalty-free licensing for implementations. This document is intended to become a W3C Recommendation; it will remain a Candidate Recommendation at least until to gather additional feedback.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-multicol” in the title, like this: “[css-multicol] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list [email protected].

This document is governed by the 03 November 2023 W3C Process Document.

This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

1. Introduction

(This section is not normative.)

This module describes multi-column layout in CSS. By using functionality described in this document, style sheets can declare that the content of an element is to be laid out in multiple columns.

Other layout methods in CSS, when applied to a parent element, change the display properties of the direct children. For example if a three column grid layout is created, the direct children of the grid container become grid items and are placed into the column tracks, one element per cell with additional rows created as needed.

The child elements of a multi-column container however continue in normal flow, that flow is arranged into a number of columns. These columns have a flexible inline size, and therefore respond to available space by changing the size or number of columns displayed.

Multi-column layouts are easy to describe in CSS. Here is a simple example:

body { column-width: 12em }

In this example, the body element is set to have columns at least 12em wide. The exact number of columns will depend on the available space.

The number of columns can also be set explicitly in the style sheet:

body { column-count: 2 }

In this case, the number of columns is fixed and the column widths will vary depending on the available width.

The shorthand columns property can be used to set either, or both, properties in one declaration.

In these examples, the number of columns, the width of columns, and both the number and width are set, respectively:
body { columns: 2 }
body { columns: 12em }
body { columns: 2 12em }

Another group of properties introduced in this module describe gaps and rules between columns.

body {
  column-gap: 1em;
  column-rule: thin solid black;
}

The first declaration in the example above sets the gap between two adjacent columns to be 1em. Column gaps are similar to padding areas. In the middle of the gap there will be a rule which is described by the column-rule property.

The values of the column-rule property are similar to those of the CSS border properties. Like border, column-rule is a shorthand property.

In this example, the shorthand column-rule declaration from the above example has been expanded:
body {
  column-gap: 1em;
  column-rule-width: thin;
  column-rule-style: solid;
  column-rule-color: black;
}

The column-fill and column-span properties give style sheets a wider range of visual expressions in multi-column layouts.

In this example, columns are set to be balanced, i.e., to have approximately the same length. Also, h2 elements are set to span across all columns.
div { column-fill: balance }
h2 { column-span: all }
Tests

This specification introduces ten new properties, all of which are used in the examples above.

If all column properties have their initial value, the layout of an element will be identical to a multi-column layout with only one column.

Column gaps (diagonal hatching) and column rules are shown in this sample rendition of a multi-column container with padding (cross hatching). The hatched areas are present for illustrational purposes only. In actual implementations these areas will be determined by the background, the second image shows a rendering of a multi-column container with column-rules.
a diagram showing the various parts of multi-column layout key to the conventions used to display invisible parts of diagram
A multi-column layout with the non-visible column-span and padding inside the multicol container highlighted.
a diagram showing the various parts of multi-column layout
The same layout as in the first image, as it would be displayed by an implementation.

1.1. Value Definitions

This specification follows the CSS property definition conventions from [CSS21] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types.

In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.

2. The Multi-Column Model

An element whose column-width or column-count property is not auto establishes a multi-column container (or multicol container for short), and therefore acts as a container for multi-column layout.

Tests

Basic multicol tests.


Tests demonstrating that auto values do not create a multicol container.


Multicol properties do not inherit.


Multicol with scrolled columns.


Multicol with zero height.


In the traditional CSS box model, the content of an element is flowed into the content box of the corresponding element. Multi-column layout introduces a fragmentation context formed of anonymous fragmentation containers called column boxes (or columns for short). These column boxes establish an independent block formatting context into which the multi-column container’s content flows, and form the containing block for its non-positioned children.

In this example, the width of the image is set with these rules:
img {
  display: block;
  width: 100%;
}

Given that the column box creates a new block formatting context, the width is calculated relative to the column box. Therefore the image will not overflow the column box:

an image contained inside a column box
The image is constrained by the column box that it is displayed in.
Given that the column box creates a new block formatting context, a top margin set on the first child element of a multicol container will not collapse with the margins of the multicol container.
The first paragraph has a 'margin-top' of ''1em'', which appears before the text.
The margin above the first paragraph has not collapsed, leaving a 1em margin above the first line in the multicol container.
Tests

Floats that appear inside multi-column layouts are positioned with regard to the column box where the float appears.

In this example, this CSS fragment describes the presentation of the image:
img {
  display: block;
  float: right;
}

In the HTML, the image appears after the sentence ending, "the leg of a chicken".

an image floated and contained inside a column box
The image is floated inside the column box it appears in.

Content overflowing a column box in the block axis fragments and continues in the next column box.

Note: Column boxes, which are anonymous boxes, do not become the containing block for absolutely positioned boxes. The position property, which establishes a containing block for such boxes, applies to the multicol container, it being the principal box.

Tests
In this example, the multi-column container has position: relative thus becoming the containing block. The image is a direct child of the multi-column container and has position: absolute. It takes positioning from the multi-column container and not from the column box.
.container {
  position: relative;
  column-count: 3;
}
img {
  position: absolute;
  top: 20px;
  left: 40px;
}
The absolutely positioned image is positioned by reference to the [=multi-column container=] not the [=column box=].
The figure demonstrates that the absolutely positioned image is positioned by reference to the multicol container and not the column box.

Out-of-flow descendants of a multi-column container do affect column balancing, and the block-size of the multi-column container.

Tests

The column boxes are ordered in the inline base direction of the multicol container and arranged into multicol lines. The column width is the length of the column box in the inline direction. The column height is the length of the column box in the block direction. All column boxes in a line have the same column width, and all column boxes in a line have the same column height.

Tests

The following tests relate to baseline alignment of the content of columns, though this is not defined in this specification.


The following tests check the behavior of list items that are also muticol containers.


Testing grid items inside multicol


The following tests check the behavior of table elements.


The following tests check that paint order is correct.


The following tests relate to animation or transformation of multicol properties.


Tests related to implementation bugs, not linked to specific normative text.


Tests related to printing and paged media as related to multicol.


Note: In text set using a vertical writing mode, the block direction runs horizontally. In a vertical writing mode columns are laid out horizontally, and the direction of the flow of blocks may be right to left, or left to right. The column-width property therefore refers to the inline size of the column, and not the physical horizontal width.

The first image shows horizontal text with a LTR inline direction. The second shows vertical text with blocks flowing right to left. The third shows vertical text with blocks flowing left to right.
A diagram showing the different ways columns may be arranged due to writing mode.
From left to right: horizontal-tb, vertical-rl, vertical-lr.
Tests

Tests regarding vertical writing modes.


Within each multicol line in the multi-column container, adjacent column boxes are separated by a column gap, which may contain a column rule. All column gaps in the same multi-column container are equal. All column rules in the same multi-column container are also equal, if they appear; column rules only appear between columns that both have content.

In the simplest case a multicol container will contain only one line of columns, and the height of each column will be equivalent to the used height of the multi-column container’s content box. However, fragmentation or spanners can split the content of the multi-column container into multiple multicol lines.

If the multi-column container is paginated, the height of each column is constrained by the page and the content continues in a new line of column boxes on the next page; a column box never splits across pages.

The same effect occurs when a spanning element divides the multi-column container: the columns before the spanning element are balanced and shortened to fit their content. Content after the spanning element then flows into a new, subsequent line of column boxes.

a diagram showing a spanning element causing the shortened columns above the element with text continuing in new columns below
A demonstration of how the spanning element divides the multicol container.

A multi-column container therefore is a regular block container that establishes a new independent formatting context whose contents consist of a series of multicol lines and multicol spanners. Each multi-column line acts as a block-level box that establishes a multi-column formatting context for its column boxes; and each spanner acts as a block-level box that establishes an independent formatting context with its type depending on its display value as usual.

Nested multi-column containers are allowed, but there may be implementation-specific limits.

Tests

Note: It is not possible to set properties/values on column boxes. For example, the background of a certain column box cannot be set and a column box has no concept of padding, margin or borders. Future specifications may add additional functionality. For example, columns of different widths and different backgrounds may be supported.

Note: Multicol containers with column heights larger than the viewport may pose accessibility issues. See Accessibility Considerations for more details.

3. The Number and Width of Columns

Finding the number and width of columns is fundamental when laying out multi-column content. These properties are used to set the number and width of columns:

A third property, columns, is a shorthand property which sets both column-width and column-count.

Other factors, such as explicit column breaks, content, and height constraints, may influence the actual number and width of columns.

3.1. The Inline Size of Columns: the column-width property

Name: column-width
Value: auto | <length [0,∞]>
Initial: auto
Applies to: block containers except table wrapper boxes
Inherited: no
Percentages: N/A
Computed value: the keyword auto or an absolute length
Canonical order: per grammar
Animation type: by computed value type

This property describes the width of columns in multicol containers.

auto
means that the column width will be determined by other properties (e.g., column-count, if it has a non-auto value).
<length [0,∞]>
describes the optimal column width. The actual column width may be wider (to fill the available space), or narrower (only if the available space is smaller than the specified column width). Negative values are not allowed. Used values will be clamped to a minimum of 1px.
Tests
Tests
For example, consider this style sheet:
div {
  width: 100px;
  column-width: 45px;
  column-gap: 0;
  column-rule: none;
}

There is room for two 45px wide columns inside the 100px wide element. In order to fill the available space the actual column width will be increased to 50px.

Also, consider this style sheet:
div {
  width: 40px;
  column-width: 45px;
  column-gap: 0;
  column-rule: none;
}

The available space is smaller than the specified column width and the actual column width will therefore be decreased.

To ensure that column-width can be used with vertical text, column width means the length of the line boxes inside the columns.

Note: The reason for making column-width somewhat flexible is to achieve scalable designs that can fit many screen sizes. To set an exact column width, the column gap and the width of the multicol container (assuming horizontal text) must also be specified.

3.2. The Number of Columns: the column-count property

Name: column-count
Value: auto | <integer [1,∞]>
Initial: auto
Applies to: block containers except table wrapper boxes
Inherited: no
Percentages: N/A
Computed value: specified value
Canonical order: per grammar
Animation type: by computed value

This property describes the number of columns of a multicol container.

auto
means that the number of columns will be determined by other properties (e.g., column-width, if it has a non-auto value).
<integer [1,∞]>
describes the optimal number of columns into which the content of the element will be flowed. Values must be greater than 0. If both column-width and column-count have non-auto values, the integer value describes the maximum number of columns.
Tests
Example:
body { column-count: 3 }

3.3. The column-width and column-count Shorthand: The columns Property

Name: columns
Value: <'column-width'> || <'column-count'>
Initial: see individual properties
Applies to: see individual properties
Inherited: see individual properties
Percentages: see individual properties
Computed value: see individual properties
Animation type: see individual properties
Canonical order: per grammar

This is a shorthand property for setting column-width and column-count. Omitted values are set to their initial values.

Here are some valid declarations using the columns property:
columns: 12em;      /* column-width: 12em; column-count: auto */
columns: auto 12em; /* column-width: 12em; column-count: auto */
columns: 2;         /* column-width: auto; column-count: 2 */
columns: 2 auto;    /* column-width: auto; column-count: 2 */
columns: auto;      /* column-width: auto; column-count: auto */
columns: auto auto; /* column-width: auto; column-count: auto */
Tests

3.4. The Pseudo-algorithm

The pseudo-algorithm below determines the used values for column-count (N) and column-width (W). There is one other variable in the pseudo-algorithm: U is the used width of the multi-column container.

Note: The used width U of the multi-column container can depend on the element’s contents, in which case it also depends on the computed values of the column-count and column-width properties. This specification does not define how U is calculated. Another module (probably the Basic Box Model [CSS3BOX] or the Box Sizing Module [CSS3-SIZING]) is expected to define this.

Tests

The floor(X) function returns the largest integer Y ≤ X.

(01)  if ((column-width = auto) and (column-count = auto)) then
(02)      exit; /* not a multicol container */
(03)  if column-width = auto then
(04)      N := column-count
(05)  else if column-count = auto then
(06)      N := max(1,
(07)        floor((U + column-gap)/(column-width + column-gap)))
(08)  else
(09)      N := min(column-count, max(1,
(10)        floor((U + column-gap)/(column-width + column-gap))))

And:

(11)  W := max(0, ((U + column-gap)/N - column-gap))

For the purpose of finding the number of auto-repeated columns, the UA must floor the column size to a UA-specified value to avoid division by zero. It is suggested that this floor be 1px or less.

In fragmented contexts such as in paged media, user agents may perform this calculation on a per-fragment basis.

The used value for column-count is calculated without regard for explicit column breaks or constrained column heights, while the actual value takes these into consideration.

Tests
In this example, the actual column-count is higher than the used column-count due to explicit column breaks:
div {
  width: 40em;
  columns: 20em;
  column-gap: 0;
}

p {
  break-after: column;
}
<div>
  <p>one
  <p>two
  <p>three
</div>
Two columns drawn inside the container, one outside
The computed column-count is auto, the used column-count is 2 and the actual column-count is 3.
The actual column-count may be lower than the used column-count. Consider this example:
div {
  width: 80em;
  height: 10em;
  columns: 20em;
  column-gap: 0;
  column-fill: auto;
}
<div>foo</div>

The computed column-count is auto, the used column-count is 4, and the actual column-count is 1.

3.5. Stacking Context

All column boxes in a multi-column container are in the same stacking context and the drawing order of their contents is as specified in CSS 2.1. Column boxes do not establish new stacking contexts.

Tests

4. Column Gaps and Rules

Column gaps and rules are placed between columns in the same multicol container. The length of the column gaps and column rules is equal to the column height. Column gaps take up space. That is, column gaps will push apart content in adjacent columns (within the same multicol container).

Tests

A column rule is drawn in the middle of the column gap with the endpoints at opposing content edges of the multicol container. Column rules do not take up space. That is, the presence or thickness of a column rule will not alter the placement of anything else. If a column rule is wider than its gap, the adjacent column boxes will overlap the rule, and the rule may possibly extend outside the box of the multicol container. Column rules are painted just above the border of the multicol container. For scrollable multicol containers, note that while the border and background of the multicol container obviously aren’t scrolled, the rules need to scroll along with the columns. Column rules are only drawn between two columns that both have content.

Tests

Basic column rule tests


If a column rule is wider than its gap, adjacent boxes overlap.


Column rules are only drawn between two columns that have content.


Tests for behavior of backgrounds and column rules.


4.1. Gutters Between Columns: the column-gap property

The column-gap property is defined in [CSS3-ALIGN].

In a multi-column formatting context the used value of normal for the column-gap property is 1em. This ensures columns are readable when the initial values are used. If there is a column rule between columns, it will appear in the middle of the gap.

Tests

Tests that the gap is animatable.


4.2. The Color of Column Rules: the column-rule-color property

Name: column-rule-color
Value: <color>
Initial: currentcolor
Applies to: multicol containers
Inherited: no
Percentages: N/A
Computed value: computed color
Canonical order: per grammar
Animation type: by computed value type
<color>
Specifies the color of the column rule.
Tests

4.3. The Style Of Column Rules: the column-rule-style property

Name: column-rule-style
Value: <line-style>
Initial: none
Applies to: multicol containers
Inherited: no
Percentages: N/A
Computed value: specified keyword
Canonical order: per grammar
Animation type: discrete

The column-rule-style property sets the style of the rule between columns of an element. The <line-style> values are interpreted as in the collapsing border model.

Tests

The none value forces the computed value of column-rule-width to be 0.

4.4. The Width Of Column Rules: the column-rule-width property

Name: column-rule-width
Value: <line-width>
Initial: medium
Applies to: multicol containers
Inherited: no
Percentages: N/A
Computed value: absolute length, snapped as a border width; 0 if the column rule style is none or hidden
Canonical order: per grammar
Animation type: by computed value type

This property sets the width of the rule between columns. Negative values are not allowed.

Tests

4.5. Column Rule Shorthand: the column-rule property

Name: column-rule
Value: <'column-rule-width'> || <'column-rule-style'> || <'column-rule-color'>
Initial: see individual properties
Applies to: see individual properties
Inherited: see individual properties
Percentages: see individual properties
Computed value: see individual properties
Animation type: see individual properties
Canonical order: per grammar

This property is a shorthand for setting column-rule-width, column-rule-style, and column-rule-color at the same place in the style sheet. Omitted values are set to their initial values.

Tests
In this example, the column rule and the column gap have the same width. Therefore, they will occupy exactly the same space.
body {
  column-gap: 35px;
  column-rule-width: 35px;
  column-rule-style: solid;
  column-rule-color: black;
}
The rule completely covers any gap.
The column rule and column gap occupy the same space.
Tests

5. Column Breaks

When content is laid out in multiple columns, the user agent must determine where column breaks are placed. The problem of breaking content into columns is similar to breaking content into pages, which is described in CSS 2.1, section 13.3.3 [CSS21].

Three new properties are introduced to allow column breaks to be described in the same properties as page breaks: break-before, break-after, and break-inside.

5.1. Controlling Fragmentation: the break-before, break-after, break-inside properties

break-before, break-after, and break-inside are defined in [CSS3-BREAK].

Tests

6. Spanning Columns

The column-span property makes it possible for an element to span across several columns.

6.1. Spanning An Element Across Columns: the column-span property

Name: column-span
Value: none | all
Initial: none
Applies to: in-flow block-level elements
Inherited: no
Percentages: N/A
Computed value: specified keyword
Canonical order: per grammar
Animation type: discrete
Tests

This property describes how many columns an element spans across. Values are:

none
The element does not span multiple columns.
Tests
all
The element forces a column break and is taken out of flow to span across all columns of the nearest multicol ancestor in the same block formatting context. Content in the normal flow that appears before the element is automatically balanced across all columns in the immediately preceding multi-column line before the element appears, and any subsequent content flows into a new multi-column line after the element. The element establishes an independent formatting context.

Note: Whether the element establishes a new formatting context does not depend on whether the element is a descendant of a multicol or not. When column-span is all, it always does. This helps with robustness of designs to later revisions that remove the multicol, or when media queries turn the multicol off in some situations.

Tests

An element that spans more than one column is called a multi-column spanning element and the box it creates is called a multi-column spanner.

The containing block of the spanner is the multicol container itself. Consequently, in cases where the spanner itself does not establish a containing block for absolutely positioned boxes inside the spanner, their containing block chain skips directly to the multicol container (skipping any ancestors between the spanner and the multicol container).

Although the spanner is taken out-of-flow, this does not affect the painting order [CSS21] of the spanning element.

In this example, an h2 element has been added to the sample document after the sixth sentence (i.e., after the words "the leg of a"). This styling applies:
h2 { column-span: all; background: silver }

By setting column-span to all, all content that appears before the h2 element is shown above the h2 element.

An element spans all three columns
The h2 element is set to column-span: all

Note that because the spanner splits the multi-column line, it also interrupts any column rules (which are only drawn between columns in a multi-column line).

A spanning element may be lower than the first level of descendants as long as they are part of the same formatting context, and there is nothing between the spanning element and multicol container that establishes a containing block for fixed position descendants.

In this example, the element with column-span: all is inside an element with transform: rotate(90deg). The transform establishes a containing block for fixed position descendents, therefore a spanner will not be created.
<article>
  <section>
    <div class="spanner">Attempted spanner</div>
  </section>
</article>
article {
  columns: 2;
}

section {
  transform: rotate(90deg);
}

.spanner {
  column-span: all;
  background: silver;
}
Tests

If the fragment before the spanner is empty, nothing special happens; the top margin/border/padding is above the spanning element, as an empty fragment.

In this example the multicol container is the article element. Inside this parent is a paragraph and then a section element. The section contains an h2 heading set to all this spans all three columns while the containing section remains inside the column boxes.

The h2 is the first child of the section. This means that the margin, border (shown in red in the diagram) and padding on this section appear before the spanning h2 as an empty fragment.

<article>
  <p>...</p>
  <section>
    <h2>An h2 element</h2>
    <p>...</p>
  </section>
</article>
section {
  border: 2px solid red;
  margin-top: 65px;
  padding-top: 20px;
}

h2 {
  column-span: all;
  background: silver
}
An element spans all three columns, the red border around the section breaks before the spanner.
The h2 element is set to column-span: all, the section has a red border and top padding and margin
Tests

A spanning element takes up more space than the element would take up otherwise. When space is limited, it may be impossible to find room for the spanning element. In these cases, user agents may treat the element as if none had been specified on this property.

In this example, the h2 element appears later in the content, and the height of the multicol container is constrained. Therefore, the h2 element appears in the overflow and there is not room to make the element spanning. As a result, the element appears as if column-span: none was specified.
The h2 element is in an overflow column
The h2 element is in an overflow column and appears as if column-span none is specified
This example is similar to the previous example, except that the H2 element appears naturally in the last column. Still, there is not enough room to make the element spanning.
The h2 element is in the final column
The h2 element is in the final column and appears as if column-span none is specified
Tests
In fragmented contexts spanning elements are honored in all fragments. In this example, we are in paged media, and the first three paragraphs have column breaks after them. A spanning H2 element appears after the fourth paragraph.
Three columns with two lines of text each
This would appear on the first page
A spanning element across the three columns, text above and below.
This would appear on the second page

Spanners are block-level boxes therefore the margins of two adjacent spanners will collapse with each other. The margins of two spanners separated only by an absolutely positioned item will collapse with each other, as absolutely positioned items do not create column boxes. As column boxes establish a new block formatting context, margins on elements inside a column box will not collapse with the margin of a spanner.

Tests
Spanners establish new formatting contexts, but their margins can be changed by their surroundings. In this example, two spanners naturally end up at the top of a page. The top margin of the first spanner is truncated due to adjoining an unforced break. The margins between the two spanners collapse with each other. However, the bottom margin of the second spanner does not collapse with the top margin of the subsequent element.
h2 {
  margin: 16px 0;
  column-span: all;
  background: silver
}
p { margin-top: 16px }
Two spanning elements after a page break
Margins collapse between two spanning elements, but not the bottom margin of a spanner and top margin of next element.
Tests

Additional tests relating to spanners.


7. Filling Columns

There are two strategies for filling columns: columns can either be balanced, or not. If columns are balanced, user agents should try to minimize variations in column height, while honoring forced breaks, widows and orphans, and other properties that may affect column heights. If columns are not balanced, they are filled sequentially; some columns may end up partially filled, or with no content at all.

7.1. Column Balancing: the column-fill property

Name: column-fill
Value: auto | balance | balance-all
Initial: balance
Applies to: multicol containers
Inherited: no
Percentages: N/A
Computed value: specified keyword
Canonical order: per grammar
Animation type: discrete

This property specifies whether content in a multi-column line that does not immediately precede a spanner is balanced across columns or not.

Tests

The values are:

balance
Balance content equally between columns, as far as possible. In fragmented contexts, only the last fragment is balanced.
Tests
balance-all
Balance content equally between columns, as far as possible. In fragmented contexts, all fragments are balanced.
auto
fill columns sequentially
Tests

In continuous contexts, this property does not have any effect when there are overflow columns.

In this example, an article only has one short paragraph which fits on three lines. The three lines are displayed in three different columns due to column balancing.
article {
  width: 60em;
  height: auto;
  columns: 4;
  column-fill: balance;
}
Four columns, the first three have content.
Three lines displayed in three columns due to column balancing.
In this example, column balancing is turned off, and the article has a height:
article {
  width: 60em;
  height: 4em;
  columns: 4;
  column-fill: auto;
}

As a result, the first column is filled with all content:

Four columns, the first one has content.
No balancing so the whole text is shown in one paragraph.
In this example, an article has two paragraphs: first a long one, then a shorter one. This code is applied:
article {
  width: 60em;
  height: auto;
  columns: 4;
  column-fill: balance;
}

p {
  break-after: column;
}

The shortest column height possible contains five lines of text. After the column height has been established, columns are filled sequentially. As a result, the third column is as high as the first two columns, while the last column ends up being significantly shorter.

Four columns, all have content.
Once column height is established, columns are filled sequentially.
article {
  width: 60em;
  height: auto;
  columns: 4;
  column-fill: balance;
}

In this example, an article starts with an unbreakable figure which sets the column height. Subsequent content is filled sequentially into the remaining columns:

Column one contains an image, two and three have content.
Column height is established by the figure.
Tests

Tests relating to column balancing in combination with out-of-flow elements.


Other tests relating to balancing


8. Overflow

8.1. Overflow Inside Multicol Containers

Except for cases where this would cause a column break, content that extends outside column boxes visibly overflows and is not clipped to the column box.

Note: See § 5 Column Breaks for column breaks and § 8.2 Pagination and Overflow Outside Multicol Containers for whether it is clipped to the multi-column container’s content box.

In this example, the image is wider than the column:
An imagine in the first column has visible overflow
Content visibly overflows and is not clipped to the column box.
Tests

8.2. Pagination and Overflow Outside Multicol Containers

Content and column rules that extend outside column boxes at the edges of the multi-column container are clipped according to the overflow property.

A multicol container can have more columns than it has room for due to:

Tests

Tests to check that a scrollable container isn't split across multiple columns.


Columns that appear outside the multicol container in continuous contexts are called overflow columns. Overflow columns can affect the height of the multicol container.

In this example, the height of the multi-column container has been constrained to a maximum height. Also, the style sheet specifies that overflowing content should be visible:
div {
  max-height: 5em;
  overflow: visible;
}

As a result, the number of columns is increased.

Four columns, one outside the multicol container
An overflow column is created in the inline direction.

In continuous contexts overflow columns can affect the height of the multicol container. In this example a column appears in the overflow which has four lines of text. The multicol container is made tall enough to accommodate this column.

Four columns, overflow column is taller than the first three
The final column is an overflow column yet is taller than the others. The container is tall enough for this column.
In fragmented contexts, the overflow content goes into columns in subsequent fragments. Given the same content as in example 31 and a page box that only has room for five lines of formatted text, this would appear on the first page:
Three columns
The first three paragraphs appear on page one.

Assuming column balancing, this would appear on the second page:

Three columns
The overflow column is moved onto page two.
In this example, explicit column breaks are generated after paragraphs:
p {
  break-after: column;
}

As a result, the number of columns increases and the extra columns are added in the inline direction:

Four columns, one outside the multicol container
An overflow column is created in the inline direction.
In paged media, extra columns are shown on the next page. Given the same code as the previous example, the last paragraph appears on the second page. This would appear on the first page:
Three columns
The first three paragraphs appear on page one.

This would appear on the second page:

Three columns
The overflow column is moved onto page two.

Due to column balancing, the last paragraph is split across three columns.

Appendix B. Changes

This appendix is informative.

Changes from the Candidate Recommendation (CR) of 12 October 2021

Changes from the Working Draft (WD) of 12 February 2021

Changes from the Working Draft (WD) of 15 October 2019

Changes from the Working Draft (WD) of 28 May 2018

Changes from the Working Draft (WD) of 5 October 2017

Changes from the Candidate Recommendation (CR) of 12 April 2011.

Privacy Considerations

Multicol introduces no new privacy leaks.

Security Considerations

Multicol introduces no new security considerations.

Accessibility Considerations

Setting container height and line length can pose challenges for people with visual or cognitive disabilities. See WCAG Success Criterion 1.4.10 Reflow and WCAG 1.4.8 Visual Presentation to understand user needs.

Acknowledgments

This document is based on several older proposals and comments on older proposals. Contributors include:

Alex Mogilevsky, Andy Clarke, Anton Prowse, Bert Bos, Björn Höhrmann, Cédric Savarese, Chris Lilley, Chris Wilson, Daniel Glazman and Dave Raggett, David Hyatt, David Singer, David Woolley, Elika Etemad, Giovanni Campagna, Ian Hickson. Joost de Valk, Kevin Lawver, L. David Baron, Markus Mielke, Melinda Grant, Michael Day, Morten Stenshorne, Øyvind Stenhaug, Peter Linss, Peter-Paul Koch, Robert O’Callahan, Robert Stevahn, Sergey Genkin, Shelby Moore, Steve Zilles, Sylvain Galineau, Tantek Çelik, Till Halbach

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Tests

Tests relating to the content of this specification may be documented in “Tests” blocks like this one. Any such block is non-normative.


Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at https://www.w3.org/Style/CSS/Test/. Questions should be directed to the [email protected] mailing list.

CR exit criteria

For this specification to be advanced to Proposed Recommendation, there must be at least two independent, interoperable implementations of each feature. Each feature may be implemented by a different set of products, there is no requirement that all features be implemented by a single product. For the purposes of this criterion, we define the following terms:

independent
each implementation must be developed by a different party and cannot share, reuse, or derive from code used by another qualifying implementation. Sections of code that have no bearing on the implementation of this specification are exempt from this requirement.
interoperable
passing the respective test case(s) in the official CSS test suite, or, if the implementation is not a Web browser, an equivalent test. Every relevant test in the test suite should have an equivalent test created if such a user agent (UA) is to be used to claim interoperability. In addition if such a UA is to be used to claim interoperability, then there must one or more additional UAs which can also pass those equivalent tests in the same way for the purpose of interoperability. The equivalent tests must be made publicly available for the purposes of peer review.
implementation
a user agent which:
  1. implements the specification.
  2. is available to the general public. The implementation may be a shipping product or other publicly available version (i.e., beta version, preview release, or "nightly build"). Non-shipping product releases must have implemented the feature(s) for a period of at least one month in order to demonstrate stability.
  3. is not experimental (i.e., a version specifically designed to pass the test suite and is not intended for normal usage going forward).

The specification will remain Candidate Recommendation for at least six months.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-BACKGROUNDS-3]
Elika Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. 11 March 2024. CR. URL: https://www.w3.org/TR/css-backgrounds-3/
[CSS-BREAK-4]
Rossen Atanassov; Elika Etemad. CSS Fragmentation Module Level 4. 18 December 2018. WD. URL: https://www.w3.org/TR/css-break-4/
[CSS-DISPLAY-3]
Elika Etemad; Tab Atkins Jr.. CSS Display Module Level 3. 30 March 2023. CR. URL: https://www.w3.org/TR/css-display-3/
[CSS-GRID-2]
Tab Atkins Jr.; Elika Etemad; Rossen Atanassov. CSS Grid Layout Module Level 2. 18 December 2020. CR. URL: https://www.w3.org/TR/css-grid-2/
[CSS-POSITION-3]
Elika Etemad; Tab Atkins Jr.. CSS Positioned Layout Module Level 3. 10 August 2024. WD. URL: https://www.w3.org/TR/css-position-3/
[CSS-TABLES-3]
François Remy; Greg Whitworth; David Baron. CSS Table Module Level 3. 27 July 2019. WD. URL: https://www.w3.org/TR/css-tables-3/
[CSS-VALUES-3]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. 22 March 2024. CR. URL: https://www.w3.org/TR/css-values-3/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. 12 March 2024. WD. URL: https://www.w3.org/TR/css-values-4/
[CSS-WRITING-MODES-4]
Elika Etemad; Koji Ishii. CSS Writing Modes Level 4. 30 July 2019. CR. URL: https://www.w3.org/TR/css-writing-modes-4/
[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. REC. URL: https://www.w3.org/TR/CSS21/
[CSS3-ALIGN]
Elika Etemad; Tab Atkins Jr.. CSS Box Alignment Module Level 3. 17 February 2023. WD. URL: https://www.w3.org/TR/css-align-3/
[CSS3-BREAK]
Rossen Atanassov; Elika Etemad. CSS Fragmentation Module Level 3. 4 December 2018. CR. URL: https://www.w3.org/TR/css-break-3/
[CSS3-SIZING]
Tab Atkins Jr.; Elika Etemad. CSS Box Sizing Module Level 3. 17 December 2021. WD. URL: https://www.w3.org/TR/css-sizing-3/
[MEDIAQUERIES-5]
Dean Jackson; et al. Media Queries Level 5. 18 December 2021. WD. URL: https://www.w3.org/TR/mediaqueries-5/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119

Informative References

[CSS-TRANSFORMS-1]
Simon Fraser; et al. CSS Transforms Module Level 1. 14 February 2019. CR. URL: https://www.w3.org/TR/css-transforms-1/
[CSS3BOX]
Elika Etemad. CSS Box Model Module Level 3. 11 April 2024. REC. URL: https://www.w3.org/TR/css-box-3/

Property Index

Name Value Initial Applies to Inh. %ages Anim­ation type Canonical order Com­puted value
column-count auto | <integer [1,∞]> auto block containers except table wrapper boxes no N/A by computed value per grammar specified value
column-fill auto | balance | balance-all balance multicol containers no N/A discrete per grammar specified keyword
column-rule <'column-rule-width'> || <'column-rule-style'> || <'column-rule-color'> see individual properties see individual properties see individual properties see individual properties see individual properties per grammar see individual properties
column-rule-color <color> currentcolor multicol containers no N/A by computed value type per grammar computed color
column-rule-style <line-style> none multicol containers no N/A discrete per grammar specified keyword
column-rule-width <line-width> medium multicol containers no N/A by computed value type per grammar absolute length, snapped as a border width; 0 if the column rule style is none or hidden
column-span none | all none in-flow block-level elements no N/A discrete per grammar specified keyword
column-width auto | <length [0,∞]> auto block containers except table wrapper boxes no N/A by computed value type per grammar the keyword auto or an absolute length
columns <'column-width'> || <'column-count'> see individual properties see individual properties see individual properties see individual properties see individual properties per grammar see individual properties