W3C

CSS Positioning Level 3

W3C Editor's Draft 25 July 2011

This version:
TBD
Latest published version:
http://www.w3.org/TR/TBD/
Latest editor's draft:
TBD
Previous version:
none
Editors:
Arron Eicholz, Microsoft Corporation
Sylvain Galineau, Microsoft Corporation

Abstract

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc. This module contains the features of CSS level 3 relating to positioned type boxes with their margins, positioning properties, and the "out-of-flow" layout of boxes. Also included in the document are sections that are relevant to properly positioning elements using absolute positioning. It includes and extends the functionality of CSS level 2 [CSS21].

Other kinds of layout, such as tables, "floating" boxes, ruby annotations, grid layouts, columns and basic handling of normal "flow" content, are described in other modules. Also, the layout of text inside each line is defined elsewhere.

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 http://www.w3.org/TR/.

The CSS WG maintains an issues list for this module. A test suite and implementation report for CSS Positioning Level 3 will be developed during the Candidate Recommendation phase, which will last a minimum of three months, i.e., at least until 15 December 2011. See the section "CR exit criteria" for more details.

This document was published by the CSS Working Group as an Editor's Draft. If you wish to make comments regarding this document, please send them to www-style@w3.org (subscribe, archives). All feedback is welcome.

Publication as a Editor's 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.

This document was produced by a group operating under the 5 February 2004 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.

Table of Contents

1. Introduction

Note, the model in this specification extends and clarifies the model described in the CSS level 2 revision 1 specification [CSS21].

CSS assumes the document layout is modeled as a tree of elements. Each element has an ordered list of zero or more child elements, with an optional string of text before the list, in-between the children and after the list. The unique element that has no parent is called the root element.

This module describes how any of the elements from the tree of elements can be arranged independent of document order (i.e. taken out of "flow").

With a positioned element the element may be placed anywhere within the content not specifically respecting the tree of elements order.

In [CSS21], the visual formatting model explained how each element in the document tree generates zero or more boxes according to the box model. This module further explains and extends the positioning scheme. The layout of these boxes is governed by:

The properties defined in this module apply to both continuous media and paged media.

1.1 Module Interactions

This module replaced and extends the positioning scheme features defined in [CSS21] sections:

2. Values

This specification follows the CSS property definition conventions from [CSS21].

All other values are defined in CSS Level 2 Revision 1 [CSS21].

All properties defined in this specification also accept the inherit keyword as their property value, but for readability it has not been listed explicitly.

3. The Viewport

User agents for continuous media generally offer users a viewport (a window or other viewing area on the screen) through which users consult a document. User agents may change the document's layout when the viewport is resized (see the initial containing block).

When the viewport is smaller than the area of the canvas on which the document is rendered, the user agent may offer a scrolling mechanism. There is at most one viewport per canvas, but user agents may render to more than one canvas (i.e., provide different views of the same document).

4. Containing Blocks

In CSS, many box positions and sizes are calculated with respect to the edges of a rectangular box called a containing block. In general, generated boxes act as containing blocks for descendant boxes; we say that a box "establishes" the containing block for its descendants. The phrase "a box's containing block" means "the containing block in which the box lives," not the one it generates.

Each box is given a position with respect to its containing block, but it is not confined by this containing block; it may overflow.

4.1 Definition of containing block

The position and size of an element's box(es) are sometimes calculated relative to a certain rectangle, called the containing block of the element. The containing block of an element is defined as follows:

  1. The containing block in which the root element lives is a rectangle called the initial containing block. For continuous media, it has the dimensions of the viewport and is anchored at the canvas origin; it is the page area for paged media. The 'direction' property of the initial containing block is the same as for the root element.
  2. For other elements, if the element's position is 'relative' or 'static', the containing block is formed by the content edge of the nearest block container ancestor box.
  3. If the element has 'position: fixed', the containing block is established by the viewport in the case of continuous media or the page area in the case of paged media.
  4. If the element has 'position: page', the containing block is the initial containing block. Typically this is the viewport or the page area when in paged media. In the case of CSS Regions this is the individual region.
  5. If the element has ‘position: absolute’, the containing block is established by the nearest ancestor with a 'position' other than 'static', in the following way:
    1. In the case that the ancestor is block-level, the containing block is formed by the padding edge of the ancestor.
    2. In the case that the ancestor is inline-level, the containing block depends on the 'direction' property of the ancestor:
      1. If the 'direction' is 'ltr', the top and left of the containing block are the top and left content edges of the first box generated by the ancestor, and the bottom and right are the bottom and right content edges of the last box of the ancestor.
      2. If the 'direction' is 'rtl', the top and right are the top and right edges of the first box generated by the ancestor, and the bottom and left are the bottom and left content edges of the last box of the ancestor.

        Note, in some cases when a line wraps it may seem as if the left and right positions are swapped.

    If there is no such ancestor, the containing block is the initial containing block.

In paged media, an absolutely positioned element is positioned relative to its containing block ignoring any page breaks (as if the document were continuous). The element may subsequently be broken over several pages.

For absolutely positioned content that resolves to a position on a page other than the page being laid out (the current page), or resolves to a position on the current page which has already been rendered for printing, printers may place the content:

Note, a block-level element that is split over several pages may have a different width on each page and that there may be device-specific limits.

Example(s):

With no positioning, the containing blocks (C.B.) in the following document:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
   <HEAD>
      <TITLE>Illustration of containing blocks</TITLE>
   </HEAD>
   <BODY id="body">
      <DIV id="div1">
      <P id="p1">This is text in the first paragraph...</P>
      <P id="p2">This is text <EM id="em1"> in the 
      <STRONG id="strong1">second</STRONG> paragraph.</EM></P>
      </DIV>
   </BODY>
</HTML>

are established as follows:

For box generated by C.B. is established by
htmlinitial C.B. (UA-dependent)
bodyhtml
div1body
p1div1
p2div1
em1p2
strong1p2

If we position "div1":

#div1 { position: absolute; left: 50px; top: 50px }

its containing block is no longer "body"; it becomes the initial containing block (since there are no other positioned ancestor boxes).

If we position "em1" as well:

#div1 { position: absolute; left: 50px; top: 50px }
#em1  { position: absolute; left: 100px; top: 100px }

the table of containing blocks becomes:

For box generated by C.B. is established by
htmlinitial C.B. (UA-dependent)
bodyhtml
div1initial C.B.
p1div1
p2div1
em1div1
strong1em1

By positioning "em1", its containing block becomes the nearest positioned ancestor box (i.e., that generated by "div1").

5. Normal Flow

Boxes in the normal flow belong to a formatting context, which may be block or inline, but not both simultaneously. See the CSS Basic Box Model module [CSS3BOX] for further details about normal flow.

6. Floats

A float is a box that is positioned within content, often left or right on the current line. The most interesting characteristic of a float (or "floated" or "floating" box) is that content may flow along its side (or be prohibited from doing so by the 'clear' property) or around the floated box. See the CSS Floats and Exclusions spec for more details about Floats.

7. Positioning schemes

In CSS, a box may be laid out according to three positioning schemes:

  1. Normal flow. In CSS, normal flow includes block formatting of block-level boxes, inline formatting of inline-level boxes, and relative positioning of block-level and inline-level boxes.
  2. Floats. In the float model, a box is first laid out according to the normal flow, then taken out of the flow and positioined, typically to the left or right. Content may flow along the side of a float.
  3. Absolute positioning. In the absolute positioning model, a box is removed from the normal flow entirely (it has no impact on later siblings) and assigned a position with respect to a containing block.

An element is called out of flow if it is floated, absolutely positioned, or is the root element. An element is called in-flow if it is not out-of-flow. The flow of an element A is the set consisting of A and all in-flow elements whose nearest out-of-flow ancestor is A.

7.1 Relative Positioning

Once a box has been laid out according to the normal flow or floated, it may be shifted relative to this position. This is called relative positioning. Offsetting a box (B1) in this way has no effect on the box (B2) that follows: B2 is given a position as if B1 were not offset and B2 is not re-positioned after B1's offset is applied. This implies that relative positioning may cause boxes to overlap. However, if relative positioning causes an 'overflow: auto' or 'overflow: scroll' box to have overflow, the UA must allow the user to access this content (at its offset position), which, through the creation of scrollbars, may affect layout.

A relatively positioned box keeps its normal flow size, including line breaks and the space originally reserved for it.

A relatively positioned box establishes a new a new containing block for absolutely positioned descendants. (This is a common use of relatively positioned boxes.) The section on containing blocks explains when a relatively positioned box establishes a new containing block.

For relatively positioned elements, 'left' and 'right' move the box(es) horizontally, without changing their size. 'Left' moves the boxes to the right, and 'right' moves them to the left. Since boxes are not split or stretched as a result of 'left' or 'right', the used values are always: left = -right.

If both 'left' and 'right' are 'auto' (their initial values), the used values are '0' (i.e., the boxes stay in their original position).

If 'left' is 'auto', its used value is minus the value of 'right' (i.e., the boxes move to the left by the value of 'right').

If 'right' is specified as 'auto', its used value is minus the value of 'left'.

If neither 'left' nor 'right' is 'auto', the position is over-constrained, and one of them has to be ignored. If the 'direction' property of the containing block is 'ltr', the value of 'left' wins and 'right' becomes -'left'. If 'direction' of the containing block is 'rtl', 'right' wins and 'left' is ignored.

Example(s):

The following three rules are equivalent:

div.a8 { position: relative; direction: ltr; left: -1em; right: auto }
div.a8 { position: relative; direction: ltr; left: auto; right: 1em }
div.a8 { position: relative; direction: ltr; left: -1em; right: 5em }

The 'top' and 'bottom' properties move relatively positioned element(s) up or down without changing their size. 'Top' moves the boxes down, and 'bottom' moves them up. Since boxes are not split or stretched as a result of 'top' or 'bottom', the used values are always: top = -bottom.

If 'top' and 'bottom' are 'auto', their used values are both '0'.

If one of them, 'top' or 'bottom', is 'auto', the 'auto' value becomes the negative of the other.

If neither 'top' and 'bottom' is 'auto', 'bottom' is ignored (i.e., the used value of 'bottom' will be minus the value of 'top').

Note, dynamic movement of relatively positioned boxes can produce animation effects in scripting environments (see also the 'visibility' property). Although relative positioning may be used as a form of superscripting and subscripting, the line height is not automatically adjusted to take the positioning into consideration. See the description of line height calculations for more information.

Examples of relative positioning are provided in the section comparing normal flow, floats, and absolute positioning.

7.2 Absolute positioning

In the absolute positioning model, a box is explicitly offset with respect to its containing block. It is removed from the normal flow entirely (it has no impact on later siblings). An absolutely positioned box establishes a new containing block for normal flow children and absolutely (but not fixed) positioned descendants. However, the contents of an absolutely positioned element do not flow around any other boxes. They may obscure the contents of another box (or be obscured themselves), depending on the stack levels of the overlapping boxes.

References in this specification to an absolutely positioned element (or its box) imply that the element's 'position' property has the value 'absolute' or 'fixed'.

7.3 Page positioning

In the page positioning model, a box is explicitly offset with respect to its initial containing block. It is removed from the normal flow entirely (it has no impact on later siblings). A page positioned box establishes a new containing block for normal flow children and absolutely (but not fixed, or page) positioned descendants. However, the contents of a page positioned element do not flow around any other boxes. They may obscure the contents of another box (or be obscured themselves), depending on the stack levels of the overlapping boxes. For paged media, boxes with page positions are only generated on the initial page where the page position element exists. Boxes with page position that are larger than the page area are clipped and the remaining part of the box is placed on the following page.

References in this specification to a page positioned element (or its box) imply that the element's 'position' property has the value 'page'.

7.4 Fixed positioning

Fixed positioning is a subcategory of absolute positioning. The only difference is that for a fixed positioned box, the containing block is established by the viewport. For continuous media, fixed boxes do not move when the document is scrolled. In this respect, they are similar to fixed background images. For paged media, boxes with fixed positions are repeated on every page. This is useful for placing, for instance, a signature at the bottom of each page. Boxes with fixed position that are larger than the page area are clipped. Parts of the fixed position box that are not visible in the initial containing block will not print.

Example(s):

Authors may use fixed positioning to create frame-like presentations. Consider the following frame layout:

Example of frame layout     [D]

This might be achieved with the following HTML document and style rules:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
  <HEAD>
    <TITLE>A frame document with CSS 2.1</TITLE>
    <STYLE type="text/css" media="screen">
      BODY { height: 8.5in } /* Required for percentage heights below */
      #header {
        position: fixed;
        width: 100%;
        height: 15%;
        top: 0;
        right: 0;
        bottom: auto;
        left: 0;
      }
      #sidebar {
        position: fixed;
        width: 10em;
        height: auto;
        top: 15%;
        right: auto;
        bottom: 100px;
        left: 0;
      }
      #main {
        position: fixed;
        width: auto;
        height: auto;
        top: 15%;
        right: 0;
        bottom: 100px;
        left: 10em;
      }
      #footer {
        position: fixed;
        width: 100%;
        height: 100px;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
      }
    </STYLE>
  </HEAD>
  <BODY>
    <DIV id="header"> ...  </DIV>
    <DIV id="sidebar"> ...  </DIV>
    <DIV id="main"> ...  </DIV>
    <DIV id="footer"> ...  </DIV>
  </BODY>
</HTML>
                
                

8. Choosing a positioning scheme: 'position' property

The 'position' and 'float' properties determine which of the CSS 2.1 positioning algorithms is used to calculate the position of a box.

'position'
Value:  static | relative | absolute | page | fixed
Initial:  static
Applies to:  all elements except table-column-group and table-column
Inherited:  no
Percentages:  N/A
Media:  visual
Computed value:  as specified

The values of this property have the following meanings:

static
The box is a normal box, laid out according to the normal flow. The 'top', 'right', 'bottom', and 'left' properties do not apply.
relative
The box's position is calculated according to the normal flow (this is called the position in normal flow). Then the box is offset relative to its normal position and in all cases, including table elements, does not affect the position of any following boxes. When a box B is relatively positioned, the position of the following box is calculated as though B were not offset. The effect of 'position: relative' on table elements is defined as follows:
  • table-row-group, table-header-group, table-footer-group and table-row offset relative to its normal position within the table. If table-cells span multiple rows, only the cells originating in the relative positioned row is offset.
  • table-column-group, table-column do not offset the respective column and has no visual affect when 'position: relative' is applied.
  • table-caption and table-cell offset relative to its normal position within the table. If a table cell spans multiple columns or rows the full spanned cell is offset.
absolute
The box's position (and possibly size) is specified with the 'top', 'right', 'bottom', and 'left' properties. These properties specify offsets with respect to the box's containing block. Absolutely positioned boxes are taken out of the normal flow. This means they have no impact on the layout of later siblings. Also, though absolutely positioned boxes have margins, they do not collapse with any other margins.
page
The box's position is calculated according to the 'absolute' model, but in addition, the box containing block is always the initial containing block. As with the 'absolute' model, the box's margins do not collapse with any other margins. In the case of the print media type, the box is rendered only on the initial page. UAs may paginate the content of paged boxes. Note that CSS Regions are also initial containing blocks, in accordance with section 3.1 of the CSS Regions Module.
fixed
The box's position is calculated according to the 'absolute' model, but in addition, the box is fixed with respect to some reference. As with the 'absolute' model, the box's margins do not collapse with any other margins. In the case of handheld, projection, screen, tty, and tv media types, the box is fixed with respect to the viewport and does not move when scrolled. In the case of the print media type, the box is rendered on every page, and is fixed with respect to the page box, even if the page is seen through a viewport (in the case of a print-preview, for example). For other media types, the presentation is undefined. Authors may wish to specify 'fixed' in a media-dependent way. For instance, an author may want a box to remain at the top of the viewport on the screen, but not at the top of each printed page. The two specifications may be separated by using an @media rule, as in:

Example(s):

   
        @media screen { 
          h1#first { position: fixed } 
        }
        @media print { 
          h1#first { position: static }
        }
        

UAs must not paginate the content of fixed boxes. Note that UAs may print invisible content in other ways. See "Content outside the page box" in chapter 13.

In previous versions of CSS user agents may treat position ‘fixed’ as 'static' on the root element. CSS3 removes that option and it is now required that the root element is ‘fixed’ as defined.

9. Box offsets: 'top', 'right', 'bottom', 'left'

An element is said to be positioned if its 'position' property has a value other than 'static'. Positioned elements generate positioned boxes, laid out according to four properties:

'top'
Value:   <length> | <percentage> | auto
Initial:  auto
Applies to:  positioned elements
Inherited:  no
Percentages:  refer to height of containing block
Media:  visual
Computed value:   for ‘position: relative’, see Relative Positioning. For ‘position: static’, ‘auto’. Otherwise: if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, ‘auto’.

This property specifies how far an absolutely positioned box's top margin edge is offset below the top edge of the box's containing block. For relatively positioned boxes, the offset is with respect to the top edges of the box itself (i.e., the box is given a position in the normal flow, then offset from that position according to these properties). For page positioned boxes, the offset is with respect to the top edge of the initial containing box itself. For absolutely positioned elements whose containing block is based on a block-level element, these properties are an offset from the padding edge of that element.

'right'
Value:  <length> | <percentage> | auto
Initial:  auto
Applies to:  positioned elements
Inherited:  no
Percentages:  refer to width of containing block
Media:  visual
Computed value:   for ‘position: relative’, see Relative Positioning. For ‘position: static’, ‘auto’. Otherwise: if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, ‘auto’.

Like 'top', but specifies how far a box's right margin edge is offset to the left of the right edge of the box's containing block. For relatively positioned boxes, the offset is with respect to the right edge of the box itself. For page positioned boxes, the offset is with respect to the right edge of the initial containing box itself. For absolutely positioned elements whose containing block is based on a block-level element, these properties are an offset from the padding edge of that element.

'bottom'
Value:  <length> | <percentage> | auto
Initial:  auto
Applies to:  positioned elements
Inherited:  no
Percentages:  refer to height of containing block
Media:  visual
Computed value:   for ‘position: relative’, see Relative Positioning. For ‘position: static’, ‘auto’. Otherwise: if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, ‘auto’.

Like 'top', but specifies how far a box's bottom margin edge is offset above the bottom of the box's containing block. For relatively positioned boxes, the offset is with respect to the bottom edge of the box itself. For page positioned boxes, the offset is with respect to the bottom edge of the initial containing box itself. For absolutely positioned elements whose containing block is based on a block-level element, these properties are an offset from the padding edge of that element.

'left'
Value:  <length> | <percentage> | auto
Initial:  auto
Applies to:  positioned elements
Inherited:  no
Percentages:  refer to width of containing block
Media:  visual
Computed value:   for ‘position: relative’, see Relative Positioning. For ‘position: static’, ‘auto’. Otherwise: if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, ‘auto’.

Like 'top', but specifies how far a box's left margin edge is offset to the right of the left edge of the box's containing block. For relatively positioned boxes, the offset is with respect to the left edge of the box itself.

The values for the four properties have the following meanings:

<length>
The offset is a fixed distance from the reference edge. Negative values are allowed.
<percentage>
The offset is a percentage of the containing block's width (for 'left' or 'right') or height (for 'top' and 'bottom'). Negative values are allowed.
auto
For non-replaced elements, the effect of this value depends on which of related properties have the value 'auto' as well. See the sections on the width and height of absolutely positioned, non-replaced elements for details. For replaced elements, the effect of this value depends only on the intrinsic dimensions of the replaced content. See the sections on the width and height of absolutely positioned, replaced elements for details.

Note for 'page' and 'fixed' positioned elements using large values or negative values may easily move elements outside the viewport and make the contents unreachable through scrolling or other means. Authors should be aware that page and fixed position elements are always relative to the initial containing block.

10. Sizing and positioning details

10.1 The width of absolute, page or fixed positioned, non-replaced element

The constraint that determines the used values for these elements is:


'left' + 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' + 'right' = width of containing block


If all three of 'left', 'width', and 'right' are 'auto': First set any 'auto' values for 'margin-left' and 'margin-right' to 0. Then, if the 'direction' property of the element establishing the static-position containing block is 'ltr' set 'left' to the static position and apply rule number three below; otherwise, set 'right' to the static-position and apply rule number one below.

If none of the three is 'auto': If both 'margin-left' and 'margin-right' are 'auto', solve the equation under the extra constraint that the two margins get equal values, unless this would make them negative, in which case when direction of the containing block is 'ltr' ('rtl'), set 'margin-left' ('margin-right') to zero and solve for 'margin-right' ('margin-left'). If one of 'margin-left' or 'margin-right' is 'auto', solve the equation for that value. If the values are over-constrained, ignore the value for 'left' (in case the 'direction' property of the containing block is 'rtl') or 'right' (in case 'direction' is 'ltr') and solve for that value.

Otherwise, set 'auto' values for 'margin-left' and 'margin-right' to 0, and pick one of the following six rules that apply.

  1. If 'left' and 'width' are 'auto' and 'right' is not 'auto', then the width is shrink-to-fit. Then solve for 'left'
  2. If 'left' and 'right' are 'auto' and 'width' is not 'auto', then if the 'direction' property of the element establishing the static-position containing block is 'ltr' set 'left' to the static-position, otherwise set 'right' to the static-position. Then solve for 'left' (if 'direction is 'rtl') or 'right' (if 'direction' is 'ltr').
  3. If 'width' and 'right' are 'auto' and 'left' is not 'auto', then the width is shrink-to-fit. Then solve for 'right'
  4. If 'left' is 'auto', 'width' and 'right' are not 'auto', then solve for 'left'
  5. If 'width' is 'auto', 'left' and 'right' are not 'auto', then solve for 'width'
  6. If 'right' is 'auto', 'left' and 'width' are not 'auto', then solve for 'right'

10.2 The width of absolute, page or fixed positioned, replaced element

If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'.

If 'height' and 'width' both have computed values of 'auto' and the element has no intrinsic width, but does have an intrinsic height and intrinsic ratio; or if 'width' has a computed value of 'auto', 'height' has some other computed value, and the element does have an intrinsic ratio; then the used value of 'width' is:


(used height) * (intrinsic ratio)


If 'height' and 'width' both have computed values of 'auto', the element has an intrinsic ratio but no intrinsic height or width, and the containing block's width does not itself depend on the replaced element's width, then the used value of 'width' is calculated from the constraint equation used for block-level, non-replaced elements in normal flow.

Otherwise, if 'width' has a computed value of 'auto', and the element has an intrinsic width, then that intrinsic width is the used value of 'width'.

Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, and then the used value of 'width' becomes 300px. If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.

After establishing the 'width', in order to position the replaced element, apply the following rules as appropriate.

  1. If both 'left' and 'right' have the value 'auto', and if the 'direction' property of the element establishing the static-position containing block is 'ltr', set 'left' to the static position and solve for 'right'; else if 'direction' is 'rtl', set 'right' to the static position and solve for 'left'.
  2. If 'left' is 'auto' and 'right' is not 'auto', replace any 'auto' on 'margin-left' or 'margin-right' with '0', then solve for 'left'
  3. If 'right' is 'auto' and 'left' is not 'auto', replace any 'auto' on 'margin-left' or 'margin-right' with '0', then solve for 'right'
  4. If at this point both 'margin-left' and 'margin-right' are still 'auto', solve the equation under the extra constraint that the two margins must get equal values, unless this would make them negative, in which case when the direction of the containing block is 'ltr' ('rtl'), set 'margin-left' ('margin-right') to zero and solve for 'margin-right' ('margin-left').
  5. If at this point there is an 'auto' left, solve the equation for that value.
  6. If at this point the values are over-constrained, ignore the value for either 'left' (in case the 'direction' property of the containing block is 'rtl') or 'right' (in case 'direction' is 'ltr') and solve for that value.

10.3 The height of absolute, page or fixed positioned, non-replaced element

For absolutely positioned elements, the used values of the vertical dimensions must satisfy this constraint:


'top' + 'margin-top' + 'border-top-width' + 'padding-top' + 'height' + 'padding-bottom' + 'border-bottom-width' + 'margin-bottom' + 'bottom' = height of containing block


If all three of 'top', 'height', and 'bottom' are auto, set 'top' to the static position and apply rule number three below.

If none of the three are 'auto': If both 'margin-top' and 'margin-bottom' are 'auto', solve the equation under the extra constraint that the two margins get equal values. If one of 'margin-top' or 'margin-bottom' is 'auto', solve the equation for that value. If the values are over-constrained, ignore the value for 'bottom' and solve for that value.

Otherwise, pick the one of the following six rules that applies.

  1. 'top' and 'height' are 'auto' and 'bottom' is not 'auto', then the height is based on the 'Auto' heights for block formatting context roots, set 'auto' values for 'margin-top' and 'margin-bottom' to 0, and solve for 'top'
  2. 'top' and 'bottom' are 'auto' and 'height' is not 'auto', then set 'top' to the static position, set 'auto' values for 'margin-top' and 'margin-bottom' to 0, and solve for 'bottom'
  3. 'height' and 'bottom' are 'auto' and 'top' is not 'auto', then the height is based on the 'Auto' heights for block formatting context roots, set 'auto' values for 'margin-top' and 'margin-bottom' to 0, and solve for 'bottom'
  4. 'top' is 'auto', 'height' and 'bottom' are not 'auto', then set 'auto' values for 'margin-top' and 'margin-bottom' to 0, and solve for 'top'
  5. 'height' is 'auto', 'top' and 'bottom' are not 'auto', then 'auto' values for 'margin-top' and 'margin-bottom' are set to 0 and solve for 'height'
  6. 'bottom' is 'auto', 'top' and 'height' are not 'auto', then set 'auto' values for 'margin-top' and 'margin-bottom' to 0 and solve for 'bottom'

10.4 The height of absolute, page or fixed positioned, replaced element

If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic height, then that intrinsic height is the used value of 'height'.

Otherwise, if 'height' has a computed value of 'auto' and the element has an intrinsic ratio then the used value of 'height' is:


(used width) / (intrinsic ratio)


Otherwise, if 'height' has a computed value of 'auto' and the element has an intrinsic height, then that intrinsic height is the used value of 'height'.

Otherwise, if 'height' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'height' must be set to the height of the largest rectangle that has a 2:1 ratio, has a height not greater than 150px, and has a width not greater than the device width.

After establishing the 'height', in order to position the replaced element, apply the following rules as appropriate.

  1. If both 'top' and 'bottom' have the value 'auto', replace 'top' with the element's static position.
  2. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or 'margin-bottom' with '0'.
  3. If at this point both 'margin-top' and 'margin-bottom' are still 'auto', solve the equation under the extra constraint that the two margins must get equal values.
  4. If at this point there is only one 'auto' left, solve the equation for that value.
  5. If at this point the values are over-constrained, ignore the value for 'bottom' and solve for that value.

10.5 'Auto' heights for block formatting context roots

In certain cases (see, e.g., The height of absolute, page or fixed positioned, non-replaced element above), the height of an element that establishes a block formatting context is computed as follows:

If it only has inline-level children, the height is the distance between the top of the topmost line box and the bottom of the bottommost line box.

If it has block-level children, the height is the distance between the top margin-edge of the topmost block-level child box and the bottom margin-edge of the bottommost block-level child box.

Absolutely positioned children are ignored, and relatively positioned boxes are considered without their offset. Note that the child box may be an anonymous block box.

In addition, if the element has any floating descendants whose bottom margin edge is below the element's bottom content edge, then the height is increased to include those edges. Only non-positioned floats that participate in this block formatting context are taken into account, e.g., floats inside absolutely positioned descendants or other floats are not.

11. Relationships between 'display', 'position', and 'float'

The three properties that affect box generation and layout — 'display', 'position', and 'float' — interact as follows:

  1. If 'display' has the value 'none', then 'position' and 'float' do not apply. In this case, the element generates no box.
  2. Otherwise, if 'position' has the value 'absolute', 'page' or 'fixed', and the value of 'float' is 'left' or 'right', the box is absolutely positioned and the computed value of 'float' is 'none'. The 'display' is set according to the table below. Positioning of the box will determined by the 'top', 'right', 'bottom' and 'left' properties and the box's containing block.
  3. Otherwise, if 'position' has the value 'absolute', 'page' or 'fixed', and the value of 'float' is not 'none', the box is absolutely positioned and floated. The 'display' is set according to the table below. Positioning of the box will determined by the 'top', 'right', 'bottom' and 'left' properties and the box's containing block.
  4. Otherwise, if 'float' is other than 'none', the box is floated and 'display' is set according to the table below.
  5. Otherwise, if the element is the root element, 'display' is set according to the table below.
  6. Otherwise, the remaining 'display' property values apply as specified.
Specified value Computed value
inline-table table
inline, table-row-group, table-column, table-column-group, table-header-group, table-footer-group, table-row, table-cell, table-caption, inline-block block
others same as specified

12. Comparison of normal flow, floats, and absolute positioning

This section is non-normative.


To illustrate the differences between normal flow, relative positioning, floats, and absolute positioning, we provide a series of examples based on the following HTML:


        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
        <HTML>
          <HEAD>
            <TITLE>Comparison of positioning schemes</TITLE>
          </HEAD>
        
          <BODY>
            <P>Beginning of body contents.
              <SPAN id="outer"> Start of outer contents.
              <SPAN id="inner"> Inner contents.</SPAN>
              End of outer contents.</SPAN>
        
              End of body contents.
            </P>
          </BODY>
        </HTML>
        

In this document, we assume the following rules:


        body { display: block; font-size:12px; line-height: 200%; 
               width: 400px; height: 400px }
        p    { display: block }
        span { display: inline }
        

The final positions of boxes generated by the outer and inner elements vary in each example. In each illustration, the numbers to the left of the illustration indicate the normal flow position of the double-spaced (for clarity) lines.

Note. The diagrams in this section are illustrative and not to scale. They are meant to highlight the differences between the various positioning schemes in CSS 2.1, and are not intended to be reference renderings of the examples given.

12.1 Normal flow

Consider the following CSS declarations for outer and inner that do not alter the normal flow of boxes:


            
            #outer { color: red }
            #inner { color: blue }
            

The P element contains all inline content: anonymous inline text and two SPAN elements. Therefore, all of the content will be laid out in an inline formatting context, within a containing block established by the P element, producing something like:

Image illustrating the normal flow of text between parent and sibling boxes.    [D]

12.2 Relative positioning

To see the effect of relative positioning, we specify:


            #outer { position: relative; top: -12px; color: red }
            #inner { position: relative; top: 12px; color: blue }
            

Text flows normally up to the outer element. The outer text is then flowed into its normal flow position and dimensions at the end of line 1. Then, the inline boxes containing the text (distributed over three lines) are shifted as a unit by '-12px' (upwards).

The contents of inner, as a child of outer, would normally flow immediately after the words "of outer contents" (on line 1.5). However, the inner contents are themselves offset relative to the outer contents by '12px' (downwards), back to their original position on line 2.

Note that the content following outer is not affected by the relative positioning of outer.

Image illustrating the effects of relative positioning on a
            box's content.   [D]

Note also that had the offset of outer been '-24px', the text of outer and the body text would have overlapped.

12.3 Floating a box

Now consider the effect of floating the inner element's text to the right by means of the following rules:


            #outer { color: red }
            #inner { float: right; width: 130px; color: blue }
            

Text flows normally up to the inner box, which is pulled out of the flow and floated to the right margin (its 'width' has been assigned explicitly). Line boxes to the left of the float are shortened, and the document's remaining text flows into them.

Image illustrating the effects of floating a box.    [D]

To show the effect of the 'clear' property, we add a sibling element to the example:


            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
            
            <HTML>
              <HEAD>
                <TITLE>Comparison of positioning schemes II</TITLE>
              </HEAD>
              <BODY>
                <P>Beginning of body contents.
                  <SPAN id=outer> Start of outer contents.
                  <SPAN id=inner> Inner contents.</SPAN>
            
                  <SPAN id=sibling> Sibling contents.</SPAN>
                  End of outer contents.</SPAN>
                  End of body contents.
                </P>
              </BODY>
            
            </HTML>
            

The following rules:


            #inner { float: right; width: 130px; color: blue }
            #sibling { color: red }
            

cause the inner box to float to the right as before and the document's remaining text to flow into the vacated space:

Image illustrating the effects of floating a box without
            setting the clear property to control the flow of text around the
            box.   [D]

However, if the 'clear' property on the sibling element is set to 'right' (i.e., the generated sibling box will not accept a position next to floating boxes to its right), the sibling content begins to flow below the float:


            #inner { float: right; width: 130px; color: blue }
            #sibling { clear: right; color: red }
            

Image illustrating the effects of floating an element with setting the clear property to control the flow of text around the element.    [D]

12.4 Absolute positioning

Next, we consider the effect of absolute positioning. Consider the following CSS declarations for outer and inner:


            #outer { 
                position: absolute; 
                top: 200px; left: 200px; 
                width: 200px; 
                color: red;
            }
            #inner { color: blue }
            

which cause the top of the outer box to be positioned with respect to its containing block. The containing block for a positioned box is established by the nearest positioned ancestor (or, if none exists, the initial containing block, as in our example). The top side of the outer box is '200px' below the top of the containing block and the left side is '200px' from the left side. The child box of outer is flowed normally with respect to its parent.

Image illustrating the effects of absolutely positioning a box.    [D]

The following example shows an absolutely positioned box that is a child of a relatively positioned box. Although the parent outer box is not actually offset, setting its 'position' property to 'relative' means that its box may serve as the containing block for positioned descendants. Since the outer box is an inline box that is split across several lines, the first inline box's top and left edges (depicted by thick dashed lines in the illustration below) serve as references for 'top' and 'left' offsets.


            #outer { 
              position: relative; 
              color: red 
            }
            #inner { 
              position: absolute; 
              top: 200px; left: -100px; 
              height: 130px; width: 130px; 
              color: blue;
            }
            

This results in something like the following:

Image illustrating the effects of absolutely positioning a
            box with respect to a containing block.   [D]

If we do not position the outer box:


            #outer { color: red }
            #inner {
              position: absolute; 
              top: 200px; left: -100px; 
              height: 130px; width: 130px; 
              color: blue;
            }
            

the containing block for inner becomes the initial containing block (in our example). The following illustration shows where the inner box would end up in this case.

Image illustrating the effects of absolutely positioning a box with respect to a containing block established by a normally positioned parent.    [D]

Relative and absolute positioning may be used to implement change bars, as shown in the following example. The following fragment:


            <P style="position: relative; margin-right: 10px; left: 10px;">
            I used two red hyphens to serve as a change bar. They
            will "float" to the left of the line containing THIS
            <SPAN style="position: absolute; top: auto; left: -1em; color: red;">--</SPAN>
            
            word.</P>
            

might result in something like:

Image illustrating the use of floats to create a changebar effect.    [D]

First, the paragraph (whose containing block sides are shown in the illustration) is flowed normally. Then it is offset '10px' from the left edge of the containing block (thus, a right margin of '10px' has been reserved in anticipation of the offset). The two hyphens acting as change bars are taken out of the flow and positioned at the current line (due to 'top: auto'), '-1em' from the left edge of its containing block (established by the P in its final position). The result is that the change bars seem to "float" to the left of the current line.

12.5 Page positioning

Finally, we consider the effect of page positioning. Consider the following CSS declarations for outer and inner:


            #outer { 
                position: page; 
                top: 200px; left: 200px; 
                width: 200px; 
                color: red;
            }
            #inner { color: blue }
            

which cause the top of the outer box to be positioned with respect to its containing block. The containing block for a page positioned box is always established by the initial containing block. The top side of the outer box is '200px' below the top of the initial containing block and the left side is '200px' from the left side. The child box of outer is flowed normally with respect to its parent.

Image illustrating the effects of absolutely positioning a box.    [D]

The following example shows a page positioned box that is a child of a relatively positioned box. Although the parent outer box is setting its 'position' property to 'relative' this outer box box does not serve as the containing block for page positioned descendants. Since the inner box is a page positioned element its containing block is not the relative positioned outer box box, page positioned elements are positioned from the initial containing block, in this case the top and left edges (depicted by thick dashed lines in the illustration below) serve as references for 'top' and 'left' offsets.


            #outer { 
              position: relative; 
              color: red 
            }
            #inner { 
              position: page; 
              top: 200px; left: -100px; 
              height: 130px; width: 130px; 
              color: blue;
            }
            

This results in something like the following:

Image illustrating the effects of absolutely positioning a
            box with respect to a containing block.   [D]

The previous image is incorrect. Need to create a new image.

If we do not position the outer box:


            #outer { color: red }
            #inner {
              position: page; 
              top: 200px; left: -100px; 
              height: 130px; width: 130px; 
              color: blue;
            }
            

the containing block for inner becomes the initial containing block. The following illustration shows where the inner box would end up in this case.

Image illustrating the effects of absolutely positioning a box with respect to a containing block established by a normally positioned parent.    [D]

13. Clipping: the clip property

A clipping region defines what portion of an element's border box is visible. By default, the element is not clipped. However, the clipping region may be explicitly set with the 'clip' property.

'clip'
Value:  <shape> | auto |
Initial:  auto
Applies to:  absolutely positioned elements
Inherited:  no
Percentages:  N/A
Media:  visual
Computed value:  'auto' if specified as 'auto', otherwise a rectangle with four values, each of which is 'auto' if specified as 'auto' and the computed length otherwise

The 'clip' property applies only to absolutely positioned elements. Values have the following meanings:

auto
The element does not clip.
<shape>
rect(<top>, <right>, <bottom>, <left>)

Each of the arguments <top> and <bottom> specify offsets from the top border edge of the box, and <right>, and <left> specify offsets from the left border edge of the box. Authors should separate offset values with commas. User agents must support separation with commas, but may also support separation without commas (but not a combination), because a previous revision of this specification was ambiguous in this respect.

<top>, <right>,<bottom>, and <left> may either have a <length> value or 'auto'. Negative lengths are permitted. The value 'auto' means that a given edge of the clipping region will be the same as the edge of the element's generated border box (i.e., 'auto' means the same as '0' for <top> and <left>, the same as the used value of the height plus the sum of vertical padding and border widths for <bottom>, and the same as the used value of the width plus the sum of the horizontal padding and border widths for <right>, such that four 'auto' values result in the clipping region being the same as the element's border box).

When coordinates are rounded to pixel coordinates, care should be taken that no pixels remain visible when <left> and <right> have the same value (or <top> and <bottom> have the same value), and conversely that no pixels within the element's border box remain hidden when these values are 'auto'.

inset(<top>, <right>, <bottom>, <left>)

Like rect(), except that the values are offsets relative to the respective edges of the element.

diagram of rect vs inset-rect

Diagram of the rectangles defined by rect() and inset-rect().

An element's clipping region clips out any aspect of the element (e.g., content, children, background, borders, text decoration, outline and visible scrolling mechanism — if any) that is outside the clipping region. Content that has been clipped does not cause overflow.

The element's ancestors may also clip portions of their content (e.g., via their own 'clip' property and/or if their 'overflow' property is not 'visible'); what is rendered is the cumulative intersection.

If the clipping region exceeds the bounds of the UA's document window, content may be clipped to that window by the native operating environment.

Example(s):

Example: The following two rules:


        p#one { clip: rect(5px, 40px, 45px, 5px); }
        p#two { clip: rect(5px, 55px, 45px, 5px); }

and assuming both Ps are 50 by 55 px, will create, respectively, the rectangular clipping regions delimited by the dashed lines in the following illustrations:

Two clipping regions    [D]

The following rule:


        IMG { clip: rect(5px, 40px, 45px, 5px); }
                

will create the rectangular clipping region delimited by the dashed line in the following illustration:

A clipping region [D]

An image of 50 by 55 pixels is clipped with a clipping mask of 35 by 40 pixels.

Note. In CSS 2.1, all clipping regions are rectangular. We anticipate future extensions to permit non-rectangular clipping.

14. Layered presentation

In the following sections, the expression "in front of" means closer to the user as the user faces the screen.

In CSS, each box has a position in three dimensions. In addition to their horizontal and vertical positions, boxes lie along a "z-axis" and are formatted one on top of the other. Z-axis positions are particularly relevant when boxes overlap visually. This section discusses how boxes may be positioned along the z-axis.

Each box belongs to one stacking context . Each box in a given stacking context has an integer stack level , which is its position on the z-axis relative to other boxes in the same stacking context. Boxes with greater stack levels are always formatted in front of boxes with lower stack levels. Boxes may have negative stack levels. Boxes with the same stack level in a stacking context are stacked bottom-to-top according to document tree order.

The rootelement creates a root stacking context , but other elements may establish local stacking contexts . Stacking contexts are inherited. A local stacking context is atomic; boxes in other stacking contexts may not come between any of its boxes.

An element that establishes a local stacking context generates a box that has two stack levels: one for the stacking context it creates (always ‘0’) and one for the stacking context to which it belongs (given by the z-index property).

An element's box has the same stack level as its parent's box unless given a different stack level with the z-index property.

'z-index'
Value:  auto | <integer>
Initial:  auto
Applies to:  positioned elements
Inherited:  no
Percentages:  N/A
Media:  visual
Computed value:  as specified

For a positioned box, the 'z-index' property specifies:

  1. The stack level of the box in the current stacking context.
  2. Whether the box establishes a stacking context.

Values have the following meanings:

<integer>
This integer is the stack level of the generated box in the current stacking context. The box also establishes a new stacking context.
auto
The stack level of the generated box in the current stacking context is 0. The box does not establish a new stacking context unless it is the root element.

In the following example, the stack levels of the boxes (named with their "id" attributes) are: "text2"=0, "image"=1, "text3"=2, and "text1"=3. The "text2" stack level is inherited from the root box. The others are specified with the 'z-index' property.


        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
        <HTML>
          <HEAD>
        
            <TITLE>Z-order positioning</TITLE>
            <STYLE type="text/css">
              .pile { 
                position: absolute; 
                left: 2in; 
                top: 2in; 
                width: 3in; 
                height: 3in; 
              }
            </STYLE>
          </HEAD>
          <BODY>
        
            <P>
              <IMG id="image" class="pile" 
                   src="butterfly.png" alt="A butterfly image"
                   style="z-index: 1">
        
            <DIV id="text1" class="pile" 
                 style="z-index: 3">
              This text will overlay the butterfly image.
            </DIV>
        
            <DIV id="text2">
              This text will be beneath everything.
            </DIV>
        
            <DIV id="text3" class="pile" 
                 style="z-index: 2">
              This text will underlay text1, but overlay the butterfly image
            </DIV>
          </BODY>
        </HTML>
        
        

This example demonstrates the notion of transparency. The default behavior of the background is to allow boxes behind it to be visible. In the example, each box transparently overlays the boxes below it. This behavior can be overridden by using one of the existing background properties.

14.1 Detailed stacking context

14.1.1 Definitions

Tree Order
Preorder depth-first traversal of the rendering tree, in logical (not visual) order for bidirectional content, after taking into account properties that move boxes around.
Element
In this description, "element" refers to actual elements, pseudo-elements, and anonymous boxes. Pseudo-elements and anonymous boxes are treated as descendants in the appropriate places. For example, an outside list marker comes before an adjoining 'before' box in the line box, which comes before the content of the box, and so forth.

14.1.2 Painting order

The bottom of the stack is the furthest from the user, the top of the stack is the nearest to the user:

A stacking context with four layers

Schematic diagram of a stacking context with four layers.

The stacking context background and most negative positioned stacking contexts are at the bottom of the stack, while the most positive positioned stacking contexts are at the top of the stack.

The canvas is transparent if contained within another, and given a UA-defined color if it is not. It is infinite in extent and contains the root element. Initially, the viewport is anchored with its top left corner at the canvas origin.

The painting order order for the descendants of an element generating a stacking context (see the 'z-index' property) is:

  1. If the element is a root element:
    1. background color of element over the entire canvas.
    2. background image of element, over the entire canvas, anchored at the origin that would be used if it was painted for the root element.
  2. If the element is a block, list-item, or other block equivalent:
    1. background color of element unless it is the root element.
    2. background image of element unless it is the root element.
    3. border of element.
    Otherwise, if the element is a block level table:
    1. table backgrounds (color then image) unless it is the root element.
    2. column group backgrounds (color then image).
    3. column backgrounds (color then image).
    4. row group backgrounds (color then image).
    5. row backgrounds (color then image).
    6. cell backgrounds (color then image).
    7. all table borders (in tree order for separated borders).
  3. Stacking contexts formed by positioned descendants with negative z-indices (excluding 0) in z-index order (most negative first) then tree order.
  4. For all its in-flow, non-positioned, block-level descendants in tree order: If the element is a block, list-item, or other block equivalent:
    1. background color of element.
    2. background image of element.
    3. border of element.
    Otherwise, the element is a table:
    1. table backgrounds (color then image).
    2. column group backgrounds (color then image).
    3. column backgrounds (color then image).
    4. row group backgrounds (color then image).
    5. row backgrounds (color then image).
    6. cell backgrounds (color then image).
    7. all table borders (in tree order for separated borders).
  5. All non-positioned floating descendants, in tree order. For each one of these, treat the element as if it created a new stacking context, but any positioned descendants and descendants which actually create a new stacking context should be considered part of the parent stacking context, not this new one.
  6. If the element is an inline element that generates a stacking context, then:
    1. For each line box that the element is in:
      1. Jump to 7.2.1 for the box(es) of the element in that line box (in tree order).
  7. Otherwise: first for the element, then for all its in-flow, non-positioned, block-level descendants in tree order:
    1. If the element is a block-level replaced element, then: the replaced content, atomically.
    2. Otherwise, for each line box of that element:
      1. For each box that is a child of that element, in that line box, in tree order:
        1. background color of element.
        2. background image of element
        3. border of element.
        4. For inline elements:
          1. For all the elements in-flow, non-positioned, inline-level children that are in this line box, and all runs of text inside the element that is on this line box, in tree order:
            1. If this is a run of text, then:
              1. any underlining affecting the text of the element, in tree order of the elements applying the underlining (such that the deepest element's underlining, if any, is painted topmost and the root element's underlining, if any, is drawn bottommost).
              2. any overlining affecting the text of the element, in tree order of the elements applying the overlining (such that the deepest element's overlining, if any, is painted topmost and the root element's overlining, if any, is drawn bottommost).
              3. the text
              4. any line-through affecting the text of the element, in tree order of the elements applying the line-through (such that the deepest element's line-through, if any, is painted topmost and the root element's line-through, if any, is drawn bottommost).
            2. Otherwise, jump to 7.2.1 for that element
          For inline-block and inline-table elements:
          1. For each one of these, treat the element as if it created a new stacking context, but any positioned descendants and descendants which actually create a new stacking context should be considered part of the parent stacking context, not this new one.
          For inline-level replaced elements:
          1. the replaced content, atomically.

        Note, some of the boxes may have been generated by line splitting or the Unicode bidirectional algorithm.

      2. Optionally, the outline of the element (see 10 below).
    3. Optionally, if the element is block-level, the outline of the element (see 10 below).
  8. All positioned descendants with 'z-index: auto' or 'z-index: 0', in tree order. For those with 'z-index: auto', treat the element as if it created a new stacking context, but any positioned descendants and descendants which actually create a new stacking context should be considered part of the parent stacking context, not this new one. For those with 'z-index: 0' treat the stacking context generated atomically.
  9. Stacking contexts formed by positioned descendants with z-indices greater than or equal to 1 in z-index order (smallest first) then tree order.
  10. Finally, implementations that do not draw outlines in steps above must draw outlines from this stacking context at this stage. (It is recommended to draw outlines in this step and not in the steps above.)

Need to account for new stacking context creation by opacity and transforms.


14.1.3 Notes

The background of the root element is only painted once, over the whole canvas.

While the backgrounds of bidirectional in lines are painted in tree order, they are positioned in visual order. Since the positioning of inline backgrounds is unspecified in CSS, the exact result of these two requirements is UA-defined. A future version of CSS may define this in more detail.

15. Conformance

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.

Conformance to CSS Backgrounds and Borders Level 3 is defined for three 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 CSS Backgrounds and Borders Level 3 if all of its declarations that use properties defined in this module have values that are valid according to the generic CSS grammar and the individual grammars of each property as given in this module.

A renderer is conformant to CSS Backgrounds and Borders Level 3 if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the properties defined by CSS Backgrounds and Borders Level 3 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 CSS Backgrounds and Borders Level 3 if it writes syntactically correct style sheets, according to the generic CSS grammar and the individual grammars of each property in this module.

15.1 Levels

This section is non-normative.

CSS has different levels of features, each a subset of the other. (See [CSSBEIJING] for a full explanation.) The lists below describe which features from this specification are in each level.

15.1.1 CSS Level 1

15.1.2 CSS Level 2

  • 'position'
  • 'top'
  • 'right'
  • 'bottom'
  • 'left'
  • 'clip'
  • 'z-index'

15.1.3 CSS Level 3

All features described in the CSS Positioning Module Level 3

15.2 CR exit criteria

As described in the W3C process document, a Candidate Recommendation (CR) is a specification that W3C recommends for use on the Web. The next stage is “Recommendation,” when the specification is sufficiently implemented.

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

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

A minimum of three months of the CR period must have elapsed. This is to ensure that enough time is given for any remaining major errors to be caught.

Features will be dropped if two or more interoperable implementations are not found by the end of the CR period.

Features may/will also be dropped if adequate/sufficient (by judgment of CSS WG) tests have not been produced for those feature(s) by the end of the CR period.

A. Acknowledgements

This spec would not have been possible without input and support from many helpful people. Special thanks to Bert Bos, Rossen Atanassov, Chris Jones, John Jansen. Thanks to Eliot Graff for editorial assistance.

B. References

B.1 Normative references

[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification.. W3C Recommendation. URL: http://www.w3.org/TR/CSS21/
[CSS3BOX]
Bert Bos. CSS basic box model. 9 August 2007. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2007/WD-css3-box-20070809
[CSSBEIJING]
Elika J. Etemad. Cascading Style Sheets (CSS) Snapshot 2007. 16 May 2008. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2008/WD-css-beijing-20080516
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt

B.2 Informative references

No informative references.