<pre class='metadata'>
Title: CSS Generated Content for Paged Media Module Level 3
Status: ED
Prepare for TR: no
Work Status: Exploring
Shortname: css-gcpm
Level: 3
Group: csswg
ED: https://drafts.csswg.org/css-gcpm/
TR: https://www.w3.org/TR/css-gcpm-3/
Editor: Mike Bremford, BFO, mike@bfo.com, w3cid 118053
Editor: Rachel Andrew, Google, rachelandrew@google.com, w3cid 81117
Former Editor: Dave Cramer, Hachette Livre, dave.cramer@hbgusa.com, w3cid 65283
Former Editor: Håkon Wium Lie, Opera Software
Link defaults: css-content-3 (property) counter-increment, css-content-3 (property) counter-reset, css21 (property) string, css2 (property) max-height
Abstract: Books and other paged media often use special techniques to display information. Content may be moved to or generated for special areas of the page, such as running heads or footnotes. Generated content within pages, such as tab leaders or cross-references, helps readers navigate within and between pages.
Ignored Terms:


</pre>

<pre class="link-defaults">
	spec:css-content-3; type:function; text:string()
	spec:css-content-3; type:property; text:bookmark-label
	spec:css-content-3; type:property; text:bookmark-level
</pre>

<h2 class="no-num" id="introduction">
	Introduction
</h2>


Paged media have many <a href="http://w3c.github.io/dpub-pagination/index.html">special requirements</a> for the display of document content, which have evolved over the long history of printed books. Running headers and footers function as aids to navigation. Notes may appear at the bottom of the page, as footnotes. The properties of pages themselves may change based on their content or position in the document. Leaders visually connect related content. Cross-references may require generated text. Some paged media formats such as PDF use bookmarks for navigation.

This module defines new properties and values, so that authors may bring these techniques to paged media.

<h3 id="values">
Value Definitions</h3>

This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS21]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values &amp; Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.

In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> as their property value.
For readability they have not been repeated explicitly.

<!--page areas-->
<h2 id="running-headers-and-footers">
	Running headers and footers
</h2>
[[CSS3PAGE]] describes the sixteen page margin boxes which can be used for running headers and footers, but does not describe a mechanism for inserting content in those boxes. This module provides two methods for doing so. <dfn lt="named string">Named strings</dfn> copy text for reuse in margin boxes. <dfn id="running-elements0">Running elements</dfn> move elements (complete with style and structure) from the document to margin boxes.
<h3 id="named-strings">
	Named strings
</h3>
The 'string-set' property copies the text content of an element into a <a>named string</a>, which functions as a variable. The text content of this named string can be retrieved using the ''string()'' function. Since these variables may change on a given page, an optional second value for the ''string()'' function allows authors to choose which value on a page is used.
<h4 id="setting-named-strings-the-string-set-pro">
	The string-set property
</h4>

<pre class="propdef">
Name: string-set
Value: [ <<custom-ident>> <<content-list>> ]# | none
Initial: none
Applies to: all elements, but not pseudo-elements
Inherited: no
Percentages: N/A
Computed value: specified value
Animation type: discrete
</pre>

	<p class=all-media>User agents are expected to support this property on all media, including non-visual ones.</p>

The 'string-set' property contains one or more pairs, each consisting of an custom identifier (the name of the <a>named string</a>) followed by a <<content-list>> describing how to construct the value of the named string.


<<content-list>> expands to one or more of the following values, in any order.

<pre class="prod">
	<dfn id="content-list">&lt;content-list></dfn> = [ <<string>> | <<counter()>> | <<counters()>> | <<content()>> | <<attr()>> ]+
</pre>


<dl dfn-type="value" dfn-for="<content-list>">
	<dt><<string>>
	<dd>A <a href="https://www.w3.org/TR/CSS21/syndata.html#strings">string</a>, as defined in [[CSS21]]
	<dt><<counter()>>
	<dd>A <a href="https://www.w3.org/TR/CSS21/syndata.html#counter">counter()</a> function, as described in [[CSS21]].
	<dt><<counters()>>
	<dd>A <a href="https://www.w3.org/TR/CSS21/syndata.html#counter">counters()</a> function, as described in [[CSS21]].
	<dt><<content()>>
	<dd>The ''content()'' function, described below.
	<dt><<attr()>>
	<dd>An ''attr()'' function, as defined in [[CSS-VALUES-3]]
</dl>

<h5 id="content-function-header">The ''content()'' function</h5>

<pre class="prod">
	<dfn>content()</dfn> = content([text | before | after | first-letter ])
</pre>


<p class="issue">How do we define the default value for this function?</p>


<dl dfn-type="value" dfn-for="content()">

<dt>text</dt>
	<dd>The string value of the element, determined as if <code>white-space: normal</code> had been set. This is the default value</dd>
	<dt>before</dt>
	<dd>The string value of the <code>::before</code> pseudo-element, determined as if <code>white-space: normal</code> had been set. </dd>
	<dt>after</dt>
	<dd>The string value of the <code>::after</code> pseudo-element, determined as if <code>white-space: normal</code> had been set. </dd>
	<dt>first-letter</dt>
	<dd>The first letter of the element, as defined for the <code><a href="https://www.w3.org/TR/css3-selectors/#first-letter">::first-letter</a></code> pseudo-element </dd>
</dl>

The content values of <a>named strings</a> are assigned at the point when the content box of the element is first created (or would have been created if the element’s display value is none). The <dfn>entry value</dfn> for a page is the assignment in effect at the end of the previous page. The <dfn>exit value</dfn> for a page is the assignment in effect at the end of the current page.



Whenever the value of the element changes, the value of the <a lt="named string">named string(s)</a> is updated. User agents must be able to recall many values of the named string, as the ''string()'' function can return past, current, or future values of the assignment.
<div class="example">

HTML:

<pre highlight="html">
&lt;h1>Loomings&lt;/h1>
</pre>

CSS:

<pre highlight="css">
h1::before {
	content: 'Chapter ' counter(chapter);
}

h1 {
	string-set: header content(before) ':' content(text);
}

h1::after {
	content: '.';
}
</pre>

The value of the <a>named string</a> “header” will be “Chapter 1: Loomings”.
</div>

<div class="example">
HTML:

<pre highlight="html">
&lt;section title="Loomings">
</pre>

CSS:

<pre highlight="css">
section {
	string-set: header attr(title);
}
</pre>

The value of the “header” string will be “Loomings”.
</div>


<h4 id="using-named-strings">
	The ''string()'' function
</h4>
The ''string()'' function is used to copy the value of a <a>named string</a> to the document, via the 'content' property. This function requires one argument, the name of the <a>named string</a>. Since the value of a named string may change several times on a page (as new instances of the element defining the string appear) an optional second argument indicates which value of the named string should be used.


The second argument of the ''string()'' function is one of the following keywords:
<dl dfn-type="value" dfn-for="string()">
	<dt id="string-first">first</dt>
	<dd>The value of the first assignment on the page is used. If there is no assignment on the page, the <a>entry value</a> is used. <code>first</code> is the default value.</dd>
	<dt id="string-start">start</dt>
	<dd>If the element is the first element on the page, the value of the first assignment is used. Otherwise the <a>entry value</a> is used. The <a>entry value</a> may be empty if the element hasn’t yet appeared. </dd>
	<dt id="string-last">last</dt>
	<dd>The <a>exit value</a> of the <a>named string</a> is used.</dd>
	<dt id="string-first-except">first-except</dt>
	<dd>This is identical to <code>first</code>, except that the empty string is used on the page where the value is assigned.</dd>
</dl>



<div class="example">
CSS:

<pre highlight="css">
@page {
	size: 15cm 10cm;
	margin: 1.5cm;

	@top-left {
		content: "first: " string(heading, first);
	}

	@top-center {
		content: "start: " string(heading, start);
	}

	@top-right {
		content: "last: " string(heading, last);
	}
}

h2 {
	string-set: heading content();
}
</pre>
The following figures show the first, start, and last assignments of the “heading” string on various pages.
<figure>
<img src="images/using-strings-1.jpg" width="480" alt="">
<figcaption>The <a href="#string-start">start</a> value is empty, as the string had not yet been set at the start of the page.</figcaption>
</figure>
<figure>
<img src="images/using-strings-2.jpg" width="480" alt="">
<figcaption>Since the page starts with an h2, the <a href="#string-start">start</a> value is the value of that head.</figcaption>
</figure>
<figure>
<img src="images/using-strings-3.jpg" width="480" alt="">
<figcaption>Since there’s not an h2 at the top of this page, the <a href="#string-start">start</a> value is the <a>exit value</a> of the previous page.</figcaption>
</figure>

</div>

<!--
<div class="example">
<pre highlight="css">
Example where element fragments across page boundary
</pre>
</div>
-->

<h3 id="running-elements">
	Running elements
</h3>
Many headers and footers cannot be represented only by unformatted text. A book title serving as a running head may contain an italic word, for example. A mechanism is needed to move or copy elements into margin boxes. To do this, we add the ''running()'' value to the position property, and the ''element()'' value to the content property.

<div class="example">
<pre highlight="css">
@page {
	@top {
		content: element(header);
	}
}

h1 {
	position: running(header);
}
</pre>

In this example, the <code>h1</code> element is placed in the <code>@top</code> margin box, complete with formatting and any descendant elements. It does not display in the normal document flow.
</div>

<h4 id="running-syntax">
The ''running()'' value
</h4>

<code>position: running(custom-ident)</code> removes the element (and associated ::before and ::after pseudo-elements) from the normal flow, and makes it available to place in a page margin box using ''element()''. The element inherits from its original position in the document, but does not display there.

<pre class="propdef partial">
	Name: position
	New Values: <<running()>>
</pre>


<pre class="prod">
	<dfn>running()</dfn> = running( <<custom-ident>> )
</pre>

<!--

<h4 id="alternative-syntax-running">Alternative Proposal from Bert Bos</h4>



-->


<div class="example">

HTML:

<pre highlight="html">
&lt;p class="rh">&lt;i>Miranda v. Arizona&lt;/i> in Context&lt;/p>
&lt;h2>&lt;i>Miranda v. Arizona&lt;/i> in Context&lt;/h2>
</pre>

CSS:

<pre highlight="css">
@top-center {
	content: element(heading);
}

p.rh {
	position: running(heading);
}

p.rh::before {
	content: counter(page) ' / ';
}
</pre>



<figure>


<img src="images/running-element-gcpm_Page_1.jpg" width="480" alt="running header using running elements">
<figcaption><a>Running element</a> in page margin box</figcaption>
</figure>
</div>



<p class="note">The ''element()'' value can only be used in page margin boxes. And it cannot be combined with other possible values for the content property.</p>
<div class="issue">
<p>This idea would be much more useful if we could also copy (rather than just move) elements. That would avoid the duplication of HTML in the example above.
</p>


Bert Bos has proposed an alternative syntax, which allows both moving and copying elements into running heads. In the example below, h2 elements appear in their normal place in the document, but are also copied into running heads.

<div class="example">
<pre highlight="css">
h2 {
	display: block;
	running: chapter;
	font-size: 18pt;
	font-weight: bold;
}

h2:running {
	display: inline;
	font-size: 11pt;
	font-weight: normal;
	font-variant: small-caps;
	letter-spacing: 1pt;
}

@page {
	@top-center {
		content: element(chapter);
	}
}
</pre>
</div>


<pre class="propdef">
Name: running
Value: <<custom-ident>>
Initial: none
Applies to: elements
Inherited: no
Percentages: N/A
Computed value: specified value
Animation type: discrete
</pre>

<p class=all-media>User agents are expected to support this property on all media, including non-visual ones.</p>

</div>

<h4 id="element-syntax">
The ''element()'' value
</h4>

The ''element()'' value of the content property places an element (which has been removed from the normal flow via ''running()'') in a page margin box. Whenever the value of the element changes, the value of ''element()'' is updated.

Just as with ''string()'', ''element()'' takes an optional keyword to describe which value should be used in the case of multiple assignments on a page. User agents must be able to recall many values, as ''element()'' can return past, current, or future values of the assignment.

<pre class="propdef partial">
	Name: content
	New Values: <<element()>>
</pre>

<pre class="prod">
	<dfn>element()</dfn> = element( <<custom-ident>> , [ first | start | last | first-except ]? )
</pre>

<h2 id="footnotes">
	Footnotes
</h2>
Ancillary content may be moved to the bottom or side of a page. A footnote is created when such content moves to the bottom of the page, leaving a reference indicator.


<h3 id="footnote-terms">Terminology</h3>

Footnotes are complex objects (see the <a href="https://www.w3.org/TR/dpub-latinreq/#footnotes">footnote section</a> at [[dpub-latinreq]]), so it will be helpful to define some terms before proceeding.

<figure>


<img src="images/footnote-diagram.001.jpg" width="480" alt="page with footnotes">
<figcaption>Footnote terminology</figcaption>
</figure>

<dl>



<dt>footnote element</dt>
<dd>The element containing the content of the footnote, which will be removed from the flow and displayed as a footnote.</dd>

<dt>footnote marker (also known as footnote number)</dt>
<dd>A number or symbol adjacent to the footnote body, identifying the particular footnote. The footnote marker should use the same number or symbol as the corresponding footnote call, although the marker may contain additional punctuation.</dd>

<dt>footnote body</dt>
<dd>The footnote marker is placed before the footnote element, and together they represent the footnote body, which will be placed in the footnote area.</dd>

<dt>footnote call (also known as footnote reference)</dt>
<dd>A number or symbol, found in the main text, which points to the footnote body.</dd>


<dt>footnote area</dt>
<dd>The page area used to display footnotes.</dd>

<dt>footnote rule (also known as footnote separator)</dt>
<dd>A horizontal rule is often used to separate the footnote area from the rest of the page. The separator (and the entire footnote area) cannot be rendered on a page with no footnotes.</dd>

</dl>



<h3 id="creating-footnotes">
	Creating footnotes
</h3>
An element becomes a footnote by applying <code>float: footnote</code> to that element. This triggers the following actions:
<ol>
	<li> The footnote element is removed from the flow, and a <code>::footnote-call</code> pseudo-element is inserted in its place, which serves as a reference to the footnote.</li>
	<li> A <code>::footnote-marker</code> pseudo-element, identifying the footnote, is placed at the beginning of the footnote element. Together this is the footnote body.</li>
	<li>The <a>footnote counter</a> is incremented.</li>
	<li>The footnote body is placed in the footnote area at the bottom of the page. Footnote elements from a given page are placed in the footnote area of that page in document order.</li>
</ol>
<div class="example">
HTML:
<pre style="word-wrap: break-word; white-space: pre-wrap;">
&lt;p>Though the body was erect, the head was thrown back so that the closed eyes were pointed towards the needle of the tell-tale that swung from a beam in the ceiling.&lt;span class="footnote">The cabin-compass is called the tell-tale, because without going to the compass at the helm, the Captain, while below, can inform himself of the course of the ship.&lt;/span>&lt;/p>
</pre>
CSS:
<pre highlight="css">
@page {
	@footnote {
		float: bottom;
	}
}

span.footnote {
	float: footnote;
}
</pre>
</div>

<p class="issue">Why is float:bottom used with the footnote area? Floating footnotes to the footnote area, and then floating the footnote area itself, seems overly complex, given that implementations don’t allow the footnote area to float anywhere else. Note that some implementations do allow the footnote area to be absolutely positioned.</p>
<h3 id="footnote-types">
	Types of footnotes
</h3>
The following new value of the 'float' property creates a footnote element:

<pre class="propdef partial">
	Name: float
	New Values: footnote
</pre>
<dl dfn-type="value" dfn-for="float">
	<dt><dfn>footnote</dfn></dt>
	<dd>each footnote element is placed in the footnote area of the page</dd>
</dl>

The 'footnote-display' property determines whether a footnote is displayed as a block element or inline element.

<pre class="propdef">
	Name: footnote-display
	Value: block | inline | compact
	Initial: block
	Applies to: elements
	Inherited: no
	Percentages: N/A
	Computed value: specified value
	Animation type: discrete
</pre>


<dl dfn-type="value" dfn-for="footnote-display">
<dt><dfn id="footnote-display-block">block</dfn></dt>
<dd>The footnote element is placed in the footnote area as a block element</dd>
<dt><dfn id="footnote-display-inline">inline</dfn></dt>
<dd>The footnote element is placed in the footnote area as an inline element</dd>
<dt><dfn id="footnote-display-compact">compact</dfn></dt>
<dd>The user agent determines whether a given footnote element is placed as a block element or an inline element. If two or more footnotes could fit on the same line in the footnote area, they should be placed inline.</dd>
</dl>


<h3 id="footnote-area">
	The footnote area
</h3>
A <a href='https://drafts.csswg.org/css-page/#page-area'>page area</a> that can be used to display footnotes is described in the <a href='https://drafts.csswg.org/css-page/#page-context'>page context</a> using an <code>@footnote</code> rule. This rule defines a box that, if used, will contain all the footnote elements that appear on that page. <!--
We add the following to the <a href="https://drafts.csswg.org/css-page/#specializatons-of-ATKEYWORD">page rule grammar</a> in [[CSS3PAGE]]:

<pre class="lexical">
FOOTNOTE_SYM ::= "@footnote"
</pre>
-->

<p class="issue">How would one describe this in the grammar of CSS3-Page?</p>






<h4 id="footnote-area-position">Positioning of the footnote area</h4>
The bottom margin edge of the footnote area is positioned so that it touches the bottom of the page area. The footnote area can only contain footnotes.


<p class="issue">How do footnotes work in multi-column text? Prince uses <code>float: prince-column-footnote</code> to create a footnote at the bottom of a column rather than the bottom of a page.</p>

<p class="issue">Implementations that support footnotes generally support page floats like <code>float: bottom</code>. Page floats should end up above the footnote area. How might this be specified?</p>



<h4 id="footnote-area-size">Size of the footnote area</h4>

The 'max-height' property on the footnote area limits the size of this area, unless the page contains only footnotes (as may happen on the last page of a document).

Since it is undesirable for a page to consist only of footnotes, user agents <em class="RFC2119">may</em> set a default max-height value on the footnote area.


<h3 id="footnote-counters">The Footnote Counter</h3>

The <dfn>footnote counter</dfn> is a predefined <a href="https://drafts.csswg.org/css-lists/#counter">counter</a> associated with the footnote element. Its value is the number or symbol used to identify the footnote. This value is used in both the footnote call and the footnote marker. It should be incremented for each footnote.

<h4 id="footnote-counter-values">Values of the footnote counter</h4>

The <a>footnote counter</a>, like other counters, may use any <a href="https://drafts.csswg.org/css-counter-styles-3/#counter-style">counter style</a>. Footnotes often use a sequence of symbols.

<div class="example">
<pre highlight="css">
::footnote-call {
	content: counter(footnote, symbols('*', '†', '‡', '§'));
}

::footnote-marker {
	content: counter(footnote, symbols('*', '†', '‡', '§')) '. ';
}
</pre>

</div>


<h4 id="resetting-footnote-counter">Resetting the footnote counter</h4>

The <a>footnote counter</a> may be reset on each page.

<div class="example">
<pre highlight="css">
@page {
	counter-reset: footnote;
	@footnote { … }
}
</pre>
</div>

Note that the value of the <a>footnote counter</a> should depend on the position of the footnote element in the document tree, not where it is eventually placed. A footnote element may sometimes be placed on the page after the footnote call, but the same counter value must be used for both.

<h3 id="footnote-call">
	The <code>footnote-call</code> pseudo-element
</h3>
A <code>::footnote-call</code> pseudo-element is inserted in place of the footnote element when the latter is removed from the flow. By default, the content of this pseudo-element is the value of the <a>footnote counter</a>, styled as a superscripted number.
<div class="example">
<pre highlight="css">
::footnote-call {
	content: counter(footnote);
	vertical-align: baseline;
	font-size: 100%;
	line-height: inherit;
	font-variant-position: super;
}
</pre>
</div>

<h3 id="footnote-marker">
	The <code>footnote-marker</code> pseudo-element
</h3>
The <code>::footnote-marker</code> pseudo-element represents the footnote element’s marker, the number or symbol that identifies each footnote. This pseudo-element behaves like a <code>::marker</code> pseudo-element, as defined in [[CSS3LIST]]. It is placed at the beginning of the superior parent’s content, and is inline by default. The <code>::footnote-marker</code> can be styled just as other <code>::marker</code> elements can be. The default style should include <code>list-style-position: inside</code>.
<div class="example">
<pre highlight="css">
::footnote-marker {
	content: counter(footnote);
}

::footnote-marker::after {
	content: '. ';
}
</pre>
</div>


<h3 id="footnote-policy">
Rendering footnotes and <code>footnote policy</code>
</h3>

Rendering footnotes can be complex. If a footnote falls near the bottom of the page, there may not be enough room on the page for the footnote body. The 'footnote-policy' property allows authors some influence over the rendering of difficult pages.

<pre class="propdef">
	Name: footnote-policy
	Value: auto | line | block
	Initial: auto
	Applies to: elements
	Inherited: no
	Percentages: N/A
	Computed value: specified value
	Animation type: discrete
</pre>


<dl dfn-type="value" dfn-for="footnote-policy">
<dt><dfn>auto</dfn></dt>
<dd>The user agent chooses how to render footnotes, and may place the footnote body on a later page than the footnote reference. A footnote body must never be placed on a page before the footnote reference.</dd>
<dt><dfn id="footnote-policy-line">line</dfn></dt>
<dd>If a given footnote body cannot be placed on the current page due to lack of space, the user agent introduces a forced page break at the start of the line containing the footnote reference, so that both the reference and the footnote body fall on the next page. Note that the user agent must honor <a href="https://drafts.csswg.org/css-break/#widows-orphans">widow and orphan</a> settings when doing this, and so may need to insert the page break on an earlier line.</dd>
<dt><dfn>block</dfn></dt>
<dd>As with <a href="#footnote-policy-line">line</a>, except a forced page break is introduced before the paragraph that contains the footnote.</dd>
</dl>

<p class="issue">We need an algorithm for laying out footnotes</p>

<!--


<h4 id="pseudo-code-for-footnotes">
Pseudo-code for processing non-column footnotes
</h4>


let p = total height of any footnotes leftover from previous page

let t = margin-top of @footnote + padding-top of @footnote + border-top of @footnote

let g = total height of content area of page (goal in TeX lingo)

let m = max-height of @footnote (default is 75% of height of page content area)

let h(n) = height of nth footnote on page, as rendered in the footnote area

let f = total height needed for all footnotes on page

[1] at beginning of page, the following amount of space will be needed for footnotes:

f = if (p ne 0) then (p + t) else 0

[2] for n = 1 to (count of footnote elements on page)

f = f + h(n)

When starting a new page, the height of the footnote area is initially zero.


Load a page. If there are no leftover footnotes from previous pages to place, and no footnote elements on the current page, just render the current page. Otherwise,
<ol>
<li> create a footnote area, with the height of the content area set initially to zero, but all other properties as described by @footnote. The width of the footnote area is the width of the content area of the page. </li>
<li> Place any leftover footnotes in the footnote area, thus increasing its height. Continue until running out of leftover footnotes, reaching max height, or reaching height of page (size - top margin - bottom margin). If you still have parts of footnotes left after this process, mark them as leftover footnotes for the next page. </li>
<li> place the footnote area at the bottom of the page, reducing the content area of @page </li>
<li> if page is full of footnotes, go to next page. </li>
<li> If not, start drawing content on the page. if you reach a line with a footnote element, move element to bottom of footnote area. </li>
<li> Place as much of footnote as possible until reaching max height, or page height. </li>
<li> leave footnote-marker at location of footnote element. </li>
<li> increment <a>footnote counter</a> </li>
</ol>

-->

<!--
<h3>Sidenotes</h3>

<h4>Creating sidenotes</h4>

An element becomes a sidenote by applying float: sidenote to that element. This triggers several actions:

<ol>

<li>
The element is removed from the flow.
</li>

<li>
The sidenote element is positioned in the sidenote area, as described below.
</li>

</ol>

Unlike footnotes, calls and markers are not created by default for sidenotes.

<h4>The sidenote area</h4>

A page area that can be used to display sidenotes is described in the page context using an @sidenote rule. This rule defines a box that, if used, will contain the content that has been identified as a sidenote. The position or float properties of this box determines the placement of the sidenote.
-->
<h3 id="future">
Future directions
</h3>
The next level will include sidenotes, column footnotes, and multiple footnote areas.

<!--page selectors-->
<h2 id="the-first-page-pseudo-element">
Selecting Pages
</h2>

<!--should this be in css3-page?-->
A paginated document consists of a sequence of pages. [[CSS3PAGE]] defines <a>page selectors</a>, which allow the selection of the first page of the document, left and right pages, and blank pages. Here we extend the idea of page selectors to enable the selection of arbitrary document pages.
<h3 id="document-page-selectors">
Page Selectors
</h3>
The '':nth()'' page pseudo-class allows the selection of arbitrary document pages. This pseudo-class takes an argument of the form <a href="https://drafts.csswg.org/css-syntax/#anb">An + B</a> as defined in [[CSS3SYN]]. When applied to the default @page rule, '':nth()'' selects the document page whose index matches the argument.

<pre class="prod">
<dfn>:nth()</dfn> = :nth( <<a-n-plus-b>> [of <<custom-ident>>]? )
</pre>

<p class="note">
'':nth()'' is not related to the page counter, which may reset and use various numbering schemes.</p>

When the '':nth()'' selector is applied to a named page, and that named page is part of a page-group (see below), it selects the nth page in the <a>page group</a>.


<div class="example">
<pre highlight="css">
@page :nth(1)
</pre>

This selects the first page of the document.
<pre highlight="css">
@page :nth(2n)
</pre> This selects all even document pages.
</div>



<h3 id="document-sequence-selectors">
Page groups
</h3>
Many paginated documents have a repeating structure, consisting of many chapters, sections, or articles. The first page of each subdivision often requires special treatment, but [[CSS3PAGE]] doesn’t define a way to select the first page of each chapter (as distinct from the first page of the entire document).




When the 'page' property is applied to an element that also has a forced break property applied, a <a>page group</a> is created. The <dfn>page group</dfn> is the collection of all pages created by an instance of that element. When a new instance of the element is rendered, a new <a>page group</a> is started.

A page may be part of several page groups, as a given <a>page group</a> may have ancestors or descendants that are part of another <a>page group</a>.

<!-- A page group always starts on a new page.
NOT TRUE; NEED TO DESCRIBE
-->


<div class="example">
CSS:

<pre highlight="css">
div {
	page: A;
	break-before: page;
}
child {
	page: B;
	break-before: page;
}
</pre>
<figure>
<img src="images/PageGroups.001.jpg" width="480" alt="">
<figcaption>A page may be part of several <a>page groups</a>.</figcaption>
</figure>
Note that page 5 can be selected in three ways:

<pre highlight="css">
@page :nth(5 of A) /* will select 5th page of every &lt;div> */
@page :nth(1 of B) /* will select first page of every &lt;child> */
@page :nth(5)   /* will select 5th page of document */
</pre>
</div>



<div class="example">

Consider the following HTML:

<pre highlight="html">
&lt;div class="chapter">
&lt;h1>Chapter One&lt;/h1>
&lt;p>some text&lt;/p>
&lt;table class="broadside">
...
&lt;/table>
...
&lt;/div>
&lt;div class="chapter">
&lt;h1>Chapter Two&lt;/h1>
&lt;p>some text&lt;/p>
...
&lt;table class="broadside">
...
&lt;/table>
...
&lt;/div>
</pre>

And CSS:

<pre highlight="css">
div.chapter {
	page: body;
	break-before: page;
}

table.broadside {
	page: broadside;
	break-before: page;
}
</pre>

In this case, each chapter will form a separate <a>page group</a>. @page:nth(3 of body) will select the third page of each chapter, even if that page happens to use the “broadside” named page. @page:nth(1) will select only the first page of the document, as will @page:first.


</div>

<h2 id="leaders">
Leaders (moved)
</h2>

Issue: Now described in [[CSS3-CONTENT]]



<h2 id="cross-references">
Cross-references (moved)
</h2>

Issue: Now described in [[CSS3-CONTENT]]



<h2 id="bookmarks">
Bookmarks (moved)
</h2>

Issue: Now described in [[CSS3-CONTENT]]


<h2 class="no-num" id="former-wd-sections">Appendix A: Where Are They Now?</h2>

Many sections which were in the <a href="https://www.w3.org/TR/2011/WD-css3-gcpm-20111129/">29 November 2011 Working Draft</a> have been moved to other specifications. Here are some notes on where things have moved.

<h3 id=page-marks-and-bleed-area>Page marks and bleed area</h3>

<p class="note">This section has been moved to <a href="https://drafts.csswg.org/css-page/#marks">CSS Paged Media Module Level 3</a>.</p>


<h3 id=cmyk-colors>CMYK colors</h3>

<p class="note">This section has been moved to <a href="https://drafts.csswg.org/css-color-5/#device-cmyk">CSS Color Module Level 5</a>.</p>


<h3 id=styling-blank-pages>Styling blank pages</h3>
<p class="note">This section has been moved to <a href="https://drafts.csswg.org/css-page/#blank-pseudo">CSS Paged Media Module Level 3</a></p>


<h3 id=paged-presentations>Paged presentations</h3>
<p class="note">This section has been moved to <a href="https://drafts.csswg.org/css-overflow-4/#overflow-concepts">CSS Overflow Module Level 4</a>.</p>

<h3 id=navigation-between-pages>Navigation between pages</h3>
<p class="note">This is discussed in <a href="http://books.spec.whatwg.org/#spatial-layout-of-pages;-@layout">WHATWG CSS Books</a>.</p>

<h3 id=page-floats>Page floats</h3>

<p class="note">This section has been moved to <a href="https://drafts.csswg.org/css-page-floats/">CSS Page Floats</a>.</p>


<h3 id=selecting-columns-and-pages>Selecting columns and pages</h3>

<p class="note">A brief mention of selecting columns is found in <a href="http://books.spec.whatwg.org/#selecting-columns">WHATWG CSS Books</a>.</p>



<h2 class="no-num" id="ua-stylesheet">Appendix B: Default UA Stylesheet</h2>

<p>This appendix is informative, and is to help UA developers to implement a default stylesheet for HTML, but UA developers are free to ignore or modify as appropriate. </p>
<div class="example">
<pre highlight="css">
@page {
	counter-reset: footnote;

	@footnote {
		counter-increment: footnote;
		float: bottom;
		column-span: all;
		height: auto;
	}
}

::footnote-marker {
	content: counter(footnote);
	list-style-position: inside;
}

::footnote-marker::after {
	content: '. ';
}

::footnote-call {
	content: counter(footnote);
	vertical-align: super;
	font-size: 65%;
}

@supports ( font-variant-position: super ) {
	::footnote-call {
		content: counter(footnote);
		vertical-align: baseline;
		font-size: 100%;
		line-height: inherit;
		font-variant-position: super;
	}
}

h1 { bookmark-level: 1 }
h2 { bookmark-level: 2 }
h3 { bookmark-level: 3 }
h4 { bookmark-level: 4 }
h5 { bookmark-level: 5 }
h6 { bookmark-level: 6 }
</pre>
</div>

<h2 class="no-num" id="changes">Appendix C: Changes</h2>

Changes since the <a href="http://www.w3.org/TR/2014/WD-css-gcpm-3-20140513/">13 May 2014 Working Draft</a>:

<ul>
	<li>Clarify that bookmark is only created via 'bookmark-level' property. Remove <css>none</css> value from 'bookmark-label'.</li>
	<li>Move the cross references, leaders, and bookmarks sections to the <a href="https://www.w3.org/TR/css-content-3/">CSS Generated Content Module</a>.</li>
	<li>Incorrect break values were fixed. See <a href="https://github.com/w3c/csswg-drafts/issues/3524">Issue #3524</a>.</li>
	<li>The spec has new editors.</li>
</ul>


Changes since the <a href="https://hg.csswg.org/drafts/raw-file/6a5c44d11c2b/css-gcpm/Overview.html">24 September 2013 Editor’s Draft</a>:

<ul>
	<li>The spec has a new editor.</li>
	<li>All text and examples rewritten.</li>
	<li>Added ''attr(&lt;identifier>)'' value to 'string-set' property. This is supported by both Prince and AntennaHouse.</li>

	<li>Added 'footnote-policy' property to control rendering of footnotes in difficult situations.</li>
	<li>Added 'footnote-display' property to allow inline footnotes.</li>
	<li>Removed sidenotes section.</li>
	<li>Removed section on selecting elements within pages and columns</li>
	<li>Removed page-group property, and added optional argument to nth() page pseudo-class to allow selection within <a>page groups</a>.</li>
</ul>

Changes since the <a href="https://www.w3.org/TR/2011/WD-css3-gcpm-20111129/">29 November 2011 Working Draft</a>:

<ul>
	<li>Page Marks and Bleeds section moved to <a href="https://drafts.csswg.org/css-page/#marks">CSS Paged Media Module Level 3</a></li>
	<li>CMYK Colors section moved to <a href="https://drafts.csswg.org/css-color-5/#device-cmyk">CSS Colors Level 5</a>.</li>
	<li>Styling Blank Pages section deleted</li>
	<li>Paged Presentations section moved to <a href="https://drafts.csswg.org/css-overflow-3/#overflow-concepts">CSS Overflow Module Level 3</a>.</li>
	<li>Navigation Between Pages moved to <a href="http://books.spec.whatwg.org/#spatial-layout-of-pages;-@layout">WHATWG CSS Books</a></li>
	<li>Page floats section moved to <a href="https://drafts.csswg.org/css-page-floats/">CSS Page Floats</a></li>
	<li>First-page pseudo-element section deleted</li>
	<li>Selecting Columns and Pages section deleted</li>
	<li>env() function removed from string-set property</li>
	<li>alignment values of leaders removed</li>
	<li>leader specified to occupy only a single line</li>
	<li>content() value of target-text changed to content(text)</li>
	<li>target-pull() value of content property removed</li>
</ul>

<p>Differences with the <a href="http://books.ideas.whatwg.org/">WHATWG CSS Books</a> specification:</p>
<ul>
	<li>Added ''attr(&lt;identifier>)'' value to 'string-set' property. This is supported by both Prince and AntennaHouse.</li>
	<li><a href="http://books.ideas.whatwg.org/">CSS Books</a> does not have the 'footnote-display' property.</li>
	<li><a href="http://books.ideas.whatwg.org/">CSS Books</a> does not have the 'footnote-policy' property.</li>
	<li>The relationship between the <code>nth()</code> page pseudo-class and the page-group concept is clarified, which may make the page-group property redundant.</li>
	<li>This specification does not redefine the <code>:first</code> page pseudo-selector to select the first page of a page-group.</li>
	<li>This specification does not consider:
		<ol>
			<li>Named areas</li>
			<li>Selecting elements within pages</li>
			<li>The <code>range()</code> page pseudo-class</li>
			<li>Selecting columns</li>
			<li>Baseline rhythms</li>
			<li>Extending the box model</li>
			<li>Character substitution</li>
			<li>Microtypography</li>
		</ol>
	</li>
</ul>

<h2 class=no-num id=privacy>Privacy Considerations</h2>

No new privacy considerations have been reported on this specification.

<h2 class=no-num id=security>Security Considerations</h2>

No new security considerations have been reported on this specification.


<h2 class="no-num" id="acknowledgments">
Acknowledgments
</h2>
This work would not be possible without the immense contributions of Håkon Wium Lie.

Chris Lilley, Elika J. Etemad, Alan Stearns, L. David Baron, Bert Bos, Florian Rivoal, and Liam Quin have provided valuable feedback.
