[go: up one dir, main page]

CSS Multi-column Layout Module Level 1

W3C Working Draft,

This version:
https://www.w3.org/TR/2018/WD-css-multicol-1-20180528/
Latest published version:
https://www.w3.org/TR/css-multicol-1/
Editor's Draft:
https://drafts.csswg.org/css-multicol/
Previous Versions:
Test Suite:
http://test.csswg.org/suites/css-multicol-1_dev/nightly-unstable/
Issue Tracking:
Disposition of Comments
GitHub Issues
Editors:
(Opera Software)
Florian Rivoal (On behalf of Bloomberg)
Rachel Andrew (Invited Expert)

Abstract

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

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

Status of this document

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

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

GitHub Issues are preferred for discussion of this specification. When filing an issue, please put the text “css-multicol” in the title, preferably like this: “[css-multicol] …summary of comment…”. All issues and comments are archived, and there is also a historical archive.

This document was produced by the CSS Working Group (part of the Style Activity).

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

This document is governed by the 1 February 2018 W3C Process Document.

The following features are at-risk, and may be dropped during the CR period:

“At-risk” is a W3C Process term-of-art, and does not necessarily imply that the feature is in danger of being dropped or delayed. It means that the WG believes the feature may have difficulty being interoperably implemented in a timely manner, and marking it as such allows the WG to drop the feature if necessary when transitioning to the Proposed Rec stage, without having to publish a new Candidate Rec without the feature first.

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.

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:

body { column-width: 12em }

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

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

body { column-count: 2 }

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

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

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

However, as described below, setting both the width and number of columns rarely makes sense.

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

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

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

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

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

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

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

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.

2. The multi-column model

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

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 column box (or column for short). The content of a multicol container is flowed into its column boxes.

Column boxes in a multi-column container are arranged into rows. Like table cells, the column boxes in a row are ordered in the inline direction of the multicol container. 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 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 column gap, which may contain a column rule. 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.

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

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 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 row of column boxes.

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

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.

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

Given that the width is calculated relative to the column box, the image will be as wide as the column box:

an image contained inside a column box
The image is constrained by the column box that it is displayed in.

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

In this example, this CSS fragment describes the presentation of the image:
img { display: block; float: right }
an image floated and contained inside a column box
The image is floated inside the column box that it is displayed in.

A multi-column container establishes a new block formatting context, as per CSS 2.1 section 9.4.1.

A top margin set on the first child element of a multicol container will not collapse with the margins of the multicol container.
The first paragraph has a margin-top of 1em, which appears before the text.
The margin above the first paragraph has not collapsed, leaving a 1em margin above the first line in the multicol container.

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.

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. column-width

Name: column-width
Value: auto | <length>
Initial: auto
Applies to: block containers except table wrapper boxes
Inherited: no
Percentages: N/A
Media: visual
Computed value: the absolute length
Canonical order: per grammar
Animatable: as <length>

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>
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.
For example, consider this style sheet:
div {
  width: 100px;
  column-width: 45px;
  column-gap: 0;
  column-rule: none;
}

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

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

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

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

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

3.2. column-count

Name: column-count
Value: auto | <integer>
Initial: auto
Applies to: block containers except table wrapper boxes
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value
Canonical order: per grammar
Animatable: as <integer>

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>
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.
Example:
body { column-count: 3 }

3.3. columns

Name: columns
Value: <‘column-width’> || <‘column-count’>
Initial: see individual properties
Applies to: see individual properties
Inherited: see individual properties
Percentages: see individual properties
Media: see individual properties
Computed value: see individual properties
Canonical order: per grammar
Animatable: see individual properties

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

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

3.4. 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 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.

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 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.

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

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

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

3.5. Stacking context

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

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).

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.

4.1. column-gap

Name: column-gap
Value: <length-percentage> | normal
Initial: normal
Applies to: multicol containers
Inherited: no
Percentages: refer to the content width of the multi-column container
Media: visual
Computed value: as specified, with <length>s made absolute
Canonical order: per grammar
Animation type: length, percentage, or calc

column-gap accepting <length-percentage> is at risk, and may be reverted to <length>.

<length-percentage>
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.

normal
Identical to <length-percentage>, but with a used value of 1em.

4.2. column-rule-color

Name: column-rule-color
Value: <color>
Initial: currentcolor
Applies to: multicol containers
Inherited: no
Percentages: N/A
Media: visual
Computed value: same as the computed value of color is computed
Canonical order: per grammar
Animatable: as <color>
<color>
Specifies the color of the column rule.

4.3. column-rule-style

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

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.

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

4.4. column-rule-width

Name: column-rule-width
Value: <line-width>
Initial: medium
Applies to: multicol containers
Inherited: no
Percentages: N/A
Media: visual
Computed value: absolute length; 0 if the column rule style is none or hidden
Canonical order: per grammar
Animatable: as <length>

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

4.5. column-rule

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
Media: see individual properties
Computed value: see individual properties
Canonical order: per grammar
Animatable: see individual properties

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.

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

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. break-before, break-after, break-inside

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. column-span

Name: column-span
Value: none | all
Initial: none
Applies to: in-flow block-level elements
Inherited: no
Percentages: N/A
Media: visual
Computed value: specified value
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 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 formatting context.

Note: Whether the element establishes a new formatting context does not depend on whether the element is a descendent 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.

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

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

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

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

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.

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

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

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

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

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

In this example, the H2 element appears later in the content, and the height of the multicol container is constrained. Therefore, the H2 element appears in the overflow and there is not room to make the element spanning. As a result, the element appears as if 'column-span: none' was specified.
The h2 element is in an overflow column
The h2 element is in an overflow column and appears as if column-span none is specified
This example is similar to the previous example, except that the H2 element appears naturally in the last column. Still, there is not enough room to make the element spanning.
The h2 element is in the final column
The h2 element is in the final column and appears as if column-span none is specified
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 H2 element appears after the fourth paragraph.
Three columns with two lines of text each
This would appear on the first page
A spanning element across the three columns, text above and below.
This would appear on the second page
Spanners establish new formatting contexts, but their margins can be changed by their surroundings. In this example, two spanners naturally end up at the top of a page. The top margin of the first spanner is truncated due to adjoining an unforced break. The margins between the two spanners collapse with each other. However, the bottom margin of the second spanner does not collapse with the top margin of the subsequent element.
h2 {
  margin: 0.5em 0;
  column-span: all;
  background: silver
}
p { margin-top: 1em }
Two spanning elements after a page break
Margins collapse between two spanning elements, but not the bottom margin of a spanner and top margin of next element.

7. Filling columns

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

7.1. column-fill

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

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.

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

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

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

p {
  break-after: column;
}

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

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

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

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

8. Overflow

8.1. Overflow inside multicol containers

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

Note: See §5 Column breaks for column breaks and §8.2 Pagination and overflow outside multicol containers for whether it is clipped to the multi-column container’s content box.

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

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:

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

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

As a result, the number of columns is increased.

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

In continuous contexts overflow columns can 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.

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

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

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

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

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

This would appear on the second page:

Three columns
The overflow column is moved onto page two.

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

Appendix B. Changes

This appendix is informative.

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

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

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, Øyvind Stenhaug, Peter Linss, Peter-Paul Koch, Robert O’Callahan, Robert Stevahn, Sergey Genkin, Shelby Moore, Steve Zilles, Sylvain Galineau, Tantek Çelik, Till Halbach,

Conformance

Document conventions

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

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

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

This is an example of an informative example.

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

Note, this is an informative note.

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

Conformance classes

Conformance to this specification is defined for three conformance classes:

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

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

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

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

Requirements for Responsible Implementation of CSS

The following sections define several conformance requirements for implementing CSS responsibly, in a way that promotes interoperability in the present and future.

Partial Implementations

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

Implementations of Unstable and Proprietary Features

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

Implementations of CR-level Features

Once a specification reaches the Candidate Recommendation stage, implementers should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec, and should avoid exposing a prefixed variant of that feature.

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

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at https://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-BACKGROUNDS-3]
Bert Bos; Elika Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. 17 October 2017. CR. URL: https://www.w3.org/TR/css-backgrounds-3/
[CSS-COLOR-3]
Tantek Çelik; Chris Lilley; David Baron. CSS Color Module Level 3. 15 March 2018. PR. URL: https://www.w3.org/TR/css-color-3/
[CSS-COLOR-4]
Tab Atkins Jr.; Chris Lilley. CSS Color Module Level 4. 5 July 2016. WD. URL: https://www.w3.org/TR/css-color-4/
[CSS-DISPLAY-3]
Tab Atkins Jr.; Elika Etemad. CSS Display Module Level 3. 20 April 2018. WD. URL: https://www.w3.org/TR/css-display-3/
[CSS-OVERFLOW-3]
David Baron; Florian Rivoal. CSS Overflow Module Level 3. 31 May 2016. WD. URL: https://www.w3.org/TR/css-overflow-3/
[CSS-POSITION-3]
Rossen Atanassov; Arron Eicholz. CSS Positioned Layout Module Level 3. 17 May 2016. WD. URL: https://www.w3.org/TR/css-position-3/
[CSS-VALUES-3]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. 29 September 2016. CR. URL: https://www.w3.org/TR/css-values-3/
[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. REC. URL: https://www.w3.org/TR/CSS2/
[CSS22]
Bert Bos. Cascading Style Sheets Level 2 Revision 2 (CSS 2.2) Specification. 12 April 2016. WD. URL: https://www.w3.org/TR/CSS22/
[CSS3-BREAK]
Rossen Atanassov; Elika Etemad. CSS Fragmentation Module Level 3. 9 February 2017. CR. URL: https://www.w3.org/TR/css-break-3/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

Informative References

[CSS3-SIZING]
Tab Atkins Jr.; Elika Etemad. CSS Intrinsic & Extrinsic Sizing Module Level 3. 4 March 2018. WD. URL: https://www.w3.org/TR/css-sizing-3/
[CSS3BOX]
Bert Bos. CSS basic box model. 9 August 2007. WD. URL: https://www.w3.org/TR/css3-box/

Property Index

Name Value Initial Applies to Inh. %ages Media Ani­mat­able Anim­ation type Canonical order Com­puted value
column-count auto | <integer> auto block containers except table wrapper boxes no N/A visual as <integer> per grammar specified value
column-fill auto | balance | balance-all balance multicol containers no N/A see below discrete per grammar specified value
column-gap <length-percentage> | normal normal multicol containers no refer to the content width of the multi-column container visual length, percentage, or calc per grammar as specified, with <length>s made absolute
column-rule <‘column-rule-width’> || <‘column-rule-style’> || <‘column-rule-color’> see individual properties see individual properties see individual properties see individual properties see individual properties see individual properties per grammar see individual properties
column-rule-color <color> currentcolor multicol containers no N/A visual as <color> per grammar same as the computed value of color is computed
column-rule-style <line-style> none multicol containers no N/A visual no per grammar specified value
column-rule-width <line-width> medium multicol containers no N/A visual as <length> per grammar absolute length; 0 if the column rule style is none or hidden
column-span none | all none in-flow block-level elements no N/A visual discrete per grammar specified value
column-width auto | <length> auto block containers except table wrapper boxes no N/A visual as <length> per grammar the absolute length
columns <‘column-width’> || <‘column-count’> see individual properties see individual properties see individual properties see individual properties see individual properties see individual properties per grammar see individual properties