<pre class='metadata'>
Title: CSS Page Floats
TR: https://www.w3.org/TR/css-page-floats-3/
Status Text: Some of the features in this draft were previously published in <cite>CSS Generated Content for Paged Media Module</cite> [[CSS3GCPM]].
Shortname: css-page-floats
Level: 3
Group: csswg
Status: ED
Work Status: Exploring
ED: https://drafts.csswg.org/css-page-floats/
Previous Version: https://www.w3.org/TR/2015/WD-css-page-floats-3-20150915/
Editor: Johannes Wilm, Vivliostyle, johanneswilm@vivliostyle.com, w3cid 76051
Editor: Florian Rivoal, Invited Expert, https://florian.rivoal.net, w3cid 43241
Editor: Rachel Andrew, Invited Expert, https://rachelandrew.co.uk, w3cid 81117
Former Editor: H&aring;kon Wium Lie, Opera Software, howcome@opera.com
Abstract: This document describes floats that move to the top or bottom of content
Abstract: passages. This feature has traditionally been used in print
Abstract: publications in which figures and photos are moved to the top or bottom
Abstract: of columns or pages, along with their captions.
Abstract: This draft describes how to achieve this effects for floats within pages,
Abstract: columns, regions and elements.
Ignored Terms: near, 3em, intrude, top-corner, bottom-corner, left, right, both, element, none, floats, inline, max-width, max-height
</pre>


<h2 id="overview">Overview</h2>

  <em>This section is not normative.</em>

  This specification adds new keywords on the 'float' property.

  This document allows to specify whether a <a>float</a> floats to align with a
  <a>float reference</a> inline box, column, region or page. In the case of floats
  with a reference <a>fragmentation container</a>, placement can be deferred to a
  subsequent <a>fragmentation container</a> with the <em>float-defer</em> properties.

  New values on the 'clear' property add further ways of refining layouts.

  The way contents wrap around floats can be controlled by changing the value of
  the 'wrap-flow' property which initially is set to 'both' for page floats.

  <p class="issue">
    Page floats as defined here work with different types of fragmentation types
    (columns, regions, pages) as well as container elements. The specification
    is no longer specific to print or to pages.
    At the same time, inline floats and page floats differ in many ways, and it may
    (or may not) be a good idea to separate the two entirely.
    Therefore, the name <em>CSS Page Floats</em> should probably be replaced with
    a more appropriate name.
  </div>


<h2 id="terms">
Terminology</h2>

  <dl export>
    <dt><dfn>Float</dfn>
    <dd>
      An element which has float set to something else than none.
    <dt><dfn>Inline float</dfn>
    <dd>
      A float which has float set to inline.
    <dt><dfn>Page float</dfn>
    <dd>
      A float which has float set to something else than inline or none.
    <dt><dfn>Float block formatting context</dfn>
    <dd>
      The block formatting context which is generated by a float and which contains
      its contents.
    <dt><dfn>Float anchor</dfn>
    <dd>
      The float anchor is the point in the flow where the float had appeared had
      it not been a float and instead had been an empty inline element with no
      margins, borders or padding.
    <dt><dfn>Float containing block formatting context</dfn>
    <dd>
      The block formatting context inside of which an float is embedded.
    <dt><dfn>Initial float reference</dfn>
      <dd>
        The entity to which the float is aligned initially, before float
        placement takes place.
    <dt><dfn>Float reference</dfn>
    <dd>
      The entity to which the float is aligned.
    <dt><dfn>Not overlapping</dfn>
    <dd>
      Two elements are not overlapping if the margin box of one element is not
      overlapping the margin box of the other element.
  </dl>

<h2 id="floating">
Floating to the inline-start/inline-end and block-start/block-end</h2>

  <p>
    Floating elements can float to the start or end of the <a>float anchor</a>'s line or
    block, specified by the 'float' attribute. The floats are aligning to the start
    or end of a <a>float reference</a>, specified by the 'float-reference' attribute. The
    <a>float reference</a> can be the <a>float anchor</a>'s line box, column, region or page.


  <h3 id="float-reference-property">The 'float-reference' property</h3>

  <pre class="propdef">
    Name: float-reference
    Value: inline | column | region | page
    Initial: inline
    Applies to: all elements.
    Inherited: no
    Percentages: N/A
    Computed value: specified keyword
    Animation type: discrete
  </pre>

  <dl dfn-for="float-reference" dfn-type="value">

    <dt><dfn>inline</dfn>
    <dd>
      The <a>float reference</a> is the line box of the <a>float anchor</a>.

      The <a>float containing block formatting context</a> is the same as that of the
      <a>float anchor</a>.

      The float is an <a>inline float</a>.

    <dt><dfn>column</dfn>
    <dd>
      The <a>float reference</a> is the column in a multi column environment in
      which the <a>float anchor</a> is placed. If the <a>float anchor</a> is not
      inside a column, the <a>float reference</a> is the line box of the <a>float
      anchor</a>.

      The <a>float containing block formatting context</a> is a new block formatting
      context with the same dimensions and placement as the <a>float reference</a>.

      The float is a <a>page float</a>.

    <dt><dfn>region</dfn>
    <dd>
      The <a>float reference</a> is the region in a region-chain within which the
      <a>float anchor</a> is placed. If the <a>float anchor</a> is not inside a
      region, the <a>float reference</a> is the line box of the <a>float
      anchor</a>.

      The <a>float containing block formatting context</a> is a new block formatting
      context with the same dimensions and placement as the <a>float reference</a>.

      The float is a <a>page float</a>.

    <dt><dfn>page</dfn>
    <dd>
      The <a>float reference</a> of the float is the page within which the <a>float
      anchor</a> is placed. If the <a>float anchor</a> is not inside a page, the
      <a>float reference</a> is the line box of the <a>float anchor</a>.

      The <a>float containing block formatting context</a> is a new block formatting
      context with the same dimensions and placement as the <a>float reference</a>.

      The float is a <a>page float</a>.
  </dl>

  <div class="issue">
    The <a>float containing block formatting context</a> having the same dimensions
    as the <a>float reference</a> means that all floats that are not inline floats
    cannot move outside of their float references. Is this wanted?
  </div>

  <div class="issue">
    It is not possible to specify a block element which element to use as the
    reference element. This has been requested.

    Maybe something like:

    <pre><code>
&lt;style>
.float {
float-reference: float-container;
}

#container {
float-container: true;
}
&lt;/style>

&lt;div id="container">
&lt;p>First paragraph&lt;span class="float">FLOAT&lt;/span>&lt;/p>

&lt;p>Second paragraph
&lt;span class="inline-block">[&lt;span class="float">FLOAT&lt;/span>] &lt;/span>
And some more text&lt;/p>
&lt;/div>
    </code></pre>

    This should float both floats with reference to the &lt;div id="container">
    element, rather than the &lt;P> and inline &lt;SPAN> elements.

  </div>

<h3 id="float-property">The 'float' property</h3>

<pre class="propdef">
  Name: float
  Value: block-start | block-end | inline-start | inline-end | snap-block | <<snap-block()>> | snap-inline | <<snap-inline()>> | left | right | top | bottom | none
  Initial: none
  Applies to: all elements.
  Inherited: no
  Percentages: N/A
  Computed value: as specified
  Animation type: by computed value type
</pre>

<dl dfn-for="float" dfn-type="value">

  <dt><dfn>inline-start</dfn>
  <dd>
    If the <a>float reference</a> is a line box, the element generates a box that
    is floated to the line-start outer edge of the <a>float reference</a> and
    content flows on the line-end side of the box.

    If the <a>float reference</a> is not a line box, the element generates a box
    that is floated to the line-start and block-start outer edges of the <a>float
    reference</a>.

  <dt><dfn>inline-end</dfn>
  <dd>
    If the <a>float reference</a> is a line box, the element generates a box that
    is floated to the line-ebd  outer edge of the <a>float reference</a> and
    content flows on the line-start side of the box.

    If the <a>float reference</a> is not a line box, the element generates a box
    that is floated to the line-end and block-end outer edges of the <a>float
    reference</a>.

  <dt><dfn>block-start</dfn>
  <dd>
    If the <a>float reference</a> is a line box, block-start behaves like
    inline-start.

    If the <a>float reference</a> is not a line box, the element generates a box
    that is floated to the block-start and line-start outer edges of the <a>float
    reference</a>.

    The initial value of the <a>max-width</a> or <a>max-height</a> property that
    refers to the <a>inline size</a> of the float is '100%'.

    Content flows on the block-end side of the box.

  <dt><dfn>block-end</dfn>
  <dd>
    If the <a>float reference</a> is a line box, block-end behaves like inline-end.

    If the <a>float reference</a> is not a line box, the element generates a box
    that is floated to the block-end and line-end outer edges of the <a>float
    reference</a>.

    The initial value of the <a>max-width</a> or <a>max-height</a> property that
    refers to the <a>inline size</a> of the float is '100%'.

    Content flows on the block-start side of the box.

  <dt><dfn>left</dfn>

  <dd>
    If the <a>float reference</a> is a line box, behaves like inline-start or
    inline-end, whichever corresponds to line-left for the float reference.

    Otherwise, behaves like block-end, inline-start or inline-end depending on
    the float containing block’s 'direction' and 'writing-mode'.

  <dt><dfn>right</dfn>

  <dd>
    If the <a>float reference</a> is a line box, behaves like inline-start or
    inline-end, whichever corresponds to line-right for the float reference.

    Otherwise, behaves like block-start, inline-start or inline-end depending on
    the float containing block’s 'direction' and 'writing-mode'.

  <dt><dfn>top</dfn>

  <dd>
    Behave like block-start or inline-start depending on the float
    containing block’s 'direction' and 'writing-mode'.

  <dt><dfn>bottom</dfn>

  <dd>
    Behave like block-end or inline-end depending on the float
    containing block’s 'direction' and 'writing-mode'.

  <dt><dfn function>snap-block()</dfn>
  <dd>
      The ''snap-block()'' function is defined as:

      <pre class='prod'>
        snap-block() = snap-block( <<length>> , [ start | end | near ]? )
      </pre>

      Has no effect if the element is an <a>inline float</a>.

      If the element is a <a>page float</a>, it makes the element float to the
      start or the end of the block if it naturally appears within a certain
      distance from either one. The length value(s) specifies the maximum
      distance from the start/end that an element must be within in order to be
      floated; one length value specifies the distance from both the start and
      the end, two length values specify the distance from the start and end,
      respectively.

      The optional keyword value specifies where the element is floated: start,
      end, or the nearest of the two. The initial value is 'near'. If 'near'
      is in effect and the element is within the specified distance both from
      the start and the end, end wins.

  <dt><dfn>snap-block</dfn>
  <dd>Behaves as <code>snap-block(2em, near)</code>

  <dt><dfn function>snap-inline()</dfn>
  <dd>
      The ''snap-inline()'' function is defined as:

      <pre class='prod'>
        snap-inline() = snap-inline( <<length>> , [ left | right | near ]? )
      </pre>

      Has no effect if the element is an <a>inline float</a>.

      If the element is a <a>page float</a>, it makes the element float to the
      line start or line end if it naturally appears within a certain distance
      from the start or end of the line. The length value(s) specifies the
      maximum distance from the start/end that an element must be within in
      order to be floated; one length value specifies the distance from both the
      start and the end, two length values specify the distance from the start
      and end, respectively.

      The optional keyword value specifies where the element is floated: line
      start, line end, or the nearest of the two. The initial value is 'near'.
      If 'near' is in effect and the element is within the specified distance
      both from the start and the end, end wins.


  <dt><dfn>snap-inline</dfn>
  <dd>same as <code>snap-inline(2em, near)</code>

  <dt><dfn>none</dfn>
  <dd>The box is not floated.

</dl>

<div class="issue">
  There is currently no way to float into a combination of directions (top right,
  right top, left bottom, bottom left, etc.).
</div>


<div class="example">
  Float figure to top of reference column:

<pre>
.figure { float-reference: column; float: top }
</pre>

  <img alt="sample rendering" src="images/7.png">
</div>

<div class="example">
  In this example a block-start float that does not fill the entire <a>inline size</a>
  of the float reference is placed at the start of the block and line.

<pre>
.figure { float-reference: column; float: block-start; width: 50% }
</pre>

  <img alt="sample rendering" src="images/block_line_start.png">
</div>

<div class="example">
  In this example, a figure naturally appears close to a column break. There is
  not enough space for the figure in the first column, and it is therefore placed
  in the second column, leaving white space at the bottom of the first column.

  <img alt="sample rendering" src="images/23.png">

  To avoid the white space, the image can be floated to the nearest edge (in the
  block direction):

<pre>
.figure { float-reference: column; float: snap-block }
</pre>

  In this example, the figure is already at the nearest edge, so it does not
  move. However, floats allow subsequent content to be displayed before the
  float and the white space can therefore be filled:

  <img alt="sample rendering" src="images/7.png">
</div>

<div class="example">

  In this example, two figures naturally appear in the text flow:

  <img alt="sample rendering" src="images/20.png">

  A typographer would typically try to avoid single lines of text above/below
  figures, which can be achieved with:

<pre>
div.figure { float-reference: column; float: snap-block(1.5em) }
</pre>

  The length value specifies the reach of the snap function; in this example the
  second figure is affected, but not the first.
</div>

<div class="example">

  In this example, two figures naturally appear in the text flow:

  <img alt="sample rendering" src="images/20.png">

  To make the figures snap to the nearest edges, this code can be applied:

<pre>
div.figure { float-reference: column; float: snap-block(2.5em) }
</pre>

  The resultant rendering is:

  <img alt="sample rendering" src="images/22.png">

</div>


<div class="example">
  In this example, tables will snap to the top/bottom if the top/bottom of the
  border box is closer than '3em' from the top/bottom of the float-reference
  which is a block element.

<pre>
table { float: snap }
table { float: snap-block(3em) }
table { float: snap-block(3em, bottom) }
table { float: snap-block(3em 2em, bottom) }
</pre>

</div>

  <div class="note">
    More examples with regions as <a>float reference</a>s needed.
  </div>


<h2 id="clearing_page_floats">
The 'clear' property</h2>

  <pre class="propdef">
    Name: clear
    Value: inline-start | inline-end | block-start | block-end | left | right | top | bottom | none
    Initial: none
    Applies to: block-level elements, floats, regions, pages
    Inherited: no
    Percentages: N/A
    Computed value: specified keyword
    Animation type: discrete
  </pre>

  To prevent stacking of floats, the 'clear' property can be used:

  <dl dfn-for="clear" dfn-type="value">

    <dt><dfn>inline-start</dfn>
    <dd>
      If applied to an inline float, requires that the block-start outer edge of
      the box comes after the block-end outer edge of any inline-start-floats
      with an inline-start-float-reference that resulted from elements earlier
      in the source document.

      If applied to a <a>page float</a>, the <a>float reference</a> in which the
      page float is placed will be seen as full when determining whether it can
      host subsequent page floats that float in the inline-start direction.

    <dt><dfn>inline-end</dfn>
    <dd>
      If applied to a block-level element or an <a>inline float</a>, requires
      that the block-start outer edge of the box comes after the block-end outer
      edge of any inline-end-floats with an inline-end-float-reference that
      resulted from elements earlier in the source document.

      If applied to a <a>page float</a>, the <a>float reference</a> in which the
      page float is placed will be seen as full when determining whether it can
      host subsequent page floats that float in the inline-end direction.


    <dt><dfn>block-start</dfn>
    <dd>
      If applied to a block-level element or an <a>inline float</a>, behaves like
      inline-start.

      If applied to a page float, the <a>float reference</a> in which the page
      float is placed will be seen as full when determining whether it can host
      subsequent page floats that float in the block-start direction.

    <dt><dfn>block-end</dfn>

    <dd>
      If applied to a block-level element or an <a>inline float</a>, behaves
      like inline-end.

      If applied to a page float, the <a>float reference</a> in which the page float
      is placed will be seen as full when determining whether it can host
      subsequent page floats that float in the block-end direction.

    <dt><dfn>left</dfn>

    <dd>
      Behave like block-end, inline-start or inline-end depending on the float
      containing block’s 'direction' and 'writing-mode'.

    <dt><dfn>right</dfn>

    <dd>
      Behave like block-start, inline-start or inline-end depending on the float
      containing block’s 'direction' and 'writing-mode'.

    <dt><dfn>top</dfn>

    <dd>
      Behave like block-start or inline-start depending on the float
      containing block’s 'direction' and 'writing-mode'.

    <dt><dfn>bottom</dfn>

    <dd>
      Behave like block-end or inline-end depending on the float
      containing block’s 'direction' and 'writing-mode'.

    <dt><dfn>both-inline</dfn>

    <dd>
      Behave like inline-start and inline-end.

    <dt><dfn>both-block</dfn>

    <dd>
      Behave like block-start and block-end.

    <dt><dfn>both</dfn>

    <dd>
      Behave like both-inline.

    <dt><dfn>all</dfn>

    <dd>
      Behave like both-block and both-inline.

  </dl>


  <div class="example">
    In this example, the two figures may appear in the same column:

<pre>
.figure { float-reference: column; float: bottom; clear: none }

&lt;div class=figure>&lt;/div>
&lt;div class=figure>&lt;/div>
</pre>
    <img alt="sample rendering" src="images/16.png">
  </div>

  <div class="example">
    In this example, the two figures will appear in different columns:

<pre>
.figure { float-reference: column; float: bottom; clear: bottom }

&lt;div class=figure>&lt;/div>
&lt;div class=figure>&lt;/div>
</pre>

    <img alt="sample rendering" src="images/17.png">
  </div>


  <div class="example">
    In this example, the two figures may appear at the bottom of the same column
    due to clearing only at the top:

<pre>
.figure { float-reference: column; float: bottom; clear: top }

&lt;div class=figure>&lt;/div>
&lt;div class=figure>&lt;/div>
</pre>

    <img alt="sample rendering" src="images/16.png">
  </div>

  <div class="example">
    In this example, the two figures will appear in different columns due to
    clearing at the bottom:

<pre>
.figure { float-reference: column; float: bottom; clear: bottom }

&lt;div class=figure>&lt;/div>
&lt;div class=figure>&lt;/div>
</pre>

    <img alt="sample rendering" src="images/17.png">
  </div>


  <div class="example">
    In this example, the two figures end up the top corner of two different
    pages:

<pre>
.figure { float-reference: page; float: top; clear: top }

&lt;div class=figure>&lt;/div>
&lt;div class=figure>&lt;/div>
</pre>

  </div>

  <div class="example">
    In this example, the two figures request different positions, and they may
    therefore end up in the same column:

<pre>
.figure.one { float-reference: column; float: top; clear: top }
.figure.two { float-reference: column; float: bottom; clear: bottom }

&lt;div class="figure one">&lt;/div>
&lt;div class="figure two">&lt;/div>
</pre>

  </div>

<h2 id="deferring_floats">Deferring page floats</h2>

  Users can influence the placement of a <a>page float</a> by deferring them to
  another <a>fragmentation container</a> than where the <a>float anchor</a> is
  placed.

  A float that is an <a>inline float</a> cannot be deferred.

  Float deferring assigns an <a>initial float reference</a>, yet float stacking
  can lead page floats being moved to a subsequent <a>fragmentation container</a>
  if their <a>initial float reference</a> lacks the space to host them.

  The 'float-defer' property is introduced to control deferring floats:

  <h3 id="float-defer-property">The 'float-defer' property</h3>

    <pre class="propdef">
      Name: float-defer
      Value: &lt;integer> | last | none
      Initial: none
      Applies to: floats
      Inherited: no
      Percentages: N/A
      Computed value: specified keyword or integer
      Animation type: discrete
    </pre>


    This property specifies whether the <a>initial float reference</a> of a <a>page
    float</a> is the <a>fragmentation container</a> in which the <a>float anchor</a>
    is placed after previous page floats have been placed, or in another one.

    This property is ignored if the element is an <a>inline float</a>.

    Values are:

    <dl>
      <dt>none
      <dd>The <a>initial float reference</a> is the <a>fragmentation container</a> in which the
      <a>float anchor</a> is placed after all previous page floats have been placed.

      <dt>&lt;integer>
      <dd>
        A positive integer value indicates that the <a>initial float reference</a> of
        the page float should be Nth <a>fragmentation container</a> of the `fragmentation
        flow`, where N is the value of the `float-defer` property plus the order
        number of the <a>fragmentation container</a> in which the <a>float anchor</a> is placed
        after all previous page floats have been placed within the given
        <a>fragmentation context</a>. If N is larger than the order number of the last
        <a>fragmentation container</a> within the given <a>fragmentation context</a> at the time of
        assignment, then N is the order number of the last <a>fragmentation container</a>
        within the given <a>fragmentation context</a>.

        A negative integer value indicates that the <a>initial float reference</a> of
        the page float should be a <a>fragmentation container</a> of the
        <a>fragmentation context</a>, counting backward from the end, so that -1
        is the last <a>fragmentation container</a>, -2 is the next-to-last, etc. .
        In the case of a negative integer value, the <a>initial float reference</a> is the
        Nth <a>fragmentation container</a> of the <a>fragmentation context</a>, where N is 1
        plus the order number of the last <a>fragmentation container</a> within the given
        <a>fragmentation context</a> after all previous page floats have been placed plus
        the value of the `float-defer` property.

        Zero is the same as `none`.

        If the value of the `float-defer` property would cause the <a>initial float
        reference</a> to be an inexistent <a>fragmentation container</a>, the property
        is interpreted as if it were zero.

        <p class="note">
          Negative float-defer values put the initial float reference a certain number
          to be a certain amount of fragmentation containers from the last fragmentation
          container at the time of of the placement. Subsequent page float stacking
          can mean that a page float is being placed in a later fragmentation container
          (a page float with float-defer set to -3 can end up being placed in the
          last fragmentation container), and later page floats may mean that new
          fragmentation containers are added, so that the a fragmentation container
          that previously was Nth last fragmentation container within a fragmentation
          context now is the N+Xth last. Additional fragmentation container(s) that
          are added after the page float was placed, will not cause the page float
          to be moved.

      <dt>last
      <dd>
        The <a>initial float reference</a> is the last <a>fragmentation container</a> within
        the given <a>fragmentation context</a> after all previous page floats have been
        placed.

    </dl>

    <div class="example">
      Float figure to the top of the region that follows the region in which
      the <a>float anchor</a> is placed:

<pre>
.figure { float-reference: region }
.figure { float: top }
.figure { float-defer: 1 }
</pre>

    </div>

    <div class="example">
      Float figure to the top of the next-to-last column:

<pre>
.figure { float-reference: column; float: top; float-defer: -2 }
</pre>

      <img alt="sample rendering" src="images/7.png">
    </div>

    <div class="example">
      Float figure to the top of the last page:

<pre>
.figure { float-reference: page }
.figure { float: top }
.figure { float-defer: -1 }
</pre>
    </div>

    <div class="example">
      Float figure to the top of the last column:

<pre>
.figure { float-reference: column }
.figure { float: top }
.figure { float-defer: last }
</pre>

    </div>

    <div class="example">
      Float figure to top of the last column:

<pre>
.figure { float-reference: column; float: top; float-defer: last }
</pre>

<img alt="sample rendering" src="images/6.png">
    </div>

<h2 id="wrapping-around-page-floats">Wrapping around page floats</h2>

  Page floats have their 'wrap-flow' property set to 'both' initially and are
  treated like exclusions. This specification does not make any further
  specification about wrapping contents around page floats.

  <div class="issue">
    Should the 'wrap-flow' really be set to both, or should the flow be restricted
    to only be on one side?
  </div>

<h2 id="the-float_offset-property">The 'float-offset' property</h2>

  <pre class="propdef">
    Name: float-offset
    Value: <<length>> | <<percentage>>
    Initial: 0
    Applies to: floats
    Inherited: no
    Percentages: see prose
    Computed value: computed <<length-percentage>> value
    Animation type: by computed value type
  </pre>

  This property pushes a <a>page float</a> in direction opposite of the where it has been
  floated with 'float'.

  If the element is an <a>inline float</a>, this property is ignored.

  This property can only influence a <a>page float</a> along an axis along which
  it has been floated.

  <dl>
    <dt><<percentage>></dt>
    <dd>
      Percentage values are computed according to this formula:

    <pre>
      (containing-block-width - float-width) * percentage
      (containing-block-height - float-height) * percentage
    </pre>
    </dd>
  </dl>

  <div class="example">

<pre>
img {
  float-reference: column;
  float: left;
  float-offset: 2em;
}
</pre>

    In this example, the image is floated to the left. Therefore, 'float-offset'
    may only push the element to the right.

  </div>


  <div class="example">

<pre>
img {
  float-reference: column;
  float: right;
  float-offset: 5px;
}
</pre>

    <img alt="sample rendering" src="images/14.png">

  </div>

  <!--div class="example">
    Pull quotes are often centered in a column. In this example, the pull quote is
    floated to the right, and then pushed back into the center.

    <img alt="sample rendering" src="images/region_pullquote.png">

<pre>
.pullquote {
  float-reference: region;
  float: right;
  float-offset: 50%; /* 50% centers the box */
}
</pre>

  </div-->


<h2 id="page-float-placement">Page float placement</h2>

  The order of page floats placement is determined by the following rules:

  <ol>
    <li>
      All page floats with 'float-reference' set to `page` are placed, in
      document order, before those with 'float-reference' set to `region` and
      `column`.
    <li>
      Thereafter, page floats with 'float-reference' set to `column` and `region`
      are placed in document order.
    </li>
  </ol>

  The placement of a single page float is a process that has to be terminated
  entirely before the placement of a subsequent page float can be initiated. The
  placement process consists of the following steps:

  <ol>

    <li>Determine the <a>initial float reference</a> by considering the
    <a>fragmentation container</a> in which the <a>float anchor</a> is placed and
    the `float-defer` property of the page float. The <a>float reference</a> is
    initially set to be the same as the <a>initial float reference</a>.</li>

    <li>Determine if the given <a>float reference</a> has enough space or can be
    expanded to host the page float, if the rules of <a href="#float-stacking">
    float stacking</a> and <a href="#float-reference-growth">float reference
    growth</a> are to be followed. If this is not the case, and the <a>float
    reference</a> is not the last <a>fragmentation container</a> within the given
    <a>fragmentation context</a>, then make the following <a>fragmentation
    container</a> within the given <a>fragmentation context</a> the <a>float
    reference</a>. Repeat this step until the <a>float reference</a> can be
    expanded enough to host the page float or it is the last <a>fragmentation
    container</a> within the given <a>fragmentation context</a>.</li>

    <li>If the <a>float reference</a> is the last <a>fragmentation container</a> within
    the given <a>fragmentation context</a>, and it has not enough space and cannot be
    expanded to host the page float, then do the following:</li>

    <ol>
      <li>If the <a>fragmentation context</a> allows for the addition of another
      <a>fragmentation container</a> and an additional <a>fragmentation container</a>
      would have the needed size to host the page float, a new <a>fragmentation
      container</a> is added to the end of the <a>fragmentation context</a>. The
      <a>float reference</a> is set the newly created <a>fragmentation
      container</a>.</li>

      <li>Otherwise, if the <a>fragmentation container</a> is a region, then the
      'regionOverset` attribute of the <a>fragmentation container</a> is set to
      `overset`.
    </ol>

    <li>The page float is placed in the <a>float reference</a> according to the rules
    of 'float stacking' and 'float reference growth'.</li>

  </ol>

<h3 id="float-reference-growth">Float reference growth</h3>

Float references can grow up to the their `max-height` and `max-width` or their
`available size`, whichever is the lowest, in order to accommodate page floats.

<h3 id="float-stacking">Rules for page float stacking</h3>

Page floats are stacked within a given <a>float reference</a> in the order of their
placement and in the direction of the inline- and flow-directions of the
<a>fragmentation context</a> while <a>not overlapping</a> with any other page
floats with the same <a>float reference</a> and by keeping a distance N between
the page float's margin edge and the padding edge of the <a>float reference</a>
as well as between the page float's margin edge and the margin edge of the last
previously placed page float with the same <a>float reference</a> and the same
'float' value, where N is the 'float-offset' value of the page float.

For the purpose of calculating whether enough space is available for a page floats
within the <a>float reference</a>, it is assumed that the page floats in the block
directions fill the entire line size of the <a>float reference</a> and page floats
in the inline direction fill the entire block size of the <a>float reference</a>.

For the purpose of placement, page floats in the block-start direction are also
placed at the inline-start edge of the float reference and vice versa, and page
floats in the block-end direction are placed at the inline-end edge of the float
reference and vice versa.

If the page float has a defined 'clear'-value, then the <a>float reference</a> in
which the page float is placed is closed for all subsequent page floats that
floating in the direction specified by the 'clear'-value.

<p class="issue">
  We can effectively currently float to two corners: inline-start/block-start and
  inline-end/block-end. We should augment this with the option to have a secondary
  float direction to allow basic 2D floating.


<h2 id="relation_to_absolutely_positioned_exclusions">
Floats and absolutely positioned exclusions</h2>

Floats and absolutely positioned exclusions share some common traits, but in the
case of inline floats they are not the same. Floats that are not inline floats
should behave the same as absolutely positioned exclusions with positions and
sizes manually set to prevent overlap between floats and to prevent floats from
moving beyond the edges of the float reference, with the float reference being
grown as much as needed up to its maximum extend to accommodate all containing
floats.

<h3 id="inline_floats_and_absolutely_positioned_exclusions">
Differences between inline floats and absolutely positioned elements</h3>

  <em>This section is not normative.</em>

  <p>
    Inline floats and absolutely positioned elements are both out-of-flow elements.
    Absolutely positioned elements that are also exclusions can imitate many of
    the features of floats.

  <p>
    However, in the case of inline floats, the block formatting context that
    contains them (the <a>float containing block formatting context</a>) is
    required to include the area occupied by the float, which is not a requirement
    for absolutely positioned elements.

  <div class="example">
    An inline float inside a <a>float containing block formatting context</a> given
    by a display-inline-block element. The element, which has a green border, is
    expanded to include the brown float.

<pre><code>
&lt;style>
.float {
  float: left;
  margin: 5px;
}
.border {
    border: 3px solid black;
    margin: 5px;
}
#outer {
    border: 1px solid green;
    display: inline-block;
}
canvas {
    background-color: brown;
}
p {
  margin: 5px;
}
&lt;/style>
&lt;div id="outer">
    &lt;p class="border">
        &lt;span class="float border">
            &lt;canvas width="100" height="100"/>
        &lt;/span>
        First paragraph.
    &lt;/p>
    &lt;p class="border">
        Second paragraph and some more text.
    &lt;/p>
&lt;/div>
</code></pre>

    <img alt="sample rendering" src="images/float_containing_context.png">

    In comparison, the below is the same HTML, but the float is replaced by an
    absolutely positioned element that is also an exclusion. The <a>float
    containing block formatting context</a> is still given by a
    display-inline-block element. However, the element, marked by a green border,
    does not expand to include the brown, absolutely positioned element.

<pre><code>
&lt;style>
.float {
    position: absolute;
    top: 8px;
    left: 8px;
    wrap-flow: both;
}
.border {
    border: 3px solid black;
    margin: 5px;
}
#outer {
    border: 1px solid green;
    display: inline-block;
    position: relative;
}
canvas {
    background-color: brown;
}
&lt;/style>
&lt;div id="outer">
    &lt;p class="border">
        &lt;span class="float border">
            &lt;canvas width="100" height="100"/>
        &lt;/span>
        First paragraph.
    &lt;/p>
    &lt;p class="border">
        Second paragraph and some more text.
    &lt;/p>
&lt;/div>
</code></pre>

    <img alt="sample rendering" src="images/positioned_containing_context.png">

  </div>

<h2 id="overconstrained-page-floats">Overconstrained floats</h2>

  In many cases, the specified values on these properties cannot be honored.

  <div class="example">

    The number of columns is limited, and high values therefore cannot be honored:

<pre>
.figure { float-reference: column; float: top; float-defer: 1000 }
</pre>

  </div>

  <div class="example">
    A narrow screen may only have room for one column, in which case this request
    cannot be honored:

<pre>
.figure { float-reference: column; float: top; float-defer: -5 }
</pre>

  </div>

  <div class="example">
    In long documents, all content cannot fit on the last page, and this rule
    therefore cannot be honored:

<pre>
p { float-reference: page; float: top; float-defer: last }
</pre>

  </div>

  Floats are processed in the order they appear in the source. However, the
  visual order of floats may not be the same as the source order.

  <div class="example">
    Consider this code:

<pre>
.one { float-reference: page; float: top; float-defer: last }
.two { float-reference: column; float: top; clear: column }

&lt;div class=one>&lt;/div>
&lt;div class=two>&lt;/div>
</pre>

    In this example, the first element requests to appear on the last page, while
    the second element requests to appear in the natural column. If the natural
    column of the second element appears on a page before the last page, the second
    element will appear visually before the first.

  </div>


  <div class="example">

    Consider this code:

<pre>
.one { float-reference: page; float: top; float-defer: last }
.two { float-reference: page; float: top; clear: page; }

&lt;div class=one>&lt;/div>
&lt;div class=two>&lt;/div>
</pre>

    If all content can fit on one page, the first page will also be the last page.
    The first element is processed first and is placed on top of the first page.
    Then the second element is processed. It requests a clear top, something which is
    not possible on the first page. Therefore, a second page is created and the
    first element is moved there. Even if the first element requests to be on the
    last page, it will not appear there.

  </div>

  When resolving over-constrained layouts, the order of importance for defined
  goals are:

  <ol>
    <li>honor 'clear: top/bottom'
    <li>honor 'float-defer'
    <li>honor 'float: top/bottom'
    <li>display all content (as described by other CSS properties)
    <li>keep the number of pages to a minimum
  </ol>

<h2 class="no-num" id="acks">
Acknowledgments</h2>

  This specification is made possible by input from
  Rossen Atanassov,
  Tab Atkins Jr.,
  David Baron,
  Lars Erik Bolstad,
  Bert Bos,
  Mike Bremford,
  Dave Cramer,
  Michael Day,
  Werner Donn&eacute;,
  Brady Duga,
  James Elmore,
  Elika Etemad,
  Michel Fortin,
  Daniel Glazman,
  Melinda Grant,
  Ian Hickson,
  Laurens Holst,
  Brad Kemper,
  Toru Kawakubo,
  Rune Lillesveen,
  Peter Linss,
  Cameron McCormack,
  Paul E. Merrell,
  Del Merritt,
  Markus Mielke,
  Kelly Miller,
  Alex Mogilevsky,
  Peter Moulder,
  Shinyu Murakami,
  Michel Onoff,
  Anton Prowse,
  Liam R E Quin,
  Jacob Grundtvig Refstrup,
  Florian Rivoal,
  Christian Roth,
  Allan Sandfeld Jensen,
  Simon Sapin,
  Alan Stearns,
  Morten Stenshorne,
  Philip Taylor,
  Ian Tindale,
  Ladd Van Tol,
  Lea Verou,
  Tarquin (Mark) Wilton-Jones,
  Steve Zilles,
  Tantek &#xC7;elik
  and the CSS Working Group members.
