Permalink
Fetching contributors…
Cannot retrieve contributors at this time
1496 lines (1198 sloc) 51.7 KB
<pre class="metadata">
Title: CSS Multi-column Layout Module Level 1
Group: CSSWG
Shortname: css-multicol
Level: 1
Status: ED
Work Status: Testing
WPT Path Prefix: /css/css-multicol/
ED: https://drafts.csswg.org/css-multicol/
TR: https://www.w3.org/TR/css-multicol-1/
Previous Version: https://www.w3.org/TR/2017/WD-css-multicol-1-20171005/
Previous Version: https://www.w3.org/TR/2011/CR-css3-multicol-20110412/
Previous Version: https://www.w3.org/TR/2009/CR-css3-multicol-20091217/
Previous Version: https://www.w3.org/TR/2009/WD-css3-multicol-20090630/
Previous Version: https://www.w3.org/TR/2007/WD-css3-multicol-20070606/
Previous Version: https://www.w3.org/TR/2005/WD-css3-multicol-20051215/
Previous Version: https://www.w3.org/TR/2001/WD-css3-multicol-20010118/
Previous Version: http://www.w3.org/1999/06/WD-css3-multicol-19990623
Editor: Håkon Wium Lie, Opera Software, howcome@opera.com, w3cid 9796
Editor: Florian Rivoal, On behalf of Bloomberg, https://florian.rivoal.net, w3cid 43241
Editor: Rachel Andrew, Invited Expert, https://rachelandrew.co.uk, w3cid 81117
Issue Tracking: Disposition of Comments https://drafts.csswg.org/css-multicol-1/issues
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.
Link Defaults: css-color (property) color, css2 (property) max-height, css-backgrounds-3 (value) hidden
At Risk: column-gap accepting <<length-percentage>> instead of <<length>>
</pre>
<pre class="link-defaults">
spec:css22; type:dfn; text: table wrapper box
</pre>
<style type="text/css">
.cols { width: 500px; height: 200px; background: #fff; position: relative; border: solid 5px blue; margin: 0.5em 2em 1em 0; font: bold 14px/19px Arial, sans-serif }
.cols p { padding: 3px; margin: 0 }
.col { position: absolute; left: 0px; top: 0; z-index: 6; width: 170px }
.gap { position: absolute; background: green; width: 5px; bottom: 0px; top: 0px; border: 10px solid yellow; border-top-width: 0; border-bottom-width: 0; }
.rep { position: absolute; top: 45px; background: black; height: 110px; width: 100px; color: white; z-index: 4 }
table.breaks { border-collapse: collapse; margin: 1em 0 }
table.breaks td, table.breaks th { border: thin solid black; padding: 0.1em 0.2em }
div.example:before { width: 9em }
</style>
<h2 id="introduction">
Introduction</h2>
(This section is not normative.)
This module describes <dfn export>multi-column layout</dfn> 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.
On the Web, tables have also been used to describe multi-column
layouts. The main benefit of using CSS-based columns is flexibility;
content can flow from one column to another, and the number of columns
can vary depending on the size of the viewport. Removing presentation
table markup from documents allows them to more easily be presented on
various output devices including speech synthesizers and small mobile
devices.
Multi-column layouts are easy to describe in CSS. Here is a simple example:
<div class=example>
<pre highlight="css">body { column-width: 12em }</pre>
In this example, the <code class=html>body</code> element is
set to have columns at least ''12em'' wide. The exact number of
columns will depend on the available space.
</div>
The number of columns can also be set explicitly in the style sheet:
<div class=example>
<pre highlight="css">body { column-count: 2 }</pre>
In this case, the number of columns is fixed and the column widths
will vary depending on the available width.
</div>
The shorthand 'columns' property can be used to set either,
or both, properties in one declaration.
<div class=example>
In these examples, the number of columns, the width of columns, and
both the number and width are set, respectively:
<pre highlight="css">
body { columns: 2 }
body { columns: 12em }
body { columns: 2 12em }
</pre>
However, as described below, setting both the width and number of
columns rarely makes sense.
</div>
Another group of properties introduced in this module describe
gaps and rules between columns.
<div class=example>
<pre highlight="css">
body {
column-gap: 1em;
column-rule: thin solid black;
}
</pre>
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.
</div>
The values of the 'column-rule' property are similar to those of
the CSS border properties. Like 'border', 'column-rule' is a
shorthand property.
<div class=example>
In this example, the shorthand 'column-rule' declaration from the
above example has been expanded:
<pre highlight="css">
body {
column-gap: 1em;
column-rule-width: thin;
column-rule-style: solid;
column-rule-color: black;
}
</pre>
</div>
The 'column-fill' and 'column-span' properties give style sheets a
wider range of visual expressions in multi-column layouts.
<div class=example>
In this example, columns are set to be balanced, i.e., to have
approximately the same length. Also, <code>h2</code> elements are set
to span across all columns.
<pre highlight="css">
div { column-fill: balance }
h2 { column-span: all }
</pre>
</div>
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.
<h2 id="the-multi-column-model">
The multi-column model</h2>
A <dfn lt="multi-column container|multicol container" oldids="multi-column-element" export>multi-column container</dfn>
(or <i>multicol container</i> for short)
is an element whose 'column-width' or 'column-count'
property is not ''column-width/auto'' and therefore acts as a container for
multi-column layout.
<wpt>
multicol-count-computed-004.xht
</wpt>
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 new type of container between the content box and
the content, namely the <dfn export local-lt=column>column box</dfn> (or <i>column</i> for
short). The content of a multicol container is flowed into its column
boxes.
Column boxes in a multi-column container are arranged into <dfn export lt="column row" local-lt=row>rows</dfn>.
Like table cells,
the column boxes in a row are ordered
in the inline direction of the multicol container.
The <dfn export>column width</dfn> is the length of the column box in the inline direction.
The <dfn export>column height</dfn> is the length of the column box in the block direction.
All column boxes in a row have the same column width,
and all column boxes in a row have the same column height.
Within each row in the multi-column container,
adjacent column boxes are separated by a <dfn noexport>column gap</dfn>,
which may contain a <dfn noexport>column rule</dfn>.
All column gaps in the same row are equal.
All column rules in the same row 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 row
of columns, and the height of each column will be equivalent to the
used height of the multi-column container's content box.
<div class="example">
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.
<figure>
<img alt="a diagram showing the various parts of multi-column layout" src="images/initial-example.svg">
<figcaption>A multi-column layout with the non-visible column-span and padding inside the multicol container highlighted.</figcaption>
</figure>
<figure>
<img alt="a diagram showing the various parts of multi-column layout" src="images/initial-example-b.svg">
<figcaption>The same layout as in the first image, as it would be displayed by an implementation.</figcaption>
</figure>
</div>
If the multi-column container is paginated, the height of each row is
constrained by the page and the content continues in a new row of
column boxes on the next page; a column box never splits across pages.
The same effect occurs when a <i>spanning element</i> 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 row of column boxes.
<div class="example">
<figure>
<img alt="a diagram showing a spanning element causing the shortened columns above the element with text continuing in new columns below" src="images/simple-span-example.svg">
<figcaption>A demonstration of how the spanning element divides the multicol container.</figcaption>
</figure>
</div>
Column boxes are block container boxes. The multi-column container is the principal box, and column boxes are anonymous.
Note: Column boxes do not become the containing block for elements with ''position: fixed'' or ''position: absolute''. The containing block is the multicol element, it being the principal box.
<wpt>
multicol-containing-001.xht
multicol-containing-002.xht
</wpt>
<div class="example">
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.
<pre highlight="css">
.container {
position: relative;
column-count: 3;
}
img {
position: absolute;
top: 20px;
left: 40px;
}
</pre>
<figure>
<img src="images/column-not-containing-block.svg" alt="The absolutely positioned image is positioned by reference to the multicol container not the column box.">
<figcaption>The figure demonstrates that the absolutely positioned image is positoned by reference to the multicol container and not the column box.</figcaption>
</figure>
</div>
<div class=example>
In this example, the width of the image is set with these rules:
<pre highlight="css">
img { display: block; width: 100% }
</pre>
Given that the width is calculated relative to the column box, the
image will be as wide as the column box:
<figure>
<img src="images/image-inside-column.svg" alt="an image contained inside a column box">
<figcaption>The image is constrained by the column box that it is displayed in.</figcaption>
</figure>
</div>
Floats that appear inside multi-column layouts are positioned with
regard to the column box where the float appears.
<div class="example">
In this example, this CSS fragment describes the presentation of the image:
<pre highlight="css">
img { display: block; float: right }
</pre>
<figure>
<img src="images/image-floated-in-column.svg" alt="an image floated and contained inside a column box">
<figcaption>The image is floated inside the column box that it is displayed in.</figcaption>
</figure>
</div>
A multi-column container establishes a new block formatting context,
as per CSS 2.1 section 9.4.1.
<div class="example">
A top margin set on the first child element of a multicol container will not collapse with the margins of the multicol container.
<figure>
<img src="images/margins-do-not-collapse.svg" alt="The first paragraph has a margin-top of 1em, which appears before the text.">
<figcaption>The margin above the first paragraph has not collapsed, leaving a 1em margin above the first line in the multicol container.</figcaption>
</figure>
</div>
<wpt>
multicol-margin-001.xht
multicol-margin-002.xht
multicol-margin-child-001.xht
multicol-nested-margin-001.xht
multicol-nested-margin-002.xht
multicol-nested-margin-003.xht
multicol-nested-margin-004.xht
multicol-nested-margin-005.xht
</wpt>
Nested multi-column containers are allowed, but there may be
implementation-specific limits.
<wpt>
multicol-nested-002.xht
multicol-nested-005.xht
</wpt>
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.
<h2 id="the-number-and-width-of-columns">
The number and width of columns</h2>
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:
<!--When the block direction
is unconstrained and no column breaks are added through style sheets,
these two properties determine the outcome:-->
<ul>
<li>'column-count'
<li>'column-width'
</ul>
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.
<h3 id='cw'>
'column-width'</h3>
<pre class=propdef>
Name: column-width
Value: auto | <<length>>
Initial: auto
Applies to: <a>block containers</a> except <a>table wrapper boxes</a>
Inherited: no
Percentages: N/A
Computed value: the keyword ''auto'' or an absolute length
Animation type: by computed value type
</pre>
This property describes the width of columns in multicol containers.
<dl dfn-type=value dfn-for=column-width>
<dt><dfn>auto</dfn>
<dd>
means that the column width will be determined by other properties
(e.g., 'column-count', if it has a non-auto value).
<dt><dfn><<length>></dfn>
<dd>
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.
</dl>
<wpt>
multicol-basic-003.html
multicol-basic-008.xht
multicol-reduce-000.xht
multicol-width-001.xht
multicol-width-002.xht
multicol-width-003.xht
multicol-width-ch-001.xht
multicol-width-negative-001.xht
multicol-width-invalid-001.xht
multicol-width-large-001.xht
multicol-width-large-002.xht
multicol-inherit-003.xht
multicol-list-item-001.xht
</wpt>
<div class="example">
For example, consider this style sheet:
<pre highlight="css">
div {
width: 100px;
column-width: 45px;
column-gap: 0;
column-rule: none;
}
</pre>
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>
<div class="example">
Also, consider this style sheet:
<pre highlight="css">
div {
width: 40px;
column-width: 45px;
column-gap: 0;
column-rule: none;
}
</pre>
The available space is smaller than the specified column width and
the actual column width will therefore be decreased.
</div>
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
element (assuming horizontal text) must also be specified.
<h3 id='cc'>
'column-count'</h3>
<pre class=propdef>
Name: column-count
Value: auto | <<integer>>
Initial: auto
Applies to: <a>block containers</a> except <a>table wrapper boxes</a>
Inherited: no
Percentages: N/A
Computed value: specified value
Animatable: by computed value
</pre>
This property describes the number of columns of a multicol container.
<dl dfn-type=value dfn-for=column-count>
<dt><dfn>auto</dfn>
<dd>
means that the number of columns will be determined by other properties
(e.g., 'column-width', if it has a non-auto value).
<dt><dfn><<integer>></dfn>
<dd>
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.
</dl>
<wpt>
multicol-count-001.xht
multicol-count-002.xht
multicol-basic-002.html
multicol-basic-006.xht
multicol-width-count-001.xht
multicol-width-count-002.xht
multicol-columns-toolong-001.xht
multicol-count-negative-001.xht
multicol-count-negative-002.xht
multicol-count-non-integer-001.xht
multicol-count-non-integer-002.xht
multicol-count-non-integer-003.xht
multicol-inherit-001.xht
multicol-inherit-002.xht
multicol-table-cell-001.xht
multicol-table-cell-height-001.xht
multicol-table-cell-height-002.xht
multicol-table-cell-vertical-align-001.xht
</wpt>
<div class="example">
Example:
<pre highlight="css">body { column-count: 3 }</pre>
</div>
<h3 id="columns">
'columns'</h3>
<pre class="propdef shorthand">
Name: columns
Value: <<'column-width'>> || <<'column-count'>>
</pre>
This is a shorthand property for setting 'column-width' and
'column-count'. Omitted values are set to their initial values.
<div class="example">
Here are some valid declarations using the 'columns' property:
<pre highlight="css">
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 */
</pre>
</div>
<wpt>
multicol-columns-001.xht
multicol-columns-002.xht
multicol-columns-003.xht
multicol-columns-004.xht
multicol-columns-005.xht
multicol-columns-006.xht
multicol-columns-007.xht
multicol-columns-invalid-001.xht
multicol-columns-invalid-002.xht
multicol-basic-001.html
multicol-basic-003.html
multicol-basic-005.xht
multicol-basic-007.xht
</wpt>
<h3 id="pseudo-algorithm">
Pseudo-algorithm</h3>
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
element.
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.
<!--
Two assumptions are being made by the pseudo-algorithm:
<ul>
<li>that the block direction is unconstrained
<li>that no column breaks are added through style sheets
</ul>
-->
The <code>floor(X)</code> function returns the largest integer Y &le; X.
<pre>
(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))))
</pre>
And:
<pre>
(11) W := max(0, ((U + column-gap)/N - column-gap))
</pre>
For the purpose of finding the number of auto-repeated tracks, the UA must floor the track 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.
<wpt>
column-count-used-001.html
</wpt>
<div class="example">
In this example, the actual column-count is higher than the used column-count due to explicit column breaks:
<pre highlight="css">
div {
width: 40em;
columns: 20em;
column-gap: 0;
}
p {
break-after: column;
}
</pre>
<pre highlight="html">
&lt;div>
&lt;p>one
&lt;p>two
&lt;p>three
&lt;/div>
</pre>
<figure>
<img src="images/column-count-higher-than-used-count.svg" alt="Two columns drawn inside the container, one outside">
<figcaption>The computed column-count is auto, the used column-count is 2 and the actual column-count is 3.</figcaption>
</figure>
</div>
<div class=example>
The actual column-count may be lower than the used column-count. Consider this example:
<pre highlight="css">
div {
width: 80em;
height: 10em;
columns: 20em;
column-gap: 0;
column-fill: auto;
}
</pre>
<pre highlight="html">
&lt;div>foo&lt;/div>
</pre>
The computed column-count is auto, the used column-count is 4, and the actual column-count is 1.
</div>
<h3 id="stacking-context">
Stacking context</h3>
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.
<wpt>
multicol-rule-stacking-001.xht
</wpt>
<h2 id="column-gaps-and-rules">
Column gaps and rules</h2>
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).
<wpt>
multicol-height-001.xht
multicol-nested-column-rule-001.xht
</wpt>
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 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. Column rules are
only drawn between two columns that both have content.
<wpt>
multicol-rule-001.xht
multicol-rule-003.xht
multicol-rule-004.xht
multicol-count-computed-003.xht
multicol-count-computed-005.xht
multicol-rule-fraction-002.xht
multicol-rule-large-001.xht
</wpt>
<h3 id='cg'>
'column-gap'</h3>
<pre class=propdef>
Name: column-gap
Value: <<length-percentage>> | normal
Initial: normal
Applies to: <a>multicol containers</a>
Inherited: no
Percentages: refer to the content width of the multi-column container
Computed value: the keyword ''column-gap/normal'' or a computed <<length-percentage>> value
Animation type: by computed value type
</pre>
<wpt>
multicol-gap-animation-001.html
multicol-gap-animation-002.html
multicol-gap-animation-003.html
multicol-gap-fraction-001.xht
multicol-gap-fraction-002.html
multicol-gap-large-001.xht
multicol-gap-large-002.xht
multicol-gap-negative-001.xht
</wpt>
<i>'column-gap' accepting <<length-percentage>> is at risk,
and may be reverted to <<length>>.</i>
<dl dfn-type=value dfn-for=column-gap>
<dt><dfn><<length-percentage>></dfn>
<dd>
Specifies the gap between columns.
If there is a column rule between columns,
it will appear in the middle of the gap.
The <<length>> or <<percentage>> cannot be negative.
<wpt>
multicol-gap-000.xht
multicol-gap-002.xht
multicol-gap-percentage-001.html
</wpt>
<dt><dfn>normal</dfn>
<dd>
Identical to <a value for="column-gap">&lt;length-percentage></a>,
but with a used value of ''1em''.
<wpt>
multicol-gap-001.xht
multicol-gap-003.xht
</wpt>
</dl>
<h3 id='crc'>
'column-rule-color'</h3>
<pre class=propdef>
Name: column-rule-color
Value: <<color>>
Initial: currentcolor
Applies to: multicol containers
Inherited: no
Percentages: N/A
Computed value: computed color
Animation type: by computed value type
</pre>
<dl>
<dt><dfn value for=column-rule-color><<color>></dfn>
<dd>
Specifies the color of the column rule.
</dl>
<wpt>
multicol-rule-color-001.xht
multicol-rule-color-inherit-001.xht
multicol-rule-color-inherit-002.xht
</wpt>
<h3 id='crs'>
'column-rule-style'</h3>
<pre class=propdef>
Name: column-rule-style
Value: <<line-style>>
Initial: none
Applies to: multicol containers
Inherited: no
Percentages: N/A
Computed value: specified keyword
Animation type: discrete
</pre>
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 <a href="https://www.w3.org/TR/CSS2/tables.html#collapsing-borders">collapsing border model</a>.
The ''border-style/none'' value forces the computed value of 'column-rule-width' to be ''0''.
<h3 id='crw'>
'column-rule-width'</h3>
<pre class=propdef>
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 ''border-style/none'' or ''hidden''
Animation type: by computed value type
</pre>
This property sets the width of the rule between columns.
Negative values are not allowed.
<wpt>
multicol-rule-fraction-001.xht
multicol-rule-px-001.xht
multicol-rule-percent-001.xht
</wpt>
<h3 id="cr">
'column-rule'</h3>
<pre class="propdef shorthand">
Name: column-rule
Value: <<'column-rule-width'>> || <<'column-rule-style'>> || <<'column-rule-color'>>
</pre>
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.
<wpt>
multicol-shorthand-001.xht
multicol-rule-shorthand-001.xht
multicol-rule-shorthand-2.xht
multicol-rule-000.xht
multicol-rule-dashed-000.xht
multicol-rule-dotted-000.xht
multicol-rule-double-000.xht
multicol-rule-outset-000.xht
multicol-rule-none-000.xht
multicol-rule-hidden-000.xht
multicol-rule-inset-000.xht
multicol-rule-groove-000.xht
multicol-rule-ridge-000.xht
multicol-rule-solid-000.xht
</wpt>
<div class=example>
In this example, the column rule and the column gap have the same
width. Therefore, they will occupy exactly the same space.
<pre highlight="css">
body {
column-gap: 1em;
column-rule-width: 1em;
column-rule-style: solid;
column-rule-color: black;
}
</pre>
<figure>
<img src="images/rule-same-width-as-gap.svg" alt="The rule completely covers any gap.">
<figcaption>The column rule and column gap occupy the same space.</figcaption>
</figure>
<wpt>
multicol-rule-samelength-001.xht
</wpt>
</div>
<h2 id="column-breaks">
Column breaks</h2>
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'.
<wpt>
multicol-break-000.xht
</wpt>
<h3 id="break-before-break-after-break-inside">
'break-before', 'break-after', 'break-inside'</h3>
'break-before', 'break-after', and 'break-inside'
are defined in [[!CSS3-BREAK]].
<h2 id="spanning-columns">
Spanning columns</h2>
The 'column-span' property makes it possible for an element to span across several columns.
<h3 id="column-span">
'column-span'</h3>
<pre class="propdef">
Name: column-span
Value: none | all
Initial: none
Applies to: in-flow block-level elements
Inherited: no
Percentages: N/A
Computed value: specified keyword
Animation type: discrete
</pre>
This property describes how many columns an element spans across. Values are:
<dl dfn-type=value dfn-for=column-span>
<dt><dfn>none</dfn>
<dd>
The element does not span multiple columns.
<wpt>
multicol-span-none-001.xht
</wpt>
<dt><dfn>all</dfn>
<dd>
The element spans 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 column row before the
element appears.
The element establishes an independent <a>formatting context</a>.
Note: Whether the element establishes a new <a>formatting context</a>
does not depend on whether the element is a descendent of a multicol or not.
When 'column-span' is ''column-span/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.
<wpt>
multicol-span-000.xht
multicol-span-all-001.xht
multicol-span-all-003.xht
multicol-span-all-block-sibling-003.xht
multicol-span-all-margin-001.xht
multicol-span-all-margin-002.xht
multicol-span-all-margin-bottom-001.xht
multicol-span-all-margin-nested-001.xht
multicol-span-all-margin-nested-002.xht
multicol-span-all-margin-nested-firstchild-001.xht
multicol-span-float-001.xht
inline-block-and-column-span-all.html
</wpt>
</dl>
An element that spans more than one column is called a
<dfn export>spanning element</dfn> and the box it creates is called a <dfn export>spanner</dfn>.
<div class="example">
In this example, an <code>h2</code> element has been added to the
sample document after the sixth sentence (i.e., after the words "the leg of a"). This styling applies:
<pre highlight="css">
h2 { column-span: all; background: silver }
</pre>
By setting 'column-span' to ''column-span/all'', all content that appears before
the <code>h2</code> element is shown before the <code>h2</code>
element.
<figure>
<img src="images/h2-spanner.svg" alt="An element spans all three columns">
<figcaption>The h2 element is set to column-span: all</figcaption>
</figure>
</div>
A spanning element may be lower than the first level of descendants as long as they are part of the same formatting context. 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.
<div class="example">
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 ''column-span/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.
<pre highlight="markup">
&lt;article&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;section&gt;
&lt;h2&gt;An h2 element&lt;/h2&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;/section&gt;
&lt;/article&gt;
</pre>
<pre highlight="css">
section {
border: 2px solid red;
margin-top: 3em;
padding-top: 2em;
}
h2 {
column-span: all;
background: silver
}
</pre>
<figure>
<img src="images/nested-spanner.svg" alt="An element spans all three columns, the red border around the section breaks before the spanner.">
<figcaption>The h2 element is set to column-span: all, the section has a red border and top padding and margin</figcaption>
</figure>
</div>
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 ''column-span/none'' had been specified on this property.
<div class="example">
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.
<figure>
<img src="images/h2-in-the-overflow-no-span.svg" alt="The h2 element is in an overflow column" style="max-height: 107px;">
<figcaption>The h2 element is in an overflow column and appears as if column-span none is specified</figcaption>
</figure>
</div>
<div class="example">
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.
<figure>
<img src="images/h2-in-the-last-column-no-span.svg" alt="The h2 element is in the final column" style="max-height: 107px;">
<figcaption>The h2 element is in the final column and appears as if column-span none is specified</figcaption>
</figure>
</div>
<wpt>
multicol-span-all-002.xht
</wpt>
<div class="example">
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.
An spanning <code>H2</code> element appears after the fourth paragraph.
<figure>
<img src="images/spanner-page-break1.svg" alt="Three columns with two lines of text each">
<figcaption>This would appear on the first page</figcaption>
</figure>
<figure>
<img src="images/spanner-page-break2.svg" alt="A spanning element across the three columns, text above and below.">
<figcaption>This would appear on the second page</figcaption>
</figure>
</div>
<div class="example">
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.
<pre highlight="css">
h2 {
margin: 0.5em 0;
column-span: all;
background: silver
}
p { margin-top: 1em }
</pre>
<figure>
<img src="images/two-spanners-margin-no-collapse.svg" alt="Two spanning elements after a page break">
<figcaption>Margins collapse between two spanning elements, but not the bottom margin of a spanner and top margin of next element.</figcaption>
</figure>
</div>
<h2 id="filling-columns">
Filling columns</h2>
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.
<h3 id='cf'>
'column-fill'</h3>
<pre class="propdef">
Name: column-fill
Value: auto | balance | balance-all
Initial: balance
Applies to: multicol containers
Inherited: no
Percentages: N/A
Computed value: specified keyword
Animation type: discrete
</pre>
The values are:
<dl dfn-type=value dfn-for=column-fill>
<dt><dfn>balance</dfn>
<dd>
Balance content equally between columns, as far as possible.
In fragmented contexts, only the last fragment is balanced.
<wpt>
multicol-fill-000.xht
multicol-fill-001.xht
</wpt>
<dt><dfn>balance-all</dfn>
<dd>
Balance content equally between columns, as far as possible.
In fragmented contexts, all fragments are balanced.
<dt><dfn>auto</dfn>
<dd>
fill columns sequentially
<wpt>
multicol-fill-auto-001.xht
multicol-fill-auto-002.xht
multicol-fill-auto-003.xht
multicol-fill-auto-block-children-001.xht
multicol-fill-auto-block-children-002.xht
multicol-fill-balance-001.xht
</wpt>
</dl>
<!--
In continuous contexts, this property will only be consulted if the
length of columns has been constrained. Otherwise, columns will
automatically be balanced.
-->
In continuous contexts, this property does not have any effect when there are overflow columns.
<!--
In fragmented contexts, this property will only have
effect on the last fragment the multicol container appears in.
-->
<div class="example">
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.
<pre highlight="css">
article {
width: 60em;
height: auto;
columns: 4;
column-fill: balance;
}
</pre>
<figure>
<img src="images/column-balancing-one-paragraph.svg" alt="Four columns, the first three have content.">
<figcaption>Three lines displayed in three columns due to column balancing.</figcaption>
</figure>
</div>
<div class="example">
In this example, column balancing is turned off:
<pre highlight="css">
article {
width: 60em;
height: auto;
columns: 4;
column-fill: auto;
}
</pre>
As a result, the first column is filled with all content:
<figure>
<img src="images/no-column-balancing-one-paragraph.svg" alt="Four columns, the first one has content.">
<figcaption>No balancing so the whole text is shown in one paragraph.</figcaption>
</figure>
</div>
<div class=example>
In this example, an article has two paragraphs: first a long one, then a shorter one. This code is applied:
<pre highlight="css">
article {
width: 60em;
height: auto;
columns: 4;
column-fill: balance;
}
p {
break-after: column;
}
</pre>
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.
<figure>
<img src="images/column-balancing-with-column-break.svg" alt="Four columns, all have content.">
<figcaption>Once column height is established, columns are filled sequentially.</figcaption>
</figure>
</div>
<div class="example">
<pre highlight="css">
article {
width: 60em;
height: auto;
columns: 4;
column-fill: balance;
}
</pre>
In this example, an article starts with an unbreakable figure which sets the column height.
Subsequent content is filled sequentially into the remaining columns:
<figure>
<img src="images/column-balancing-with-figure.svg" alt="Column one contains an image, two and three have content.">
<figcaption>Column height is established by the figure.</figcaption>
</figure>
</div>
<h2 id="overflow">
Overflow</h2>
<h3 id="overflow-inside-multicol-elements">
Overflow inside multicol containers</h3>
Except for cases where this would cause a column break,
content that extends outside column boxes
visibly overflows and is not clipped to the <a>column box</a>.
Note: See
[[#column-breaks]] for column breaks
and
[[#pagination-and-overflow-outside-multicol]] for whether it is clipped to the multi-column container’s content box.
<div class=example>
In this example, the image is wider than the column:
<figure>
<img src="images/image-overflow-not-clipped.svg" alt="An imagine in the first column has visible overflow">
<figcaption>Content visibly overflows and is not clipped to the column box.</figcaption>
</figure>
</div>
<wpt>
multicol-block-no-clip-001.xht
</wpt>
<h3 id="pagination-and-overflow-outside-multicol">
Pagination and overflow outside multicol containers</h3>
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:
<ul>
<li>
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
<li>
the size of the page. In this case, additional column boxes are
moved to the next page(s).
<li>
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.
</ul>
<wpt>
multicol-overflow-000.xht
multicol-overflowing-001.xht
</wpt>
Columns that appear outside the multicol container in continuous contexts
are called <dfn export>overflow columns</dfn>. Overflow columns can effect the height of the multicol container.
<div class="example">
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:
<pre highlight="css">
div {
max-height: 5em;
overflow: visible;
}
</pre>
As a result, the number of columns is increased.
<figure>
<img src="images/height-constraint-overflow-inline.svg" alt="Four columns, one outside the multicol container">
<figcaption>An overflow column is created in the inline direction.</figcaption>
</figure>
</div>
<div class="example">
In continuous contexts overflow columns can effect 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 accomodate this column.
<figure>
<img src="images/overflow-column-effects-height.svg" alt="Four columns, overflow column is taller than the first three">
<figcaption>The final column is an overflow column yet is taller than the others. The container is tall enough for this column.</figcaption>
</figure>
</div>
<div class="example">
In fragmented contexts, the overflow content goes into columns in subsequent fragments.
Given the same content as in the previous example
and a page box that only has room for five lines of formatted text,
this would appear on the first page:
<figure>
<img src="images/pagination-overflow-page1.svg" alt="Three columns">
<figcaption>The first three paragraphs appear on page one.</figcaption>
</figure>
Assuming column balancing, this would appear on the second page:
<figure>
<img src="images/pagination-overflow-page2.svg" alt="Three columns">
<figcaption>The overflow column is moved onto page two.</figcaption>
</figure>
</div>
<div class="example">
In this example, explicit column breaks are generated after paragraphs:
<pre highlight="css">
p {
break-after: column;
}
</pre>
As a result, the number of columns increases and the extra columns
are added in the inline direction:
<figure>
<img src="images/height-constraint-column-break-overflow-inline.svg" alt="Four columns, one outside the multicol container">
<figcaption>An overflow column is created in the inline direction.</figcaption>
</figure>
</div>
<div class="example">
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:
<figure>
<img src="images/pagination-column-break-overflow-page1.svg" alt="Three columns">
<figcaption>The first three paragraphs appear on page one.</figcaption>
</figure>
This would appear on the second page:
<figure>
<img src="images/pagination-column-break-overflow-page2.svg" alt="Three columns">
<figcaption>The overflow column is moved onto page two.</figcaption>
</figure>
Due to column balancing, the last paragraph is split across three columns.
</div>
<h2 class="no-num" id="changes">Appendix B. Changes</h2>
This appendix is <em>informative</em>.
<h3 id="changes-from-20171005">Changes from the <a href="https://www.w3.org/TR/2017/WD-css-multicol-1-20171005/">Working Draft (WD) of 5 October 2017</a></h3>
<ul>
<li>Changed references to paged media to refer to fragmented contexts. Resolved <a href="https://github.com/w3c/csswg-drafts/issues/1746#issuecomment-380731574">12 Apr 2018</a>.</li>
<li>Changed a line regarding the <code>column-fill</code> property:
<br><q>In continuous media, this property does not have any effect in
overflow columns.</q>
<br>To:
<br><q>In continuous media, this property does not have any effect when there are overflow columns.</q> <a href="https://github.com/w3c/csswg-drafts/issues/2549">Resolved: 12 Apr 2018</a></li>
<li>Add a line of text plus an example to show that overflow columns can effect the multicol container height. <a href="https://github.com/w3c/csswg-drafts/issues/1745">Resolved: 12 Apr 2018</a></li>
<li>Replaced the HTML mock-up examples with SVG versions, as the examples were unclear. <a href="https://github.com/w3c/csswg-drafts/issues/1087">Issue 1087</a>.</li>
<li>Changed the value of normal for column-gap to be 1em, rather than a UA-specified length with a suggestion of 1em. <a href="https://github.com/w3c/csswg-drafts/issues/2145#issuecomment-378781507">Resolved: 4 Apr 2018</a></li>
<li>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. <a href="https://github.com/w3c/csswg-drafts/issues/1741#issuecomment-373091628">Resolved: 14 Mar 2018</a></li>
<li>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. <a href="https://github.com/w3c/csswg-drafts/issues/1075">Resolved: 9 Nov 2017</a></li>
<li>Added clarification plus an additional example that spanning elements may be lower the the first level of descendents, and that in the case of margins, borders and padding on the element containing the spanning, this would be drawn above the spanner. <a href="https://github.com/w3c/csswg-drafts/issues/1072#issuecomment-342668025">Resolved: 8 Nov 2017</a></li>
<li>Changed the sentence <q>Column rules are painted in the inline content layer, but below all inline content inside the multicol element.</q> to <q>Column 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.</q> <a href="https://github.com/w3c/csswg-drafts/issues/1739#issuecomment-342659978">Resolved: 7 Nov 2017</a></li>
<li>Under section The Multi-column Model, removed two sentences <q>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''.</q>. THese were replaced with a clarification about the principal box and a new example showing how abspos elements refer to the multicol container. <a href="https://github.com/w3c/csswg-drafts/issues/1738#issuecomment-342661881">Resolved: 7 Nov 2017</a></li>
<li>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 <a href="https://www.w3.org/TR/2017/WD-css-multicol-1-20171005/">5 Oct 2017</a>) as the multicol specification no longer introduces these properties. <a href="https://github.com/w3c/csswg-drafts/issues/1966">Editorial</a></li>
<li>Changed how we reference the element we have applied multicol to from multi-column or multicol <q>element</q> to multi-column or multicol <q>container</q>. <a href="https://github.com/w3c/csswg-drafts/issues/1965">Resolved: 22 November 2017</a></li>
<li>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." <a href="https://github.com/w3c/csswg-drafts/issues/1740">Resolved: 7 September 2017</a></li>
</ul>
<h3 id="changes-from-20110412">Changes from the
<a href="https://www.w3.org/TR/2011/CR-css3-multicol-20110412/">Candidate Recommendation (CR) of 12 April 2011</a>.</h3>
<ul>
<li>Added July 2016 resolution to change the the track size floor to a required UA-specified value, consistent with the CSS Grid spec. <a href="https://lists.w3.org/Archives/Public/www-style/2016Jan/0031.html">Resolved: 7 Jan 2016</a>
<li>Remove the restriction about overflow columns only being in continuous media in the statement that 'column-fill' has no effect on overflow columns. <a href="https://lists.w3.org/Archives/Public/www-style/2013Sep/0471.html">Resolved: September 2013</a>.
<li>Added keyword balance-all and examples to demonstrate how this should work. <a href="https://lists.w3.org/Archives/Public/www-style/2013Sep/0471.html">Resolved: September 2013</a>.
<li> The pseudo-algorithm has been revised on a number of occasions. <a href="https://lists.w3.org/Archives/Public/www-style/2013Feb/0471.html">Latest change Feb 2013</a>.
<li>Clarified that properties 'columns', 'column-width', 'column-count' "apply to block containers". <a href="https://lists.w3.org/Archives/Public/www-style/2013Feb/0536.html">Ref: Feb 2013</a>.
<li>Breaking properties have beeen moved from this specification to the <a href="https://www.w3.org/TR/css-break-3/">CSS Fragmentation Module</a>.
<li>Change to 'column-fill' wording to clarify that 'column-fill' is honored before page breaks. <a href="https://lists.w3.org/Archives/Public/www-style/2012Jan/0393.html">Ref: Jan 2012</a>.
<li>Amended example and text to clarify what happens with margin collapsing and spanning elements. <a href="https://lists.w3.org/Archives/Public/www-style/2013Oct/0247.html">Ref: Oct 2013</a>.
<li>Clarification that 'column-rule-width' does not alter the size or placement of columns. <a href="https://lists.w3.org/Archives/Public/www-style/2013Sep/0550.html">Ref: Sep 2013</a>.
<li>Added that each column spanning element establishes a separate BFC margins between them collapse. <a href="https://lists.w3.org/Archives/Public/www-style/2011Dec/0262.html">Ref: Dec 2011</a>.
<li>Column rules are painted in the inline content layer, but below all inline content inside the multicol. <a href="https://lists.w3.org/Archives/Public/www-style/2013Feb/0363.html">Ref: Feb 2013</a>.
<li>Clarify that 'column-span' causes the element to establish a formatting context even if it is not in a multicol.
<li>Column spanners do not always establish a <em>block</em> formatting context.
<li>Allow 'column-gap' to accept <<length-percentage>> instead of just <<length>>
<li>'column-width' and 'column-count' applies to <a>block containers</a> except <a>table wrapper boxes</a>.
<li>Content that overflows columns is not clipped.
</ul>
<h2 class=no-num id=acknowledgments>
Acknowledgments</h2>
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,
Øyvind Stenhaug,
Peter Linss,
Peter-Paul Koch,
Robert O'Callahan,
Robert Stevahn,
Sergey Genkin,
Shelby Moore,
Steve Zilles,
Sylvain Galineau,
Tantek Çelik,
Till Halbach,
<wpt-rest></wpt-rest>