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 : 12 em }
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.
body{ columns : 2 } body{ columns : 12 em } body{ columns : 2 12 em }
Another group of properties introduced in this module describe gaps and rules between columns.
body{ column-gap : 1 em ; 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.
body{ column-gap : 1 em ; 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.
h2
elements are set to span across all columns.
div{ column-fill : balance} h2{ column-span : all}
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.
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
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.
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:
Tests
- multicol-margin-001.xht (live test) (source)
- multicol-margin-002.xht (live test) (source)
- multicol-margin-child-001.xht (live test) (source)
- multicol-nested-margin-001.xht (live test) (source)
- multicol-nested-margin-002.xht (live test) (source)
- multicol-nested-margin-003.xht (live test) (source)
- multicol-nested-margin-004.xht (live test) (source)
- multicol-nested-margin-005.xht (live test) (source)
Floats that appear inside multi-column layouts are positioned with regard to the column box where the float appears.
img{ display : block; float : right; }
In the HTML, the image appears after the sentence ending, "the leg of a chicken".
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
.container{ position : relative; column-count : 3 ; } img{ position : absolute; top : 20 px ; left : 40 px ; }
Out-of-flow descendants of a multi-column container do affect column balancing, and the block-size of the multi-column container.
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.
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.
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile11.1+
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android52+iOS Safari9+Chrome for Android?Android WebView50+Samsung Internet?Opera Mobile11.1+
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 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.
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
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android50+iOS Safari9+Chrome for Android?Android WebView50+Samsung Internet?Opera Mobile11.1+
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
- multicol-basic-003.html (live test) (source)
- multicol-basic-008.xht (live test) (source)
- multicol-reduce-000.xht (live test) (source)
- multicol-width-001.xht (live test) (source)
- multicol-width-002.xht (live test) (source)
- multicol-width-003.xht (live test) (source)
- multicol-width-ch-001.xht (live test) (source)
- multicol-width-negative-001.xht (live test) (source)
- multicol-width-invalid-001.xht (live test) (source)
- multicol-width-large-001.xht (live test) (source)
- multicol-width-large-002.xht (live test) (source)
- multicol-inherit-003.xht (live test) (source)
- multicol-list-item-001.xht (live test) (source)
- column-width-computed.html (live test) (source)
- column-width-invalid.html (live test) (source)
- column-width-valid.html (live test) (source)
div{ width : 100 px ; column-width : 45 px ; 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.
div{ width : 40 px ; column-width : 45 px ; 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
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android52+iOS Safari9+Chrome for Android?Android WebView50+Samsung Internet?Opera Mobile11.1+
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 |
Animatable: | 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
- multicol-count-001.xht (live test) (source)
- multicol-count-002.xht (live test) (source)
- multicol-basic-002.html (live test) (source)
- multicol-basic-006.xht (live test) (source)
- multicol-width-count-001.xht (live test) (source)
- multicol-width-count-002.xht (live test) (source)
- multicol-columns-toolong-001.xht (live test) (source)
- multicol-count-negative-001.xht (live test) (source)
- multicol-count-negative-002.xht (live test) (source)
- multicol-count-non-integer-001.xht (live test) (source)
- multicol-count-non-integer-002.xht (live test) (source)
- multicol-count-non-integer-003.xht (live test) (source)
- multicol-inherit-001.xht (live test) (source)
- multicol-inherit-002.xht (live test) (source)
- column-count-invalid.html (live test) (source)
- column-count-valid.html (live test) (source)
- column-count-computed.html (live test) (source)
3.3. The column-width and column-count Shorthand: The columns Property
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android52+iOS Safari9+Chrome for Android50+Android WebView50+Samsung Internet?Opera Mobile11.1+
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.
columns : 12 em ; /* column-width: 12em; column-count: auto */ columns: auto12 em ; /* 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
- multicol-columns-001.xht (live test) (source)
- multicol-columns-002.xht (live test) (source)
- multicol-columns-003.xht (live test) (source)
- multicol-columns-004.xht (live test) (source)
- multicol-columns-005.xht (live test) (source)
- multicol-columns-006.xht (live test) (source)
- multicol-columns-007.xht (live test) (source)
- multicol-columns-invalid-001.xht (live test) (source)
- multicol-columns-invalid-002.xht (live test) (source)
- multicol-basic-001.html (live test) (source)
- multicol-basic-003.html (live test) (source)
- multicol-basic-005.xht (live test) (source)
- multicol-basic-007.xht (live test) (source)
- columns-invalid.html (live test) (source)
- columns-valid.html (live test) (source)
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 Intrinsic & Extrinsic Sizing Module [CSS3-SIZING]) is expected to define this.
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.
div{ width : 40 em ; columns : 20 em ; column-gap : 0 ; } p{ break-after : column; }
< div > < p > one< p > two< p > three</ div >
div{ width : 80 em ; height : 10 em ; columns : 20 em ; 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.
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
- multicol-rule-001.xht (live test) (source)
- multicol-rule-003.xht (live test) (source)
- multicol-rule-004.xht (live test) (source)
- multicol-count-computed-003.xht (live test) (source)
- multicol-count-computed-005.xht (live test) (source)
- multicol-rule-fraction-002.xht (live test) (source)
- multicol-rule-large-001.xht (live test) (source)
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
- multicol-gap-animation-001.html (live test) (source)
- multicol-gap-animation-002.html (live test) (source)
- multicol-gap-animation-003.html (live test) (source)
- multicol-gap-fraction-001.xht (live test) (source)
- multicol-gap-fraction-002.html (live test) (source)
- multicol-gap-large-001.xht (live test) (source)
- multicol-gap-large-002.xht (live test) (source)
- multicol-gap-negative-001.xht (live test) (source)
- multicol-gap-000.xht (live test) (source)
- multicol-gap-002.xht (live test) (source)
- multicol-gap-percentage-001.html (live test) (source)
- multicol-gap-001.xht (live test) (source)
- multicol-gap-003.xht (live test) (source)
4.2. The Color of Column Rules: the column-rule-color property
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android52+iOS Safari9+Chrome for Android?Android WebView50+Samsung Internet?Opera Mobile11.1+
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
- multicol-rule-color-001.xht (live test) (source)
- multicol-rule-color-inherit-001.xht (live test) (source)
- multicol-rule-color-inherit-002.xht (live test) (source)
- column-rule-color-computed.html (live test) (source)
- column-rule-color-valid.html (live test) (source)
- column-rule-color-invalid.html (live test) (source)
4.3. The Style Of Column Rules: the column-rule-style property
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android52+iOS Safari9+Chrome for Android?Android WebView50+Samsung Internet?Opera Mobile11.1+
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
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android52+iOS Safari9+Chrome for Android?Android WebView50+Samsung Internet?Opera Mobile11.1+
Name: | column-rule-width |
---|---|
Value: | <line-width> |
Initial: | medium |
Applies to: | multicol containers |
Inherited: | no |
Percentages: | N/A |
Computed value: | absolute length; 0 if the column rule style is none or |
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
- multicol-rule-fraction-001.xht (live test) (source)
- multicol-rule-px-001.xht (live test) (source)
- multicol-rule-percent-001.xht (live test) (source)
- column-rule-width-computed.html (live test) (source)
- column-rule-width-invalid.html (live test) (source)
- column-rule-width-valid.html (live test) (source)
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
- multicol-shorthand-001.xht (live test) (source)
- multicol-rule-shorthand-001.xht (live test) (source)
- multicol-rule-shorthand-2.xht (live test) (source)
- multicol-rule-000.xht (live test) (source)
- multicol-rule-dashed-000.xht (live test) (source)
- multicol-rule-dotted-000.xht (live test) (source)
- multicol-rule-double-000.xht (live test) (source)
- multicol-rule-outset-000.xht (live test) (source)
- multicol-rule-none-000.xht (live test) (source)
- multicol-rule-hidden-000.xht (live test) (source)
- multicol-rule-inset-000.xht (live test) (source)
- multicol-rule-groove-000.xht (live test) (source)
- multicol-rule-ridge-000.xht (live test) (source)
- multicol-rule-solid-000.xht (live test) (source)
- column-rule-computed.html (live test) (source)
- column-rule-invalid.html (live test) (source)
- column-rule-valid.html (live test) (source)
body{ column-gap : 35 px ; column-rule-width : 35 px ; column-rule-style : solid; column-rule-color : black; }
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
In all current engines.
Opera37+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile37+
In all current engines.
Opera37+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile37+
In all current engines.
Opera37+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile37+
break-before, break-after, and break-inside are defined in [CSS3-BREAK].
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
In all current engines.
Opera11.1+Edge79+
Edge (Legacy)12+IE10+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView50+Samsung Internet?Opera Mobile11.1+
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 |
This property describes how many columns an element spans across. Values are:
- none
- The element does not span multiple columns.
- 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
- multicol-span-000.xht (live test) (source)
- multicol-span-all-001.xht (live test) (source)
- multicol-span-all-003.xht (live test) (source)
- multicol-span-all-block-sibling-003.xht (live test) (source)
- multicol-span-all-margin-001.xht (live test) (source)
- multicol-span-all-margin-002.xht (live test) (source)
- multicol-span-all-margin-bottom-001.xht (live test) (source)
- multicol-span-all-margin-nested-001.xht (live test) (source)
- multicol-span-all-margin-nested-002.xht (live test) (source)
- multicol-span-all-margin-nested-firstchild-001.xht (live test) (source)
- multicol-span-float-001.xht (live test) (source)
- inline-block-and-column-span-all.html (live test) (source)
- multicol-span-all-dynamic-remove-001.html (live test) (source)
- multicol-span-all-dynamic-add-001.html (live test) (source)
- multicol-span-all-dynamic-remove-002.html (live test) (source)
- multicol-span-all-dynamic-add-002.html (live test) (source)
- multicol-span-all-dynamic-remove-003.html (live test) (source)
- multicol-span-all-dynamic-add-003.html (live test) (source)
- multicol-span-all-dynamic-remove-004.html (live test) (source)
- multicol-span-all-dynamic-add-004.html (live test) (source)
- multicol-span-all-dynamic-add-005.html (live test) (source)
- multicol-span-all-dynamic-remove-006.html (live test) (source)
- multicol-span-all-dynamic-add-006.html (live test) (source)
- multicol-span-all-dynamic-remove-007.html (live test) (source)
- multicol-span-all-dynamic-add-007.html (live test) (source)
- multicol-span-all-dynamic-add-008.html (live test) (source)
- multicol-span-all-dynamic-add-009.html (live test) (source)
- multicol-span-all-dynamic-add-010.html (live test) (source)
- multicol-span-all-dynamic-add-011.html (live test) (source)
- multicol-span-all-dynamic-add-012.html (live test) (source)
- multicol-span-all-dynamic-add-013.html (live test) (source)
- multicol-span-all-children-height-001.html (live test) (source)
- multicol-span-all-children-height-002.html (live test) (source)
- multicol-span-all-children-height-003.html (live test) (source)
- multicol-span-all-children-height-004a.html (live test) (source)
- multicol-span-all-children-height-004b.html (live test) (source)
- multicol-span-all-children-height-005.html (live test) (source)
- multicol-span-all-children-height-006.html (live test) (source)
- multicol-span-all-004.html (live test) (source)
- multicol-span-all-005.html (live test) (source)
- multicol-span-all-006.html (live test) (source)
- multicol-span-all-007.html (live test) (source)
- multicol-span-all-008.html (live test) (source)
- multicol-span-all-009.html (live test) (source)
- multicol-span-all-010.html (live test) (source)
- multicol-span-all-011.html (live test) (source)
- multicol-span-all-rule-001.html (live test) (source)
- multicol-span-all-button-001.html (live test) (source)
- multicol-span-all-button-002.html (live test) (source)
- multicol-span-all-button-003.html (live test) (source)
- multicol-span-all-fieldset-001.html (live test) (source)
- multicol-span-all-fieldset-002.html (live test) (source)
- multicol-span-all-fieldset-003.html (live test) (source)
- multicol-span-all-restyle-001.html (live test) (source)
- multicol-span-all-restyle-002.html (live test) (source)
- multicol-span-all-restyle-003.html (live test) (source)
- multicol-span-all-restyle-004.html (live test) (source)
- multicol-span-all-list-item-001.html (live test) (source)
- multicol-span-all-list-item-002.html (live test) (source)
- float-with-line-after-spanner.html (live test) (source)
An element that spans more than one column is called a spanning element and the box it creates is called a 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.
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.
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.
< article > < section > < div class = "spanner" > Attempted spanner</ div > </ section > </ article >
article{ columns : 2 ; } section{ transform : rotate ( 90 deg ); } .spanner{ column-span : all; background : silver; }
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.
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 : 2 px solid red; margin-top : 65 px ; padding-top : 20 px ; } h2{ column-span : all; background : silver}
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.
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.
H2
element appears after the fourth paragraph.
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.
h2{ margin : 16 px 0 ; column-span : all; background : silver} p{ margin-top : 16 px }
7. Filling Columns
Opera9.2+Edge79+
Edge (Legacy)12+IE8+
Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
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
In all current engines.
Opera?Edge79+
Edge (Legacy)12+IE10+
Firefox for Android52+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?
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. The values are:
- balance
- Balance content equally between columns, as far as possible. In fragmented contexts, only the last fragment is balanced.
- balance-all
- Balance content equally between columns, as far as possible. In fragmented contexts, all fragments are balanced.
- auto
- fill columns sequentially
In continuous contexts, this property does not have any effect when there are overflow columns.
article{ width : 60 em ; height : auto; columns : 4 ; column-fill : balance; }
article{ width : 60 em ; height : 4 em ; columns : 4 ; column-fill : auto; }
As a result, the first column is filled with all content:
article{ width : 60 em ; 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.
article{ width : 60 em ; 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:
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.
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:
- a declaration that constrains the column height (e.g., using height or max-height). In this case, additional column boxes are created in the inline direction
- the size of the page. In this case, additional column boxes are moved to the next page(s).
- explicit column breaks. In this case, additional column boxes are created in the inline direction for continuous contexts and additional column boxes are moved to the next fragment(s) for fragmented media.
Tests
Columns that appear outside the multicol container in continuous contexts are called overflow columns. Overflow columns can affect the height of the multicol container.
div{ max-height : 5 em ; overflow : visible; }
As a result, the number of columns is increased.
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.
Assuming column balancing, this would appear on the second page:
p{ break-after : column; }
As a result, the number of columns increases and the extra columns are added in the inline direction:
This would appear on the second page:
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
- Added the text "and there is nothing between the spanning element and multicol container that establishes a containing block for fixed position descendants." Resolved 9 Mar 2022
Changes from the Working Draft (WD) of 12 February 2021
- Added the text "Out-of-flow descendants of a multi-column container do affect column balancing, and the block-size of the multi-column container." Resolved 12 May 2021
- Added the text, "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." Resolved 12 May 2021
- Adds an accessibility considerations section. Request from APA after review.
- Adds a note and example to make clear the manner in which columns are laid out in vertical writing modes. Request from i18n WG after review.
Changes from the Working Draft (WD) of 15 October 2019
- Added the text "The spanner becomes the containing block for absolutely positioned boxes inside the spanner where the spanning element establishes a containing block, otherwise the containing block chain goes to the multicol container.". Resolved 23 Oct 2020
- Adding the text "This property specifies whether content in a multi-column line that does not immediately precede a spanner is balanced across columns or not." Resolved 29 April 2020
Changes from the Working Draft (WD) of 28 May 2018
- Removed the non-normative text "However, as described below, setting both the width and number of columns rarely makes sense." Editorial 16 Sep 2019, issue 4291.
- Added the paragraph, "Spanners are block-level boxes therefore the margins of two adjacent spanners will collapse with each other. 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." Resolved 22 Oct 2018, see also the resolution for issue 2582.
- Clarified the spec to explain that a spanning element is taken out-of-flow, leaving a forced break. Added the paragraph, "A spanning element is taken out-of-flow, leaving a forced break. This does not affect the painting order of the spanning element." Resolved 28 Feb 2019.
- Moved the definition of the column-gap property to [CSS3-ALIGN] and added a paragraph detailing the specifics of column-gap in multicol:
"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." Resolved 4 June 2019. - Reworded the section The multi-column model, based on input from Morten Stenshorne in issue 2203.
- Removed the at-risk marker from the length-percentage value for column-gap. Resolved 4 June 2019.
- Updated the introduction to remove mention of the benefits of multicol over using tables for layout and instead refer to the unique characteristics of multicol. Editorial change referenced in issue 3654.
- Changed the sentence added in the pseudo-algorithm section after the 7 Jan 2016 resolution, to refer to columns and not tracks as tracks are not defined in this specification. Resolved 13 March 2019.
- Changes and clarifications to the SVG images used in the specification.
- Changed syntax to use bracketed range notation to reflect the prose restrictions on negative/non-zero values.
Changes from the Working Draft (WD) of 5 October 2017
- Changed references to paged media to refer to fragmented contexts. Resolved 12 Apr 2018.
- Changed a line regarding the
column-fill
property:In continuous media, this property does not have any effect in overflow columns.
To:In continuous media, this property does not have any effect when there are overflow columns.
Resolved: 12 Apr 2018 - Add a line of text plus an example to show that overflow columns can affect the multicol container height. Resolved: 12 Apr 2018
- Replaced the HTML mock-up examples with SVG versions, as the examples were unclear. Issue 1087.
- Changed the value of normal for column-gap to be 1em, rather than a UA-specified length with a suggestion of 1em. Resolved: 4 Apr 2018
- Clarified that negative values are not allowed for column-width, and that while 0 may be specified, used values will be clamped to a minimum of 1px. Resolved: 14 Mar 2018
- Clarified that where there is a spanning element content is automatically balanced across all columns in the immediately preceding column row before the element appears. Resolved: 9 Nov 2017
- Added clarification plus an additional example that spanning elements may be lower the first level of descendants, and that in the case of margins, borders and padding on the element containing the spanning, this would be drawn above the spanner. Resolved: 8 Nov 2017
- Changed the sentence
Column rules are painted in the inline content layer, but below all inline content inside the multicol element.
toColumn rules are painted just above the border of the multicol element. For scrollable multicol elements, note that while the border and background of the multicol element obviously aren’t scrolled, the rules need to scroll along with the columns.
Resolved: 7 Nov 2017 - Under section The Multi-column Model, removed two sentences
That is, column boxes behave like block-level, table cell, and inline-block boxes as per CSS 2.1, section 10.1, item 2 CSS21. However, column boxes do not establish block container boxes for elements with position: fixed or position: absolute.
. These were replaced with a clarification about the principal box and a new example showing how abspos elements refer to the multicol container. Resolved: 7 Nov 2017 - Removed the sentence "To indicate where column breaks should (or should not) appear, new keyword values are introduced." and following example (Example 7 in the WD published 5 Oct 2017) as the multicol specification no longer introduces these properties. Editorial
- Changed how we reference the element we have applied multicol to from multi-column or multicol
element
to multi-column or multicolcontainer
. Resolved: 22 November 2017 - Removed the example which stated "If a tall image is moved to a column on the next page to find room for it, its natural column may be left empty. If so, the column is still considered to have content for the purpose of deciding if the column rule should be drawn." Resolved: 7 September 2017
Changes from the Candidate Recommendation (CR) of 12 April 2011.
- Added July 2016 resolution to change the track size floor to a required UA-specified value, consistent with the CSS Grid spec. Resolved: 7 Jan 2016
- Remove the restriction about overflow columns only being in continuous media in the statement that column-fill has no effect on overflow columns. Resolved: September 2013.
- Added keyword balance-all and examples to demonstrate how this should work. Resolved: September 2013.
- The pseudo-algorithm has been revised on a number of occasions. Latest change Feb 2013.
- Clarified that properties columns, column-width, column-count "apply to block containers". Ref: Feb 2013.
- Breaking properties have been moved from this specification to the CSS Fragmentation Module.
- Change to column-fill wording to clarify that column-fill is honored before page breaks. Ref: Jan 2012.
- Amended example and text to clarify what happens with margin collapsing and spanning elements. Ref: Oct 2013.
- Clarification that column-rule-width does not alter the size or placement of columns. Ref: Sep 2013.
- Added that each column spanning element establishes a separate BFC margins between them collapse. Ref: Dec 2011.
- Column rules are painted in the inline content layer, but below all inline content inside the multicol. Ref: Feb 2013.
- Clarify that column-span causes the element to establish a formatting context even if it is not in a multicol.
- Column spanners do not always establish a block formatting context.
- Allow column-gap to accept <length-percentage> instead of just <length>
- column-width and column-count applies to block containers except table wrapper boxes.
- Content that overflows columns is not clipped.
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
Tests