<pre class='metadata'>
Title: CSS Paged Media Module Level 3
Shortname: css-page
Level: 3
Status: ED
Remove Multiple Links: false
Work Status: Revising
Group: csswg
ED: https://drafts.csswg.org/css-page-3/
TR: https://www.w3.org/TR/css-page-3/
Issue Tracking: Tracker http://www.w3.org/Style/CSS/Tracker/products/13
Editor: Elika J. Etemad / fantasai, Apple&#44; formerly Mozilla, http://fantasai.inkedblade.net/contact, w3cid 35400
Former Editor: Simon Sapin, Mozilla&#44; formerly Kozea, http://exyr.org/about/, w3cid 58001
Former Editor: Melinda Grant, HP
Former Editor: Håkon Wium Lie, Opera Software
Former Editor: Jim Bigelow, Hewlett-Packard
Former Editor: Jacob Refstrup, Hewlett-Packard
Former Editor: Robert Stevahn, Hewlett-Packard
Ignored terms: fit, fit-position, stacking context
Abstract: This CSS module specifies how pages are generated and laid out to hold fragmented content in a paged presentation. It adds functionality for controlling page margins, page size and orientation, and headers and footers, and extends generated content to enable page numbering and running headers / footers. The process of paginating a flow into such generated pages is covered in [[!CSS-BREAK-3]].
</pre>

<pre class=link-defaults>
spec:css-borders-4; type:property;
	text:border-bottom-width
	text:border-top-width
spec:css-break; type:property; text:break-after
spec:css-values; type:value; text:ex
spec:css2; type: property
	text: counter-increment
	text: counter-reset
	text: display
	text: margin
	text: max-height
	text: max-width
	text: min-height
	text: min-width
</pre>

<style>
	#margin-values { border-collapse: collapse; }
	#margin-values td,
	#margin-values th
	{
		padding: 0.2em;
		border: thin solid black;
	}

	.property-list
	{
		border: 1px solid black;
		padding: .2em;
		margin-top: 2em;
	}

	.property-list td
	{
		border: 1px solid black;
		padding: .1em;
	}

	table.page-sizes
	{
		border: thin solid;
		margin-top: 1.5em;
	}
	table.page-sizes td
	{
		border: thin solid;
		padding: .5em;
	}
	table.page-sizes th
	{
		border: thin solid;
		padding: .5em;
		background: #ffffaa;
	}
</style>

<h2 id="intro">
Introduction</h2>

<div class=non-normative>
	Paged media (e.g., paper, transparencies, photo album pages, pages
	displayed on computer screens as printed output simulations) differ from
	[=continuous media=]
	in that the content of the document is split into one or more discrete
	static display surfaces. To handle pages, CSS3 Paged Media describes how:

	<ul>
		<li><a href="#page-breaks">page breaks</a> are created and avoided;
		<li>the page properties such as size, orientation, margins, border, and
		padding are specified;
		<li>headers and footers are established within the page margins; and
		<li>content such as page counters are placed in the headers and footers;
	</ul>

	This module defines a <a href="#page-model">page model</a> that specifies how a
	document is formatted within a rectangular area, called the
	<a href="#page-box-page-rule">page box</a>, that has finite width and height.

	Although CSS3 does not specify how user agents transfer page boxes to sheets,
	it does include certain mechanisms for telling user agents about the intended
	page sheet <a href="#page-size">size and orientation</a>. In the general case,
	CSS3 assumes that one page box will be transferred to one surface of similar
	size.

	Note: The [[CSS-BREAK-4]] specification
	addresses controls over [=fragmentation=] (pagination),
	such as the 'break-before', 'break-after', 'break-inside',
	'widows', and 'orphans' properties.

</div>

<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 [[!CSS2]]
	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.

<h2 id="page-terms">
Page Terminology</h2>

	The following terminology and accompanying diagrams help to describe the
	page model:

<dl>
	<dt><dfn export>Page sheet</dfn>
	<dd>
		<img src="images/PageSheet.png" style="float: right;" alt="The corner of a page sheet with the non-printable area at the edge and printable area inside it" height="148" width="194">
		The page sheet is one surface of the physical
		medium. The illustration to the right shows a representation of the upper-left
		corner of a page sheet.

	<dt><dfn export lt="printable area">Printable and non-printable areas</dfn>
	<dd>
		The non-printable area is the area of a page sheet that a physical device such
		as a printer is not capable of marking reliably, usually due to the printer's
		paper handling mechanism. This value is printer dependent and is usually a
		small region along each edge of the page sheet. The printable area is the area
		of page sheet that a printer <em>is</em> capable of marking reliably. The size
		of the printable area is the size of the page sheet reduced by the size of the
		non-printable area. A user agent may not know the dimensions of this area for a
		particular printing device; but when its dimensions are known, user agents
		may adjust the formatting of the document so that
		content falls within the printable area. How this adjustment is accomplished is
		device dependent within the constraints expressed in the sections
		[[#renderingpages]] and [[#content-outside-box]].

	<dt><dfn export>Page Orientation</dfn>
	<dd>
		The page orientation is defined by comparing the length of the edges of a
		<a>page box</a>. The page box is a rectangle with two
		perpendicular edges called the long edge and the short edge. The length of the
		long edge is always greater than or equal to the length of the short edge. When
		the page box is square, the two edges are of the same length and either can be
		used as the long edge with the other being the short edge. This specification
		defines page orientations of ''portrait'' and ''landscape''.

	<dt><dfn export lt="portrait|portrait orientation">Portrait Orientation</dfn>
	<dd>
		A portrait page's height is greater than or equal to its width. Horizontal
		elements are parallel to the short edge and vertical elements to the long edge.

	<dt><dfn export lt="landscape|landscape orientation">Landscape Orientation</dfn>
	<dd>
		A landscape page's width is greater than or equal to its height. Horizontal
		elements are parallel to the long edge and vertical elements to the short edge.

		Note: Note that CSS3 makes no distinction between landscape and
		reverse-landscape orientations. However, future versions of CSS may do so.
		UAs should consider, when formatting for duplexed printing, the binding edge,
		page progression, and ease of reading when choosing between landscape and
		reverse-landscape renderings.

	<dt><dfn export>Duplex Printing</dfn>
	<dd>
		Duplex printing prints one page box per side of a page sheet and uses both
		sides of the page sheet. This module provides no ability to specify whether a
		document is duplex printed, but the concept of left and right pages is based on
		the assumption that the document is duplex printed, regardless of whether or
		not it actually is.

	<dt><dfn export>Binding Edge</dfn>
	<dd>
		The binding edge is the edge of the page box that is toward the binding if the
		material is bound. The binding edge often has a larger margin than the opposite
		edge to provide for the space used by the binding. The binding edge can be any
		of the four edges. However, page sheets are customarily bound so that the
		binding edge of page boxes with portrait orientation is vertical. This module
		provides no method to specify the binding edge. In duplex printing, the binding
		edge is on opposite sides of the page box for the left and right pages.

	<dt><dfn export>Facing Pages</dfn>
	<dd>
		Facing pages are two sequential pages such that when the document is duplex
		printed they are on separate sheets of paper. Typically, the earlier page will
		be the back side of one sheet and the later page will be the front side of
		another. They are usually laid out so that the binding edges of facing pages
		are vertical and adjacent when the pages are placed in their normal reading
		orientation.

	<dt><dfn export>Left Page</dfn>
	<dd>
		A page that would be on the left if it is part of a pair of facing pages as
		typically laid out. Page layouts for documents using a left-to-right page
		progression have the earlier of the facing pages on the left. Rules specific to
		the left page can be specified using the '':left'' <a>page selector</a>.

	<dt><dfn export>Right Page</dfn>
	<dd>
		A page that would be on the right if it is part of a pair of facing pages as
		typically laid out. Page layouts for documents using a right-to-left page
		progression have the earlier of the facing pages on the right. Rules specific
		to the right page can be specified using the '':right'' <a>page selector</a>.
</dl>

<h2 id="page-model">The Page Model</h2>

	In the [=paged media=] formatting model, the document is transferred into one
	or more page boxes. The <dfn export>page box</dfn> is a specialized CSS
	box that maps to a rectangular print media surface, such as a page of paper.
	It is roughly analogous to the <a href="https://www.w3.org/TR/CSS2/visuren.html#viewport">viewport</a>.
	<img src="images/PageBox.png" style="float: right;" alt="" height="266" width="267">

	As with other CSS <a href="https://www.w3.org/TR/CSS2/box.html">boxes</a>, a page box
	consists of margin, border, padding, and content areas. The content and
	margin areas of a page box have special functions:

	Issue: In CSS 2.1, both the page box and page area are simple rectangles.
	Neither is a CSS box with margins, borders, and padding.
	This CSS box should be distinct from the page box and page area,
	which would be its margin area and content area, respectively.
	Naming ideas?

<ul>
	<li>
		The content area of a page box is called the <dfn export>page area</dfn>.
		The content of the document is flowed into one or more page boxes.
		The page area acts as a container for all the boxes generated by the root
		element and its descendants that are laid out within a given page box. The
		edges of the page area on the first page establish the rectangle that is the
		initial <a>containing block</a>
		of the document.

	<li>
		The margin area of a page box is divided into
		16 <dfn export>page-margin boxes</dfn>.
		Each page-margin box has its own margin, border, padding and content areas.
		Page-margin boxes are typically used to display running headers and footers.
</ul>

	The properties of a <a>page box</a> are determined by properties
	declared within the <a>page context</a>, which is the
	<a href="https://www.w3.org/TR/CSS2/syndata.html#x14">declaration block</a> of the
	''@page'' rule. Similarly the properties of a <a>page-margin box</a>
	are determined by properties declared within its <a>margin context</a>.
	Declarations in the page context can affect the page box and/or inherit
	to the page-margin boxes, but they do not apply to or inherit into the
	document's root element or other content.

	The <a>containing block</a> of the page box is specified using the '@page/size'
	property in the <a>page context</a>. The width and horizontal margins
	of the page box are then calculated exactly as for a
	<a href="https://www.w3.org/TR/CSS2/visudet.html#blockwidth">non-replaced block element in normal flow</a>. [[!CSS2]]
	The height and vertical margins
	of the page box are calculated analogously (instead of using the block height
	formulas). In both cases if the values are over-constrained, instead of
	ignoring any margins, the containing block is resized to coincide with the
	margin edges of the page box.

<h3 id="painting">
Page Backgrounds and Painting Order</h3>

	When drawing a page of content, the page layers are painted in the
	following painting order (bottommost first):

	<ol>
		<li>page background
		<li>document canvas
		<li>page borders
		<li>document contents
		<li>page-margin boxes
	</ol>

	In the page model, the page background behaves similar to the root background:
	its <a spec=css-backgrounds>background painting area</a> is the <a>bleed area</a>,
	which covers the entire page box, including its margins (regardless of 'background-clip').
	Page backgrounds are anchored within the page box's padding area by default
	(and honor 'background-origin' if the UA supports [[!CSS-BACKGROUNDS-3]]).
	However if 'background-attachment' is ''background-attachment/fixed''
	then the image is positioned relative to the page box including its margins
	(i.e. the <a spec=css-backgrounds>background positioning area</a>
	is the page's margin box).

	The document canvas background is drawn as the page box's background:
	by default its <a spec=css-backgrounds>background painting area</a> covers the page box's border box,
	and for UAs that support [[!CSS-BACKGROUNDS-3]], follows the 'background-clip' value specified on the root element.
	It remains, however, positioned with respect to the root element
	or page area as usual.

	With respect to the page-margin boxes,
	the document canvas, page borders, and all of the document contents
	are treated as a single element with a <code>z-index</code> value of ''0''
	that establishes a
	<a>stacking context</a>
	[[!CSS2]]:
	the page-margin boxes never interleave with parts of the document content
	or between the content and the canvas.
	They may only paint in front of the document content
	or behind the document canvas.
	The page background is always painted underneath everything else.

	The 'z-index' property applies to page-margin boxes.
	Since the 'position' property does not apply to page-margin boxes,
	'z-index' always affects page-margin boxes as if they were positioned elements
	regardless of the 'position' property's value.
	Each page-margin boxes always establishes a stacking context.

	The default painting order,
	or <a href="https://www.w3.org/TR/CSS2/zindex.html">CSS2.1 Appendix E</a> "tree order",
	of page-margin boxes with respect to each other is as follows:

	<ol>
		<li>''@top-left-corner''
		<li>''@top-left''
		<li>''@top-center''
		<li>''@top-right''
		<li>''@top-right-corner''

		<li>''@right-top''
		<li>''@right-middle''
		<li>''@right-bottom''

		<li>''@bottom-right-corner''
		<li>''@bottom-right''
		<li>''@bottom-center''
		<li>''@bottom-left''
		<li>''@bottom-left-corner''

		<li>''@left-bottom''
		<li>''@left-middle''
		<li>''@left-top''
	</ol>

	<p class=note>
		Start with ''@top-left-corner'', then go clockwise.
		This order is arbitrary but can be overridden with 'z-index'.
		It only has a visible effect when page-margin boxes overlap,
		which should not happen in most cases.

<h3 id="content-outside-box">Content outside the page box</h3>

When formatting content in the page model, some content may end up outside the
page box. For example, an element whose 'white-space' property has the value
''pre'' can generate a box that is wider than the page box. As another example,
when boxes are positioned absolutely or relatively, they may end up in
"inconvenient" locations. For example, images may be placed on the edge of
the page box or 100,000 meters below the page box.

A specification for the exact formatting of such elements lies outside the
scope of this document. However, it is recommended that authors and user agents
observe the following general principles concerning content outside the page
box:

<ul>
	<li>Content should be allowed slightly beyond the page box to allow pages
	to "bleed".
	<li>User agents <em class="RFC2119">SHOULD</em> avoid generating a large
	number of content-empty pages to honor the positioning of elements (e.g.,
	printing 100 blank pages is probably neither the author's nor the user's
	intent).
	A <dfn export id="content-empty">Content-empty page</dfn> is a page box whose page
	area contains no printable content other than backgrounds and/or borders. A
	page box whose page area contains generated content, or content whose
	visibility is ''visibility/hidden'', or invisible content such as a zero-width space is
	not a content-empty page. On the other hand, a page containing only a
	background and/or borders and/or page-margin box content <em>is</em> a
	content-empty page.
	<p class="note">Note, however, that generating a small number of empty page
	boxes is sometimes necessary to honor the forced-break values for
	'page-break-before'/'break-before' and 'page-break-after'/'break-after'.
	[[!CSS2]] [[!CSS-BREAK-3]]

	<li>Authors <em class="RFC2119">SHOULD NOT</em> position elements in
	inconvenient locations just to avoid rendering them. Instead:
	<ul>
		<li>To suppress box generation entirely, set the 'display' property to ''display/none''.
		<li>To make a box invisible, set the <span class="property">'visibility'</span>
		property.
		</ul>
		<li>This specification does not define how boxes positioned outside the page
		box are handled. Possibilities include discarding them or creating page boxes
		for them at the end of the document.
</ul>

<h3 id="progression">Page Progression</h3>

	CSS distinguishes between left pages and right pages on all documents,
	whether they are printed duplex or not.
	Each left page is followed by a right page and vice versa.
	Left and right pages can be styled differently
	with the <a href="#left-right-first"><code>:left</code> and <code>:right</code> pseudo-classes</a>.

	Whether the first page of a document is a left page or a right page
	depends on the page progression of the document.
	The <dfn export>page progression</dfn>
	is the direction in which the printed pages of a document would be sequenced
	when laid out side-to-side.
	For example, English and horizontally-set Japanese typically progress from left to right,
	whereas Arabic and vertically-set Japanese pages typically progress from right to left.

	The page progression direction is determined as follows:

	<ul>
		<li>If text is laid out in horizontal lines,
		the <a>page progression</a> is the same as the <a>inline base direction</a>.
		<li>If text is laid out in vertical lines,
		the <a>page progression</a> is the same as the <a>block flow direction</a>.
	</ul>

	If the UA supports the 'direction' and 'writing-mode' properties
	from the CSS 3 Writing Modes Module [[CSS-WRITING-MODES-3]], it must
	<a href="https://www.w3.org/TR/css3-writing-modes/#page-direction">determine</a>
	the <a>page progression</a> is determined by the <a>principal writing mode</a>.

	In documents with a left-to-right <a>page progression</a>
	the first page of the document is a right page, and vice versa.
	To explicitly force a document to begin printing on a left or right page,
	authors can specify a 'break-before' value
	that that propagates a page break to the root. [[!CSS-BREAK-3]]
	The UA must suppress the first (empty) page(s) in this case
	(and the <code>:first</code> pseudo-class matches the first printed page).

	<div class="example">
		<pre>
			html { break-before: always }
		</pre>

		For an HTML document with a left-to-right page progression,
		the above style rule will cause the first page of the document
		to print on a ':left' page

		<pre>
			html { break-before: left }
		</pre>

		For an HTML document,
		the above style rule will cause the first page of the document
		to print on a ':left' page,
		regardless of the page progression.

	</div>

<h2 id="page-selector-and-context">
Page Selectors and the Page Context</h2>

<h3 id="at-page-rule" oldids="page-box-page-rule">
The @page Rule</h3>

	Authors can specify various aspects of a page box,
	such as its dimensions, orientation, and margins,
	within an <dfn>@page</dfn> rule.
	''@page'' rules are allowed
	wherever <a href="https://www.w3.org/TR/CSS2/syndata.html#rule-sets">rule-sets</a> are allowed.
	An ''@page'' rule consists of the keyword ''@page'',
	an optional comma-separated list of
	<a>page selectors</a>
	and a block of declarations
	(said to be in the <dfn export id="page-context">page context</dfn>).
	An ''@page'' rule can also contain other at-rules,
	interleaved between declarations.
	The current level of this specification
	only allows <a>margin at-rules</a> inside ''@page''.

	''@page'' rules without a selector list apply to every page.
	Other ''@page'' rules apply to pages that <a>match</a>
	at least one of their selectors.
	Properties declared within the page context apply to the page box.

If an error is encountered during the processing of a declaration block within
a page or a margin context, the <a href="https://www.w3.org/TR/CSS2/syndata.html#parsing-errors">Rules for handling parsing errors</a>
apply; that is, valid declarations within the block are applied.

<h3 id="page-selectors">Page selectors</h3>

	A <dfn export id="page-selector">page selector</dfn> is made of
	either a <a>page type selector</a>
	or a <a>page pseudo-class</a>,
	followed by zero or more additional <a>page pseudo-classes</a>.
	No whitespace is allowed between components of a selector.
	The <<page-selector>> grammar
	and examples can be found below.

	A <a>page selector</a> is said to <dfn>match</dfn> a given page if and only if
	all of its components match the page.

	A <dfn export>page type selector</dfn> is
	a case-sensitive <a href="https://www.w3.org/TR/CSS2/syndata.html#value-def-identifier">CSS identifier</a> [[!CSS2]].
	It <a>matches</a> pages of the <a href="#using-named-pages">named page type</a>
	generated by the 'page' property.
	<span id="page-selector-syntax-restrict">
		A page type name of ''page/auto''
		(<a href="https://www.w3.org/TR/CSS2/syndata.html#characters">ASCII case-insensitive</a>)
		does not make the rule invalid,
		but must never match.
	</span>

	A <dfn export>page pseudo-class</dfn> is <a href="https://www.w3.org/TR/CSS2/syndata.html#characters">ASCII case-insensitive</a>
	and has the same syntax as <a href="https://www.w3.org/TR/selectors/#pseudo-classes">pseudo-classes</a> in regular Selectors. [[!SELECT]]
	The various <a>page pseudo-classes</a> are defined below.

<h4 id="spread-pseudos"><span id="left-right-first"></span>
Spread pseudo-classes: '':left'', '':right''</h4>

	When printing double-sided documents,
	left and right pages are often formatted differently.
	This can be expressed by using the '':left'' and '':right'' page pseudo-classes.

	<p dfn-type="value" dfn-for="@page">All pages are automatically classified by user agents
	as either left pages or right pages,
	based on <a href="#progression">page progression</a>.
	The <dfn>:left</dfn> and <dfn>:right</dfn> pseudo-classes
	only <a>match</a> <a lt="left page">left</a> or <a lt="right page">right pages</a>,
	respectively.

<div class="example">
The following example creates left and right binding edges using these pseudo-classes:
<pre>
@page :left {
margin-left: 3cm;
margin-right: 4cm;
}

@page :right {
margin-left: 4cm;
margin-right: 3cm;
}
</pre>
</div>

If different declarations have been given for left and right pages, the user
agent must honor these declarations even if the user
agent does not transfer the page boxes to left and right sheets (i.e., a
printer that only prints on one side of the medium must nevertheless produce
correctly formatted output).

<div class="note">

	<em><strong>Note.</strong>
	Adding declarations to the '':left'' or '':right'' pseudo-class
	does not necessarily influence whether the document
	comes out of the printer double- or single-sided
	(which is outside the scope of this specification).</em>

</div>

<h4 id="first-pseudo">
First-page pseudo-class: '':first''</h4>

	The <dfn dfn-type="value" dfn-for="@page">:first</dfn> pseudo-class <a lt="match">matches</a>
	the first printed page of a document.

<div class="example">
<pre>
@page { margin: 2cm } /* All margins set to 2cm */

@page :first {
margin-top: 10cm /* Top margin on first page 10cm */
}
</pre>
</div>

<h4 id="blank-pseudo">
Blank-page pseudo-class: ''@page/:blank''</h4>

	The <dfn dfn-type="value" dfn-for="@page">:blank</dfn> pseudo-class <a lt="match">matches</a>
	<a lt="content-empty page">content-empty pages</a>
	that appear as a result of
	<a href="https://www.w3.org/TR/css3-break/#forced-breaks">forced page breaks</a>.

	<div class="note">
		Only the ''break-before/left'', ''break-before/right'', ''break-before/recto'' and ''break-before/verso'' values
		of the 'break-before' and 'break-after' properties
		can generate pages that match ''@page/:blank''.
	</div>

<div class="example">
In this example, forced page break may occur before <code>h1</code> elements.
<pre>
h1 { break-before: left }

@page :blank {
	@top-center { content: "This page is intentionally left blank" }
}
</pre>
</div>

	A page matched by ''@page/:blank'' can also be matched
	by other page pseudo-classes.

<div class="example">

If headers have been specified on all right pages, a blank right
page will be matched by both <code>:blank</code>
and <code>:right</code>. Therefore, margin boxes set on right pages
will have to be removed unless they are wanted on blank pages. Here is
an example where the top center header is removed from blank pages,
while the page number remains:

<pre>
h1 { break-before: left }

@page :blank {
	@top-center { content: none }
}

@page :right {
	@top-center { content: "Preliminary edition" }
	@bottom-center { content: counter(page) }
}
</pre>

Due to the higher <a>specificity</a> of <code>:blank</code>
over <code>:right</code>, the top center header is removed even
if <code>content: none</code> comes before <code>content: "Preliminary
edition"</code>.

</div>

<div class="note">
<em><strong>Note.</strong> Future versions of CSS may include other page
pseudo-classes.</em>
</div>

<h3 id="syntax-page-selector">@page rule grammar</h3>

''@page'' rules are [=CSS/parsed=] according to the following grammar,
plus the additional rules noted below:

<pre class=prod>
	@page = @page <<page-selector-list>>? { <<declaration-rule-list>> }
	<dfn><<page-selector-list>></dfn> = <<page-selector>>#
	<dfn><<page-selector>></dfn> = [ <<ident-token>>? <<pseudo-page>>* ]!
	<dfn><<pseudo-page>></dfn> = : [ left | right | first | blank ]

	/* Margin rules */
	<dfn>@top-left-corner</dfn> = @top-left-corner { <<declaration-list>> };
	<dfn>@top-left</dfn> = @top-left { <<declaration-list>> };
	<dfn>@top-center</dfn> = @top-center { <<declaration-list>> };
	<dfn>@top-right</dfn> = @top-right { <<declaration-list>> };
	<dfn>@top-right-corner</dfn> = @top-right-corner { <<declaration-list>> };
	<dfn>@bottom-left-corner</dfn> = @bottom-left-corner { <<declaration-list>> };
	<dfn>@bottom-left</dfn> = @bottom-left { <<declaration-list>> };
	<dfn>@bottom-center</dfn> = @bottom-center { <<declaration-list>> };
	<dfn>@bottom-right</dfn> = @bottom-right { <<declaration-list>> };
	<dfn>@bottom-right-corner</dfn> = @bottom-right-corner { <<declaration-list>> };
	<dfn>@left-top</dfn> = @left-top { <<declaration-list>> };
	<dfn>@left-middle</dfn> = @left-middle { <<declaration-list>> };
	<dfn>@left-bottom</dfn> = @left-bottom { <<declaration-list>> };
	<dfn>@right-top</dfn> = @right-top { <<declaration-list>> };
	<dfn>@right-middle</dfn> = @right-middle { <<declaration-list>> };
	<dfn>@right-bottom</dfn> = @right-bottom { <<declaration-list>> };
</pre>

In addition, the following rules apply:

* No whitespace is allowed between the productions in <<page-selector>> or <<pseudo-page>>
	(similar to the rule for <<compound-selector>>).
* The ''@page'' rule can only contain <a>page properties</a> and <a>margin at-rules</a>.
* The <a>margin at-rules</a> can only contain <a>page-margin properties</a>.



<div class="example">
The following are examples of page selectors (declaration block intentionally
left blank)
<pre>
@page { ... }
@page :left { ... }
@page :right { ... }
@page LandscapeTable { ... }
@page CompanyLetterHead:first { ... } /*  identifier and pseudo page. */
@page:first { ... }
@page toc, index { ... }
@page :blank:first { ... }
</pre>

The following are examples of page-margin boxes
where the declaration blocks are intentionally left blank.
<pre>
@page {
	@top-left { ... /* document name */ }
	@bottom-center { ... /* page number */}
}
@page :left { @left-middle { ... /* page number in left margin */ }}
@page :right{ @right-middle { ... /* page number in right margins of right pages */}}

@page :left { @bottom-left-corner { ... /* left page numbers */ }}
@page :right { @bottom-right-corner { ... /* right page numbers */ }}
@page :first { @bottom-left-corner { ... /* empty footer on 1st page */ }
@bottom-right-corner { ... /* empty footer */ } }
</pre>
</div>

<h3 id="cascading-and-page-context">Cascading in the page context</h3>

Declarations in page and margin contexts <a href="https://www.w3.org/TR/CSS2/cascade.html">cascade</a> just like declarations in style rule for elements.

The <dfn>specificity</dfn> of a page selector is computed in a manner
analogous to the computations defined in
the <a href="https://www.w3.org/TR/CSS2/selector.html">Selectors</a> module:

<ul>
	<li>Count the number of page type names (= <var>f</var>)
		<p class="note">
			Given the syntax of page selectors, <var>f</var> can only ever be 0 or 1.
	<li>Count the number of ':first' or ':blank' pseudo-classes (= <var>g</var>)
	<li>Count the number of ':left' or ':right' pseudo-classes (= <var>h</var>)
</ul>

<p class="note">
	Note: Repeated occurrences of the same pseudo-classes are allowed
	and do increase specificity.

	Due to storage limitations,
	implementations may have limitations on
	the size of <var>f</var>, <var>g</var>, or <var>h</var>.
	If so, values higher than the limit must be clamped to that limit,
	and not overflow.

	Specificities are compared by comparing the three components in order
	(<var>f</var>, <var>g</var>, <var>h</var>):
	the specificity with a larger <var>f</var> value is more specific;
	if the two <var>f</var> values are tied,
	then the two <var>g</var> values are compared, etc.
	If all the values are tied, the two specificities are equal.

<div class="example">

Some page specificity calculation examples follow:
<pre>
@page { } /* specificity = (0,0,0) */
@page :left { } /* specificity = (0,0,1) */
@page :first { } /* specificity = (0,1,0) */
@page :blank:left { } /* specificity = (0,1,1) */
@page artsy { } /* specificity = (1,0,0) */
@page artsy:left { } /* specificity = (1,0,1) */
@page artsy:first { } /* specificity = (1,1,0) */
</pre>
</div>

<div class="example">

Consider the following usage example:
<pre>
@page :left {
	margin-left: 4cm;
}

@page {
	margin-left: 3cm;
}
</pre>

Due to the higher specificity of the pseudo-class selector,
the left margin on left pages will be 4cm and all other pages
(the right-facing pages) will have a left margin of 3cm.
</div>

<div class="example">
In this example, the higher specificity of the green rules wins over the red
rule.
Therefore the first page will have blue text in the top-left page-margin box
and green text in the top-right page-margin box,
while subsequent pages will have red text in the page-margin boxes.
<pre>
@page :first {
	color: green;

	@top-left {
		content: "foo";
		color: blue;
	}
	@top-right {
		content: "bar";
	}
}

@page { color: red;
	@top-center {
		content: "Page " counter(page);
	}
}
</pre>
</div>

<div class="example">

Page contexts cascade, so the following stylesheet would style pages with 25
millimeter margins and 14 point type in the page-margin boxes:
<pre>
@page { margin: 25mm;}
@page { font-size: 14pt;}
</pre>
</div>

<h2 id="margin-boxes">Page-Margin Boxes</h2>

	Page-margin boxes are boxes within the page margin that,
	like pseudo-elements, can contain generated content.

	Page-margin boxes can be used to create page headers and footers,
	which are portions of the page set aside for supplementary information
	such as the page number or document title.

	<div class="example">
		Typically, a <dfn export>page header</dfn> is located at the top of the page
		in documents with a predominately horizontal writing direction
		and on the side opposite the <a>binding edge</a>
		for documents with a predominately vertical writing direction.
		One possible design of page headers for horizontally written documents uses the
		''@top-left-corner'', ''@top-left'', ''@top-center'', ''@top-right'' and ''@top-right-corner''
		page-margin boxes.
		Another design, for vertically written documents, could use the
		''@right-top'', ''@right-middle'', and ''@right-bottom'' page-margin boxes
		for <a lt="right page">right facing pages</a> and
		''@left-top'', ''@left-middle'', and ''@left-bottom''
		for <a lt="left page">left facing pages</a>.

		The <dfn export>page footer</dfn> is typically at
		the opposite end of the page from the page header.
		For example, the design of a horizontally written document with a page header
		at the top of the page could use the
		''@bottom-left-corner'', ''@bottom-left'', ''@bottom-center'', ''@bottom-right'' and ''@bottom-right-corner''
		page-margin boxes as the page footer.
		The design of a vertically written document could use
		the page-margin boxes of the binding edge of the page for the page footer.
	</div>

	Page-margin boxes are positioned with respect to the page area
	and are independent of page orientation,
	for example the top page-margin boxes are above the page area
	in both portrait and landscape orientation.
	The various page-margin boxes are defined
	and illustrated in the diagram below:

	<table id="margin-box-def" class="data">
		<caption>Table 1 Page-Margin Box Definitions</caption>
		<thead>
			<tr>
				<th>Box
				<th>Description
				<th>Placement

		<tbody>
			<tr id="top-margin-boxes-def">
				<th id="top-left-corner-box-def">top-left-corner
				<td>a fixed-size box defined by the intersection of the top and left margins of the
				page box
				<td><img src="images/TopLeftCornerBox.png" alt="the top left corner box with margin, border, and padding, nested within intersection of the page's top and left margins"
				height="47" width="181">

			<tr id="top-left-box-def">
				<th>top-left
				<td>a variable-width box filling the top page margin between the top-left-corner
				and top-center page-margin boxes
				<td><img src="images/TopLeftMarginBox.png" alt="the top left box with margin, border, and padding, nested in the page's top margin next to the top left corner box"
				height="47" width="181">

			<tr id="top-center-box-def">
				<th>top-center
				<td>a variable-width box centered horizontally between the page's left and right
				border edges and filling the page top margin between the top-left and top-right
				page-margin boxes
				<td><img src="images/TopCenterMarginBox.png" alt="the top center box with margin, border, and padding, centered within the page's top margin"
				height="47" width="181">

			<tr id="top-right-box-def">
				<th>top-right
				<td>a variable-width box filling the top page margin between the top-center and
				top-right-corner page-margin boxes
				<td><img src="images/TopRightMarginBox.png" alt="the top right box with margin, border, and padding, nested within the page's top margin"
				height="47" width="181">

			<tr>
				<th id="top-right-corner-box-def">top-right-corner
				<td>a fixed-size box defined by the intersection of the top and right margins of
				the page box
				<td><img src="images/TopRightCornerMarginBox.png" alt="the top right corner box with margin, border, and padding, nested within the intersection of the page's top and right margin"
				height="47" width="181">

			<tr id="left-margin-boxes-def">
				<th id="left-top-box-def">left-top
				<td>a variable-height box filling the left page margin between the top-left-corner
				and left-middle page-margin boxes
				<td rowspan="3"><img src="images/LeftMarginBoxes.png" alt="left-top, left-middle, and left-bottom page-margin boxes in the page box's left margin"
				height="226" width="181">

			<tr id="left-middle-box-def">
				<th>left-middle
				<td>a variable-height box centered vertically between the page's top and bottom
				border edges and filling the left page margin between the left-top and
				left-bottom page-margin boxes

			<tr id="left-bottom-box-def">
				<th>left-bottom
				<td>a variable-height box filling the left page margin between the left-middle and
				bottom-left-corner page-margin boxes

			<tr id="right-margin-boxes-def">
				<th id="right-top-box-def">right-top
				<td>a variable-height box filling the right page margin between the
				top-right-corner and right-middle page-margin boxes
				<td rowspan="3"><img src="images/RightMarginBoxes.png" alt="right-top, right-middle, and right-bottom page-margin boxes in the page box's right margin"
				height="226" width="181">

			<tr id="right-middle-box-def">
				<th>right-middle
				<td>a variable-height box centered vertically between the page's top and bottom
				border edges and filling the right page margin between the right-top and
				right-bottom page-margin boxes

			<tr id="right-bottom-box-def">
				<th>right-bottom
				<td>a variable-height box filling the right page margin between the right-middle
				and bottom-right-corner page-margin boxes

			<tr id="bottom-margin-boxes-def">
				<th id="bottom-left-corner-box-def">bottom-left-corner
				<td>a fixed-size box defined by the intersection of the bottom and left margins of
				the page box
				<td><img src="images/BottomLeftCornerBox.png" alt="bottom left corner box with margin, border, and padding, nested within the page margin at the intersection of the left and bottom page margins"
				height="48" width="181">

			<tr id="bottom-left-box-def">
				<th>bottom-left
				<td>a variable-width box filling the bottom page margin between the
				bottom-left-corner and bottom-center page-margin boxes
				<td><img src="images/BottomLeftMarginBox.png" alt="bottom left page-margin box with margin, border, and padding, nested within the page's bottom margin next to the bottom-left-corner box"
				height="48" width="181">

			<tr id="bottom-center-box-def">
				<th>bottom-center
				<td>a variable-width box centered horizontally between the page's left and right
				border edges and filling the bottom page margin between the bottom-left and
				bottom-right page-margin boxes
				<td style="vertical-align: middle;"><img src="images/BottomCenterMarginBox.png" alt="bottom center box with margin, border, and padding, nested within the page's bottom margin and centered on the page"
				height="48" width="181">

			<tr id="bottom-right-box-def">
				<th>bottom-right
				<td>a variable-width box filling the bottom page margin between the bottom-center
				and bottom-right-corner page-margin boxes
				<td><img src="images/BottomRightMarginBox.png" alt="bottom right page-margin box with margin, border, and padding, nested within the page's bottom margin and next to the bottom-right-corner box"
				height="48" width="181">

			<tr id="bottom-right-corner-box-def">
				<th>bottom-right-corner
				<td>a fixed-size box defined by the intersection of the bottom and right margins of
				the page box
				<td><img src="images/BottomRightCornerBox.png" alt="bottom right corner box with margin, border, and padding, nested within the page margin at the intersection of the right and bottom page margins"
				height="48" width="181">

	</table>

<h3 id="margin-at-rules">At-rules for page-margin boxes</h3>

Page-margin boxes are created by
<a>margin at-rules</a>
inside the <a href="#page-context">page context</a>.
Authors should put these rules after any declarations in the page context
as legacy clients may not handle declarations
after margin at-rules correctly.

A <dfn id="margin-at-rule">margin at-rule</dfn> is an <a>at-rule</a>
that identifies the page-margin box
(e.g. ''@top-left'') and a block of descriptors
(said to be in the <dfn export id="margin-context">margin context</dfn>).

<div class="example">

The following style sheet establishes a page header containing the title
("Hamlet") on the left side and the page number, preceded by "Page ", on the
right side:
<pre>
@page {
	size: 8.5in 11in;
	margin: 10%;

	@top-left {
		content: "Hamlet";
	}
	@top-right {
		content: "Page " counter(page);
	}
}
</pre>
</div>

<h3 id="populating-margin-boxes">Populating page-margin boxes</h3>

As with the '':before'' and '':after'' pseudo-elements,
a specified ''content: normal'' on a page-margin box computes to ''content/none''.
A page-margin box is <dfn>generated</dfn>
if and only if the computed value of its 'content' property is not ''content/none''.
Otherwise, no box is generated, as for elements with ''display: none''.

<p class=note>
	The 'display' property does not apply to page-margin boxes.

<div class="example">
The following style sheet creates a green box in each corner of the page
except the bottom-left corner.
<pre>
	@page {
		@top-left-corner { content: " "; border: solid green; }
		@top-right-corner { content: url(foo.png); border: solid green; }
		@bottom-right-corner { content: counter(page); border: solid green; }
		@bottom-left-corner { content: normal; border: solid green; }
	}
</pre>
</div>

<h3 id="margin-dimension">Computing Page-margin Box Dimensions</h3>

The width and height of each page-margin box is determined by the rules
below. These rules define the equivalent of CSS2.1 Sections 10.3 and
10.6 for page-margin boxes.

The rules for applying 'min-height', 'max-height', 'min-width', and
'max-width' [[!CSS2]] do apply to page-margin boxes and may imply
a recalculation of the width, height, and/or margins
if the dimensions resulting from the specified 'width' or 'height'
violate their constraints.
If the UA does not support the 'min-height' or 'min-width' properties
then it must behave as if 'min-height' and 'min-width' were always zero.

<h4 id="margin-box-terms" oldids="max-margin-dimension">
Page-Margin Box Layout Terminology</h4>

	In addition to the box model definitions in CSS2.1 [[!CSS2]],
	and the sizing terms in CSS Sizing [[!CSS-SIZING-3]],
	the following terms are defined for use
	in the subsequent page-margin box calculations:

	<dl export>
		<dt><dfn lt="available width|available page-margin width">available width</dfn>
		<dd>The sum of the page’s
			left border width, left padding, <a lt="page box">page area</a> width,
			right padding, and right border width.
			In other words, it is the distance between
			the <a>page box</a>’s left right border edges.
			This quantity is used  when calculating dimensions
			of the top and bottom page-margin boxes.

		<dt><dfn lt="available height|available page-margin height">available height</dfn>
		<dd>The sum of the page’s
			top border width, top padding, <a lt="page box">page area</a> height,
			bottom padding, and bottom border width.
			In other words, it is the distance between
			the <a>page box</a>’s top bottom border edges.
			This quantity is used when calculating dimensions
			of the left and right page-margin boxes.

		<dt><dfn lt="outer width|outer page-margin width">outer width</dfn>
		<dd>The width of the <a>outer edge</a>, as defined in [[!CSS-BOX-3]].

		<dt><dfn lt="min-content width|min-content page-margin width">min-content width</dfn>
		<dd>Whichever of <a spec=css-sizing>min-content block size</a>
		or <a spec=css-sizing>min-content inline size</a> is the physical width.

		<dt><dfn lt="max-content width|max-content page-margin width">max-content width</dfn>
		<dd>Whichever of <a spec=css-sizing>max-content block size</a>
		or <a spec=css-sizing>max-content inline size</a> is the physical width.

		<dt><dfn lt="outer min width|outer min page-margin width">outer min width</dfn>
		<dd>Like the <a>outer width</a>,
		except the <a>min-content width</a> is used when the computed 'width' is ''width/auto''.

		<dt><dfn lt="outer max width|outer max page-margin width">outer max width</dfn>
		<dd>Like the <a>outer width</a>,
		except the <a>max-content width</a> is used when the computed 'width' is ''width/auto''.
	</dl>

	The <dfn>containing block</dfn> for a page-margin box depends on its location:

	For a corner page-margin box,
	it is the rectangle defined by the intersection of the two page margins meeting at that corner.

	For all other page-margin boxes,
	the <a>containing block</a> is the rectangle
	formed by the encapsulating page margin minus the containing blocks of the
	adjacent corners' page-margin boxes.
	This means that the size of this containing block is given
	in one dimension by the used page margin and in the other dimension
	by the <a>available width</a>
	(for top and bottom page-margin boxes) or
	<a>available height</a>
	(for left and right page-margin boxes).

<h4 id="variable-sizing">
Page-Margin Box Variable Dimension Computation Rules</h4>

The following rules apply to ''@top-left'', ''@top-center'' and ''@top-right''
page-margin boxes,
which are referred to as A, B, and C, respectively, in this section.

<h5 id="variable-auto-margins">Margins</h5>

If the 'margin-left' or 'margin-right' property of any of the three boxes
computes to ''margin-left/auto'', the used value is zero.

<h5 id="variable-auto-sizing">Resolving ''width/auto'' widths</h5>

The following algorithm determines the used width of each box.
For this purpose, boxes that are not <a>generated</a>
are assumed to have a 'width' and an <a>outer width</a> of zero.

<p class="note">
Note: The high-level goals are (in order of priority) to center the middle
box (B) if it is generated, to minimize overflow and overlap, and to
distribute space proportionally to the amount of content.

	If the middle box (B) is not <a>generated</a>,
	distribute the <a>available width</a> to A and C as follows:

	<ul>
		<li>
			If only one box has 'width: auto',
			its used width is resolved so that
			the sum of the <a>outer width</a>s equals <a>available width</a>.

		<li id="flex-fit">
			If A and C both have 'width: auto', distribute the space to each box as follows:
			<ol>
				<li>If the sum of the outer <a>max-content widths</a> is less than the <a>available width</a>,
		call that difference the <dfn>flex space</dfn>.
		Calculate each box's <dfn>flex factor</dfn> as proportional to
		its outer <a>max-content width</a>,
		and set its used outer width to:
		<code><a>max-content width</a> + <a>flex space</a> × <a>flex factor</a> ÷ ∑<a>flex factors</a></code>
				<li>Otherwise if the sum of the outer <a>min-content widths</a> is less than the <a>available width</a>,
		call that difference the <a>flex space</a>
		calculate each box's <a>flex factor</a> as proportional to
		its <a>max-content width</a> minus <a>min-content width</a>,
		and set its used outer width to:
		<code><a>min-content width</a> + <a>flex space</a> × <a>flex factor</a> ÷ ∑<a>flex factors</a></code>
				<li>Otherwise,
		calculate its outer size as in the previous case,
		but set each box's <a>flex factor</a> as proportional to
		its outer <a>min-content width</a>.
			</ol>
			In each case, both <a>flex factors</a> are assumed to be ''1'' if their sum is equal to zero.

	</ul>

	If the middle box (B) is <a>generated</a>,
	determine the ''width/auto'' widths of A, B, and C as follows:

	<ol>
		<li>
			First, resolve any ''width/auto'' width of the middle box (B):
			Assume there are two boxes, B and AC,
			where each of AC's dimensions is double the maximum of A and C.
			(This preserves B's centering.)
			Distribute the space to these two boxes (B and the imaginary AC)
			as described for A and C <a href="#flex-fit">above</a>.
		<li>
			Then, resolve any ''width/auto'' widths of the side boxes (A and C)
			by setting that box's outer width to
			<code>(<a>available width</a> &minus; used <a>outer width</a>s of B) ÷ 2</code>

	</ol>

<h5 id="variable-minmax">Handling 'min-width' and 'max-width'</h5>

	The 'min-width' and 'max-width' properties [[CSS2]] apply to page-margin
	boxes in the variable dimension like on normal elements, except that the
	three boxes on the same side are considered together.


	More precisely:

<ol>
	<li>
		The tentative used widths are calculated
		(without 'min-width' and 'max-width') following the rules under
		[[#variable-auto-sizing]].

	<li>
		If the tentative used width of any of the three boxes
		is greater than 'max-width', the rules above are applied again,
		but this time using the computed value of 'max-width'
		as the computed value for 'width'.

	<li>
		If the resulting width of any of the three boxes
		is smaller than 'min-width', the rules above are applied again,
		but this time using the value of 'min-width'
		as the computed value for 'width'.

</ol>

<h5 id="variable-position">Positioning</h5>

	Once the dimensions of the boxes are determined,
	they are positioned as follows:

<ul>
	<li>The left outer edge of A is flush with the left edge of the
			containing block
	<li>The outer area of B is centered in the containing block.
	<li>The right outer edge of C is flush with the right edge of the
			containing block.
</ul>

<h5 id="variable-mapping">Boxes on other sides</h5>

The used values for ''@bottom-left'', ''@bottom-center'' and ''@bottom-right''
page-margin boxes are established by the same rules as
for ''@top-left'', ''@top-center'', and ''@top-right'', respectively.

The used values for ''@left-top'', ''@left-middle'' and ''@left-bottom'' boxes are
established by the same rules, with "width" replaced by "height", "left" by
"top", "right" by "bottom" and "center" by "middle".

The used values for ''@right-top'', ''@right-middle'' and ''@right-bottom''
page-margin boxes
are established by the same rules as for ''@left-top'', ''@left-middle'' and
''@left-bottom'', respectively.

<h4 id="fixed-sizing">Page-Margin Box Fixed Dimension Computation Rules</h4>

The rules below are used to calculate the used values of each
''@top-left-corner'', ''@top-left'', ''@top-center'', ''@top-right'', and
''@top-right-corner'' page-margin box's 'height', 'margin-top', and 'margin-bottom'
properties:

<ol>
	<li>
		The following constraint must hold among the used values of the margin
		box's properties:

		'margin-top' + 'border-top-width' + 'padding-top' + 'height' +
		'padding-bottom' + 'border-bottom-width' + 'margin-bottom' = top page margin

	<li>
		If 'border-top-width' + 'padding-top' + 'height' (if it is not ''height/auto'') + 'padding-bottom' + 'border-bottom-width',
		plus 'margin-top' and/or 'margin-bottom' if not ''margin-top/auto'',
		is larger than the height of the top page margin,
		then any ''margin-top/auto'' values for 'margin-top' or 'margin-bottom' are,
		for the following rules,
		treated as <<safe-printable-inset>>.

	<li>
		If at this point all of 'height', 'margin-top', and 'margin-bottom'
		have a computed value other than ''height/auto'', the values are said to be
		"over-constrained". In this case, the specified value of 'margin-top' is
		treated as ''margin-top/auto''.

	<li>
		If there is now exactly one value specified as <css>auto</css>, its used value
		follows from the equality.

	<li>
		If 'height' is set to ''height/auto'', any <css>auto</css> margin
		values become <<safe-printable-inset>> and 'height' follows from the
		resulting equality.

	<li>
		If both 'margin-top' and 'margin-bottom' are ''margin-top/auto'',
		their used values become equal.
		This vertically centers the page-margin box content
		within the top page margin.
		If <<safe-printable-inset>> is not ''0'' here, an additional adjustment step
		is performed: If the resulting 'margin-top' in the previous step became
		less than <<safe-printable-inset>>, subtract as much as possible of this
		difference from 'margin-bottom' without making it negative. Then add
		this value to 'margin-top'.
</ol>

	The same rules apply to the bottom page-margin boxes (bottom-left-corner,
	bottom-left, bottom-center, bottom-right, and bottom-right-corner), except that
	in the overconstrained case, the 'margin-bottom' is ignored rather than the
	'margin-top'.

	Analogous rules govern the properties for the left and right
	page-margin boxes with respect to 'width'
	(top-left-corner, left-top, left-middle, left-bottom, and
	bottom-left-corner; top-right-corner, right-top, right-middle, right-bottom,
	bottom-right-corner), with "top" replaced by "left", "bottom" replaced by
	"right", and "height" replaced by "width".
	In the overconstrained case for left (right) page-margin boxes,
	the specified value of 'margin-left' ('margin-right') is ignored.

<h3 id="margin-box-ex">
Page-margin box examples</h3>

	The following is a collection of examples of page-margin box usage.

	<div class="example">
		Here is an example of a page with only a top-left header:

		<pre>
		@page {
			@top-left { content: "Header in Left Cell (top-left)" }
		}
		</pre>

		Because there are no contents defined for the top-center or the top-right
		page-margin boxes, the extent of the top-left page-margin box
		is allowed to cross the center of the page box.

		<img alt="Header Example 1" src="images/header-ex-1.png" height="177" width="737">
	</div>

	<div class="example">
		The following is an example of a page with a centered header:

		<pre>
		@page {
			@top-center { content: "Header in Center Cell (top-center)" }
		}
		</pre>

		<img alt="Header Example 2" src="images/header-ex-2.png" height="177" width="737">
	</div>

	<div class="example">
		The following is an example of a page with a single header in the top-right
		page-margin box:

		<pre>
		@page {
			@top-right { content: "Header in Right Cell (top-right)" }
		}
		</pre>

		Because the content of the center cell is empty, the extent of the top-right
		page-margin box is allowed to cross the center of the page box.

		<img alt="Header Example 3" src="images/header-ex-3.png" height="177" width="737">
	</div>

	<div class="example">
		The following is an example of a page with a top-center and a top-left header:

		<pre>
		@page {
			@top-left { content: "Left Cell (top-left)" }
			@top-center { content: "Header in Center Cell (top-center)" }
		}
		</pre>

		<img alt="Header Example 4" src="images/header-ex-4.png" height="177" width="737">
	</div>

	<div class="example">
		The following is an example of a page with a top-center and a top-right header:

		<pre>
		@page {
			@top-center { content: "Header in Center Cell (top-center)" }
			@top-right { content: "Right Cell (top-right)" }
		}
		</pre>	margin: 10%;


		<img alt="Header Example 5" src="images/header-ex-5.png" height="177" width="737">
	</div>

	<div class="example">
		The following is an example of a page with top-left and top-right headers:

		<pre>
		@page {
			@top-left { content: "Header in top-left with approx. twice as many words as right cell." }
			@top-right { content: "Right cell (top-right)" }
		}
		</pre>

		Because there are no center cell contents, the extent of the top-left is
		allowed to cross the center of the page box.

		<img alt="Header Example 6" src="images/header-ex-6.png" height="177" width="737">
	</div>

<h2 id="page-properties">
Page Properties</h2>

	<a href="#properties-list">Appendix A</a> defines the normative list of CSS 2.1 [[!CSS2]]
	<a href="#page-property-list">properties that apply to page boxes</a>.
	If a conforming user agent supports any of these properties on block boxes,
	then it must also support that property
	in the <a>page context</a>.
	This specification additionally defines the '@page/size' property
	that only applies in the page context.

	Properties that apply to the page-margin boxes can also be set
	within the page context:
	if inheritable or explicitly inherited
	(with the ''inherit'' keyword in the margin context),
	they will inherit to the page-margin boxes.

	The same appendix defines the normative list of
	CSS 2.1 [[!CSS2]]
	<a href="#page-property-list">properties that apply to page-margin boxes</a>.
	If a conforming user agent supports any of these properties on block boxes,
	then it must also support that property
	in the <a>margin context</a>.

	Other properties defined by [[!CSS2]] do not apply in these contexts.
	Behavior for properties not included in CSS 2.1 is undefined.

	Note: The intent of leaving other properties undefined is to allow the gradual
	addition of appropriate CSS3 properties as they emerge, without having to
	update this specification with each addition.

	<a href="https://www.w3.org/TR/CSS2/cascade.html#value-stages">As with
	elements in the document</a>, both the page context and the margin context
	have a computed value for every property, even if that property does not
	apply to the page or page-margin box.

	The normal rules for CSS properties apply with the following exceptions:

	<ul>
		<li>
			page-margin boxes inherit from the page context.
			The page context inherits from the root element.
			However, since the previous revision of CSS Paged
			Media Level 3 did not specify this point, an implementation that sets
			inherited properties in the page context to their initial values (as for the
			root element) is also conformant to CSS Paged Media Level 3. Note that this
			exception will be removed in Level 4.

		<li>
			Values in units of ''em'' and ''ex'' are interpreted relative to the font
			associated with their context. When used on the 'font-size' property in the
			margin context, they are relative to the font of the page context. When used
			on the 'font-size' property in the page context, they are relative to the
			'font-size' of the root element. However, since a previous revision of CSS
			Paged Media Level 3 was ambiguous on this point, an implementation that
			treats ''em'' and ''ex'' on 'font-size' as relative to the initial value is
			also conformant to CSS Paged Media Level 3. Note that this exception will
			be removed in Level 4.

		<li>
			Percentage values on the margin and padding properties are relative to the
			dimensions of the containing block. For right and left values, percentages are
			relative to the width of the containing block; for top and bottom values,
			percentages are relative to the height of the containing block.

		<li>
			The used values of 'width' and 'height' have special computation rules
			for page boxes and page-margin boxes; see <a href="#page-size">Page Size</a>
			and <a href="#margin-dimension">Computing Page-Margin Box Dimensions</a>.

		<li>
			The page background is positioned and painted
			<a href="#painting">as described above</a>.
			<li>The rules for counter scoping are modified <a href="#page-based-counters">as
			described below</a>.

		<li>
			As on the '::before' and '::after' pseudo-elements,
			the ''content/normal'' value of the 'content' property computes to ''content/none''
			on page-margin boxes.

		<li>
			On page-margin boxes, the 'vertical-align' property behaves
			<a href="https://www.w3.org/TR/CSS2/tables.html#height-layout">as specified for table cells</a>.
			It <em>always</em> performs alignment in the vertical dimension,
			regardless of writing mode.
	</ul>

	User agents should establish a default
	page margin via the user agent stylesheet that includes any non-printable area.
	Authors should assume that the
	default page area will not include unprintable regions.

<h3 id="page-based-counters">
Page-based counters</h3>

	Counters can be defined and controlled within an ''@page''
	rule, and used as content in page-margin boxes.
	This is useful for maintaining a page count.

	A 'counter-increment' within either a page or margin context causes the counter
	to increment with the generation of each page box.

	If a counter is reset or incremented within the page context, it is in scope
	for all page-margin boxes and obscures all counters of the same name within the
	document.

	If a counter is reset or incremented within a margin context, it is in scope
	for that page-margin box and obscures any counters of the same name
	in both the page context and the document.

	If a counter that has not been reset or incremented within the margin context
	or the page context is used by counter() or counters() in the margin context,
	then the resultant value is exactly
	as if the page-margin box were an element within
	the document at the start of the page, inside the deepest element in the normal
	flow that spans the page break. Use of the counter in this way does not affect
	the calculation of the counter's value.

	A counter named <css>page</css> is automatically created
	and incremented by 1 on every page of the document,
	unless the 'counter-increment' property in the <a>page context</a>
	explicitly specifies a different increment for the <css>page</css> counter.
	The implied <css>page</css> counter is a real counter,
	and can be directly affected using the 'counter-increment' and 'counter-reset' properties
	when named explicitly in those properties.
	It can also be used in the 'counter()' and 'counters()' function forms.

	<div class="example">
		The following rules result in the placement of the current page number in the
		middle of the outside margin of each page.

		<pre>
		@page {
			margin: 10%;

			@top-center {
				font-family: sans-serif;
				font-weight: bold;
				font-size: 2em;
				content: counter(page);
			}
		}
		</pre>

		Adding the following rule will make all pages even-numbered.

		<pre>
		@page {
			counter-increment: page 2;
		}
		</pre>
	</div>

	Additionally, a counter named ''pages'' is automatically created by the UA.
	Its value is always the total number of pages in the document. (In continuous
	media this is always 1.) The value of ''pages'' cannot be manipulated: while
	'counter-reset' and 'counter-increment' statements that set it are valid, they
	have no effect.

	In all other respects, page-associated counters behave as described in [[!CSS2]],
	<a href="https://www.w3.org/TR/CSS2/generate.html#scope">Nested Counters and Scope</a> and
	<a href="https://www.w3.org/TR/CSS2/syndata.html#counter">Counters</a>.

<h3 id="margin-text-alignment">
Page-margin boxes and default values</h3>

	Properties used within page or margin contexts take their initial values from
	their respective property definitions; however, user agents must behave as
	though the values in the following table were established by rules in the UA
	default style sheet.

	<table id="margin-values" class="data">
		<caption>Table 2. Default values for Page-Margin Boxes</caption>
		<thead>
			<tr>
				<th>Page-margin box
				<th>'text-align'
				<th>'vertical-align'
		<tbody>
			<tr>
				<td><a href="#top-left-corner-box-def">top-left-corner</a>
				<td>right
				<td>middle
			<tr>
				<td><a href="#top-left-box-def">top-left</a>
				<td>left
				<td>middle
			<tr>
				<td><a href="#top-center-box-def">top-center</a>
				<td>center
				<td>middle
			<tr>
				<td><a href="#top-right-box-def">top-right</a>
				<td>right
				<td>middle
			<tr>
				<td><a href="#top-right-corner-box-def">top-right-corner</a>
				<td>left
				<td>middle
			<tr>
				<td><a href="#left-top-box-def">left-top</a>
				<td>center
				<td>top
			<tr>
				<td><a href="#left-middle-box-def">left-middle</a>
				<td>center
				<td>middle
			<tr>
				<td><a href="#left-bottom-box-def">left-bottom</a>
				<td>center
				<td>bottom
			<tr>
				<td><a href="#right-top-box-def">right-top</a>
				<td>center
				<td>top
			<tr>
				<td><a href="#right-middle-box-def">right-middle</a>
				<td>center
				<td>middle
			<tr>
				<td><a href="#right-bottom-box-def">right-bottom</a>
				<td>center
				<td>bottom
			<tr>
				<td><a href="#bottom-left-corner-box-def">bottom-left-corner</a>
				<td>right
				<td>middle
			<tr>
				<td><a href="#bottom-left-box-def">bottom-left</a>
				<td>left
				<td>middle
			<tr>
				<td><a href="#bottom-center-box-def">bottom-center</a>
				<td>center
				<td>middle
			<tr>
				<td><a href="#bottom-right-box-def">bottom-right</a>
				<td>right
				<td>middle
			<tr>
				<td><a href="#bottom-right-corner-box-def">bottom-right-corner</a>
				<td>left
				<td>middle
	</table>

	<div class="example">
		This example style sheet could be used to create a centered header with the
		current chapter name:

		<pre>
		body {counter-reset: chapter;}
		div.chapter {counter-increment: chapter;}
		@page {
			margin: 10%;
			@top-center { content: "Chapter" counter(chapter) }
		}
		</pre>
	</div>

<h2 id="page-size">
Page Size</h2>

	People around the world use many different paper sizes. It is a goal of this
	specification that web content should be adaptable to a range of different
	sizes without having to write a specific style sheet for each paper size.

	However, in some situations it is important that a certain page size achieves a
	certain style. One way to achieve this goal is to utilize the '@page/size' property,
	which indicates that the document should preferentially be displayed on a
	surface of a certain size; another method is to use Media Queries [[MEDIAQ]]
	which allow different style sheets to be applied to different page sizes.

<h3 id="page-size-prop">
Page size: the '@page/size' property</h3>

	<pre class=descdef>
	Name: size
	For: @page
	Value: <<length [0,∞]>>{1,2} | auto | [ <<page-size>> || [ portrait | landscape ] ]
	Initial: auto
	Computed value: specified value, with <<length>>s made absolute.
	</pre>

	This property specifies the target size and orientation of the
	<a>page box</a>’s containing block.
	In the general case, where one page box is rendered onto one <a>page sheet</a>,
	the '@page/size' property also indicates the size of the destination page sheet.

	The size of a page box can either be "absolute" (fixed size) or "scalable"
	(i.e., fitting available sheet sizes).
	The first three values in the table below can be used to create scalable page
	boxes.
	Other values define a fixed-size page box, and thereby indicate the preferred
	output media size. When possible, output should be rendered on the media size
	indicated.
	If the specified size is not available, the rules for
	<a href="#renderingpages">transposing a page box to a different size</a>
	apply.

	If a '@page/size' property declaration is qualified by a ''width'',
	''height'', ''device-width'', ''device-height'', ''aspect-ratio'',
	''device-aspect-ratio'' or ''orientation''
	media query [[!MEDIAQ]] (or other conditional on the size of the paper), then
	the declaration must be
	<a href="https://www.w3.org/TR/CSS2/conform.html#ignore">ignored</a>. Media
	queries do not honor '@page/size': they assume the paper size that would be chosen
	if no ''@page'' rules were specified.

	<div class=issue>
		It would be useful if media queries could respond at least
		to sizes specified on an unqualified @page.

		Another option could be to do like ''@viewport'' rules
		[[CSS-DEVICE-ADAPT]]:
		First apply ''@page'' rules (matching which selectors?),
		using the UA’s default page size for Media Queries and
		<a href="https://www.w3.org/TR/css3-values/#viewport-relative-lengths">viewport-percentage lengths</a>
		[[CSS-VALUES-3]].
		The resulting page size is the "base page size".
		The entire set of stylesheets is applied again,
		this time using the "base page size" for Media Queries
		and viewport-percentage lengths.
	</div>

	<div class="example">
		In the following example

		<pre>
		@page {
			size: 4in 6in;
		}

		@media (max-width: 6in) {
			@page {
				size: letter;
			}
		}
		</pre>

		The second <code>size</code> declaration is ignored, i.e. the specified value
		of the <code>size</code> property is <code>4in 6in</code>.
	</div>

	<dl dfn-type=value dfn-for="@page/size">
		<dt><dfn>auto</dfn>
		<dd>
			The page box will be set to a size and orientation chosen by the UA. In the
			usual case, the page box size and orientation is chosen to match the target
			media sheet.

		<dt><dfn>landscape</dfn>
		<dd>
			Specifies that the page's content be printed in landscape orientation. The
			longer sides of the page box are horizontal. If a <<page-size>> is not specified, the size of the page sheet
			is chosen by the UA.

		<dt><dfn>portrait</dfn>
		<dd>
			Specifies that the page's content be printed in portrait orientation. The
			shorter sides of the page box are horizontal. If a <<page-size>> is not specified, the size of the page sheet
			is chosen by the UA.

		<dt><dfn><<length [0,∞]>></dfn>
		<dd>
			The page box will be set to the given absolute dimension(s). If only one length
			value is specified, it sets both the width and height of the page box (i.e.,
			the box is a square). If two length values are specified, the first establishes
			the page box width, and the second the page box height. Values in units of
			''em'' and ''ex'' refer to the
			page context's font. Negative lengths are illegal.

		<dt><dfn type><<page-size>></dfn>
		<dd>
			A page size can be specified using one of the following media names. This is
			the equivalent of specifying '@page/size'
			using length values. The definition of the media names comes from
			Media Standardized Names [[!PWGMSN]].

			<dl dfn-type=value dfn-for="<page-size>">
				<dt><dfn>A5</dfn>
				<dd>Equivalent to the size of ISO A5 media: 148mm wide and 210 mm high.

				<dt><dfn>A4</dfn>
				<dd>Equivalent to the size of ISO A4 media: 210 mm wide and 297 mm high.

				<dt><dfn>A3</dfn>
				<dd>Equivalent to the size of ISO A3 media: 297mm wide and 420mm high.

				<dt><dfn>B5</dfn>
				<dd>Equivalent to the size of ISO B5 media: 176mm wide by 250mm high.

				<dt><dfn>B4</dfn>
				<dd>Equivalent to the size of ISO B4 media: 250mm wide by 353mm high.

				<dt><dfn>JIS-B5</dfn>
				<dd>Equivalent to the size of JIS B5 media: 182mm wide by 257mm high.

				<dt><dfn>JIS-B4</dfn>
				<dd>Equivalent to the size of JIS B4 media: 257mm wide by 364mm high.

				<dt><dfn>letter</dfn>
				<dd>Equivalent to the size of North American letter media: 8.5 inches wide and 11 inches high

				<dt><dfn>legal</dfn>
				<dd>Equivalent to the size of North American legal: 8.5 inches wide by 14 inches high.

				<dt><dfn>ledger</dfn>
				<dd>Equivalent to the size of North American ledger: 11 inches wide by 17 inches high.
			</dl>
	</dl>

	The <<page-size>> names can be used in conjunction with ''landscape'' or
	''portrait'' to indicate both size and orientation.

	<div class="example">
		<pre>
		@page {
		size: A4 landscape;
		}
		</pre>

		The above example sets the width of the page box to be 297mm and the height to
		be 210mm. The page box in this example should be rendered on a page sheet size
		of 210 mm by 297 mm.
	</div>

<div class="example">
	In the following example, the outer edges of the page box will align with the
	page. The percentage value on the <span class="property">'margin'</span>
	property is relative to the page size so if the page sheet dimensions are 210mm
	x 297mm (i.e., A4), the margins are 21mm and 29.7mm. Assuming there are no page
	borders or padding set in the UA default style sheet, the resulting page area
	is 189mm by 267.3mm (210mm-21mm by 297mm-29.7mm).

	<pre>
	@page {
	size: auto;/* auto is the initial value */
	margin: 10%;
	}
	</pre>
</div>

<div class="example">
	<pre>
	@page {
	size: 8.5in 11in;/* width height */
	}
	</pre>

	The above example sets the width of the page box to be 8.5 inches and the
	height to be 11 inches. This indicates that the page sheet size should be
	8.5"x11" and the orientation ''portrait''.
</div>

<h4 id="page-size-media-query">
Media Queries</h4>

	<em>This section is informative.</em>

	By using Media Queries [[MEDIAQ]], one style sheet can express different
	stylistic preferences for different page sizes. Consider this example:

	<div class="example" style="font-size: 10pt;">
		<pre>
		/* style sheet for "A4" printing */
		@media print and (width: 21cm) and (height: 29.7cm) {
			@page {
				 margin: 3cm;
			}
		 }

		/* style sheet for "letter" printing */
		@media print and (width: 8.5in) and (height: 11in) {
			@page {
			margin: 1in;
			}
		}
		</pre>
	</div>

	In the example above, "A4" sheets are given a "3cm" page margin, and "letter"
	sheets are given a "1in" page margin.

<h4 id="page-orientation-prop">
Rotating The Printed Page: the '@page/page-orientation' property</h4>

	<pre class=descdef>
	Name: page-orientation
	For: @page
	Value: upright | rotate-left | rotate-right
	Initial: upright
	Computed Value: as specified
	</pre>

	High-quality printing implementations
	can handle pages of varying sizes and orientations,
	so an author can choose the size of a page
	according to what's best for that page's content.
	For example,
	they might use ''size: letter portrait;'' for most pages in a document,
	but switch to ''size: letter landscape;''
	to lay out a wide information table.

	However, handling content flowing across pages of differing widths
	is a relatively complex task,
	and is not yet solved in many popular printing implementations
	(notably, web browsers).
	The '@page/page-orientation' descriptor is intended to help such implementations,
	allowing them to lay out pages in a single consistent size,
	but change the orientation post-layout
	in the output medium
	(such as PDF),
	so that pages which want to be displayed in a different orientation
	can do so.

	Its values are defined as:

	<dl dfn-type=value dfn-for=page-orientation>
		: <dfn>upright</dfn>
		:: No special orientation is applied;
			the page is laid out and formatted as normal.

		: <dfn>rotate-left</dfn>
		:: After the page has been laid out,
			if the output medium supports rotation,
			this value indicates that the page must be displayed
			rotated a quarter turn to the left
			(counter-clockwise)
			of how it was laid out.

		: <dfn>rotate-right</dfn>
		:: Same as ''rotate-left'',
			except the page must be displayed
			rotated a quarter turn to the right
			(clockwise)
			of how it was laid out.
	</dl>

	Note: Margin boxes and other positional things
	have no special interaction with this property;
	they'll be laid out as normal in the unrotated page,
	then rotated along with everything else.

	<div class=note>
		This property is intended as a stop-gap
		for less-capable implementations,
		allowing them to still print documents
		with a mix of portrait and landscape orientations
		before they have the ability
		to flow content across differently-size pages.
		It requires some awkward contortions to use,
		such as specifying that a wide table containing only English
		actually has a vertical 'writing-mode'
		so it'll lay out "sideways",
		but be rotated back to upright for readability
		in the printed output.

		There should be no need to use this property
		in high-quality printing implementations;
		instead, use '@page/size' to control ''portrait'' vs ''landscape'' orientation of a page.
	</div>


<h3 id="marks">
Crop and Registration Marks: the '@page/marks' property</h3>

	<pre class='descdef'>
	Name: marks
	For: @page
	Value: none | [ crop || cross ]
	Initial: none
	Computed Value: as specified
	</pre>

	This property adds crop and/or registration marks to the document.
	These are printed outside the page box to facilitate
	the trimming and alignment of sheets of paper.
	Values have the following meanings:

	<dl dfn-type=value dfn-for="@page/marks">
		<dt><dfn>none</dfn>
		<dd>
			Specifies that neither crop marks nor registration marks should be printed:
			the area outside the <a>bleed area</a> will be completely blank.
		<dt><dfn>crop</dfn>
		<dd>
			Specifies that crop marks should be printed.
			These are typically short lines outside the page box
			that are effectively extensions of the page box's four edges,
			thereby indicating the precise location of those edges
			without placing any ink near or within the page box itself.
		<dt><dfn>cross</dfn>
		<dd>
			Specifies that registration marks should be printed.
			These are typically cross-shaped marks outside each edge of the page box
			used to align sheets of paper during the printing process.
	</dl>

	Note that crop marks and registration marks are only visible
	if the page box is smaller than the printable area.

	<div class="example">
		To set crop and cross marks on a document, this code can be used:

		<pre>
		@page { marks: crop cross }
		</pre>
	</div>

<h3 id="bleed">
Bleed Area: the '@page/bleed' property</h3>

	<pre class='descdef'>
	Name: bleed
	For: @page
	Value: auto | <<length>>
	Initial: auto
	Computed Value: as specified
	</pre>

	This property specifies the extent of the <dfn>bleed area</dfn> outside the page box;
	in other words the extent beyond the page box at which the page rendering is clipped.
	Values have the following meanings:

	<dl dfn-for="@page/bleed" dfn-type=value>
		<dt><dfn>auto</dfn>
		<dd>
			Computes to ''6pt'' if '@page/marks' has ''crop'' and to zero otherwise.

		<dt><dfn><<length>></dfn>
		<dd>
			Specifies by how far outward, in each direction,
			the <a>bleed area</a> extends past the <a>page box</a>.
			Values may be negative, but there may be implementation-specific limits.
	</dl>

<h3 id="renderingpages">
Rendering page boxes that do not fit a page sheet</h3>

	If a page box does not match the target page sheet dimensions, the user agent
	should do one of the following (in order of preference):

	<ol>
		<li>Render the page box at the indicated size on a larger page sheet.
		<li>Rotate the page box 90° if this will make the page box fit the page sheet.
		<li>Scale the page box to fit the page sheet. (The aspect ratio of the page box
		should be preserved.)
		<li>Graphically "slice" the page box onto multiple page sheets.
		<li>Clip overflowed content (least preferred).
	</ol>

	The user agent may wish to consult the user before
	performing these operations.

<h3 id="positioning-page-box">
Positioning the page box on the sheet</h3>

	When the page box is smaller than the page sheet, the user agent should either:

	<ul>
		<li>center the page box on the sheet since this will align double-sided pages
		and avoid accidental loss of information that is printed near the edge of the
		sheet; or
		<li>position the page box in the upper left corner of the page sheet
		(or another corner,
		based on the 'direction' and 'writing-mode' properties of the page box)
		as this may minimize media consumption.
	</ul>

	The user agent may wish to consult the user in this
	regard.<!-- "Page selector and page context" -->

<h3 id="page-margin-safety">
Staying within the printable area: the '@page/page-margin-safety' property</h3>

	<pre class='descdef'>
	Name: page-margin-safety
	For: @page
	Value: none | clamp | add
	Initial: auto
	Computed Value: as specified
	</pre>

	<div class=issue>
		<p>
			The "For:" field above should also include the at-rules
			@top-left-corner, @top-left, @top-center, @top-right,
			@top-right-corner, @right-top, @right-middle,
			@right-bottom, @bottom-right-corner, @bottom-right,
			@bottom-center, @bottom-left, @bottom-left-corner,
			@left-bottom, @left-middle, @left-top.
		</p>
		<p>However, multiple at-rules here are currently not supported by bikeshed.</p>
	</div>

	Most printers have a small region along each edge of the page sheet
	which is unprintable, typically due to the printer's paper handling
	mechanism. This property can be used to help staying within the
	<a>printable area</a>, by adjusting the page margins and page margin box
	margins.

	Some printers don't have a uniform unprintable area width along each of
	the four paper edges, and the printer may rotate the print output at
	their own discretion. The user agent may therefore not be able to make
	assumptions about which edge will be fed first into the printer, or what
	orientation the sheet of paper has. If the user agent cannot make such
	assumptions, only one will be provided (to be used on all 4 sides): The
	larger of these four values. Otherwise, if the user agent can trust that
	the four values are usable individually, and that no rotation is going
	to take place, and so on, each side of the page may have individual
	values.

	Let this value be <dfn><<safe-printable-inset>></dfn>, which is a <<length>>.

	This property only affects margins that are adjacent to one of the edges
	of a sheet. For all other margins, i.e. those margins facing the
	page's <a>page area</a>, its value is 0. In other words, when
	page-margin-safety is specified in a margin context, it will only have
	an effect at one or two sides. For instance, @page { @top-right-corner {
	page-margin-safety: clamp; } } may only clamp top and right margin
	values, as the bottom and left margins face the document's contents, not
	the page's edges.

	<dl dfn-for="@page/page-margin-safety" dfn-type=value>
		<dt><dfn>none</dfn></dt>
		<dd>Margins are not affected by unprintable regions</dd>
		<dt><dfn>clamp</dfn></dt>
		<dd>
			The used margin values will be the maximum of the
			resolved value, and <<safe-printable-inset>> for the
			given side.
		</dd>
		<dt><dfn>add</dfn></dt>
		<dd>
			The used margin values will be the resolved value, plus
			<<safe-printable-inset>> for the given side.
		</dd>
	</dl>

<h2 id="page-breaks">
		<span id="pg-br-before-after"></span>
		<span id="page-break-before"></span>
		<span id="page-break-after"></span>
		<span id="page-break-inside"></span>
		<span id="breaks-inside"></span>
		<span id="orphans"></span>
		<span id="widows"></span>
		<span id="allowed-pg-brk"></span>
		<span id="brk-btw-blocks"></span>
		<span id="brk-btw-lines"></span>
		<span id="brk-end-block"></span>
		<span id="forced-pg-brk"></span>
		<span id="best-pg-brk"></span>
		Page Breaks
</h2>

	The CSS Fragmentation Module [[!CSS-BREAK-3]] module
	defines how and where CSS boxes
	can be <em>fragmented</em>, including across page breaks.
	It defines a few properties that indicate where the user agent
	may or must break pages,
	and on what page (left or right) the subsequent content resumes.
	Each page break ends layout in the current <a>page box</a>
	and causes remaining pieces of the document tree to be laid out
	in a new page box.

<h3 id="using-named-pages">
Using named pages: 'page'</h3>

	<pre class=propdef>
	Name: page
	Value: auto | <<custom-ident>>
	Initial: auto
	Applies to: boxes that create <a href="https://www.w3.org/TR/css3-break/#btw-blocks">class A</a> break points
	Inherited: no (but see prose)
	Percentages: n/a
	Computed value: specified value
	Animation type: discrete
	</pre>

	The 'page' property is used to specify a particular type of page (called a <dfn export>named page</dfn>)
	on which an element must be displayed.
	If necessary, a <a lt="forced break" spec=css-break>forced page break</a> is introduced
	and a new page generated of the specified type.

	Note: This page can be styled by using the same type name
	in a <a href="#page-selectors">page selector</a>.

	Page type names are case-sensitive identifiers.
	However the ''page/auto'' value, being a CSS keyword, is
	<a href="https://www.w3.org/TR/CSS2/syndata.html#characters">ASCII case-insensitive</a>.

	The 'page' property does not inherit.
	However, if the 'page' value on an element is ''page/auto'',
	then its used value is the value specified
	on its nearest ancestor with a non-auto value.
	When specified on the root element,
	the used value for ''page/auto'' is the empty string.

	<!-- See https://www.w3.org/TR/2007/WD-css3-gcpm-20070504/#named3 -->

	Because a previous version of this specification
	indicated that the 'page' property is inherited,
	an implementation that inherits the 'page' property
	and treats ''page/auto'' as always naming the empty string
	remains conformant to CSS Paged Media Level 3.
	Note that this exception will be removed in Level 4.
	Therefore authors should not explicitly specify the ''page/auto'' value
	on a descendant of an element with a non-''page/auto'' value,
	as the resulting behavior will be unpredictable.

	The 'page' property works as follows:

	<ol>
		<li>
			First, any ''page/auto'' values are resolved against non-''page/auto'' ancestors
			(as specified above).

		<li>
			Next,
			a <dfn>start 'page' value</dfn> and <dfn>end 'page' value</dfn>
			is determined for each box
			as the value (if any) propagated from
			its first or last child box (respectively),
			else the used value on the box itself.
			A child propagates its own
			<a lt="start page value">start</a> or <a>end page value</a>
			if and only if the 'page' property applies to it.

			Note: A first or last child <em>box</em> is not always generated by
			a first or last child <em>element</em>.
			For example,
			an element could only have a previous sibling with 'display: none'
			which does not generate any box.

		<li>
			The first printed page’s type is the <a>start page value</a> of the root.

		<li>
			If for any two boxes meeting at a <a href="https://www.w3.org/TR/css3-break/#btw-blocks">class A</a> break point,
			the <a>end page value</a> of the box preceding the break
			and <a>start page value</a> of the box succeeding the break
			do not match,
			then a page break is forced between the two boxes,
			and content after the break resumes on a page box of the named type.
	</ol>

	Note: Essentially, the two 'page' values compared are those from the deepest boxes
	meeting at the <a href="https://www.w3.org/TR/css3-break/#btw-blocks">class A break point</a>,
	ignoring any subtrees rooted by boxes to which the 'page' property does not apply.

	See [[!CSS-BREAK-3]] for additional details on page breaks.

	<div class="example">
		In this example, the two tables are rendered on landscape pages (indeed, on the
		same page, if they fit). The page type "narrow" is used for the &lt;p&gt; after
		the second table, as the page properties for the table element are no longer in
		effect:

		<pre>
		@page narrow { size: 9cm 18cm }
		@page rotated { size: landscape }
		div { page: narrow }
		table { page: rotated }
		</pre>with this document:

		<pre>
		&lt;div&gt;
		&lt;table&gt;...&lt;/table&gt;
		&lt;table&gt;...&lt;/table&gt;
		&lt;p&gt;This text is rendered on a 'narrow' page&lt;/p&gt;
		&lt;/div&gt;
		</pre>
	</div>

	<div class="example">
		In Japanese documents, sometimes different parts of a single document
		will have different <em lang="ja-Latn">kihon hanmen</em>. [[JLREQ]]
		The 'page' property, together with ''@page'' rules specifying different page widths,
		can accommodate this type of layout:
		<pre>
		&lt;!DOCTYPE html>
		&lt;html lang="ja">
			&lt;style>
				html   {
					writing-mode: vertical-rl;
					line-height: 1.6;
				}
				.main  {
					page: main;
					columns: 2;
					column-gap: 1rem;
				}
				.index {
					page: index;
					columns: 3;
					column-gap: 1rem;
				}
				@page {
					margin: auto;  /* center kihon hanmen on page */
					width:  40rem; /* 1.6 &times; 25 lines        */
				}
				@page main  { height: 61rem; } /* 2 &times; 30 chars + 1 &times; gap */
				@page index { height: 62rem; } /* 3 &times; 20 chars + 2 &times; gap */
			&lt;/style>
			&lt;section class="main"> ... &lt;/section>
			&lt;section class="index"> ... &lt;/section>
		&lt;/html>
		</pre>
	</div>

<h2 id="image-properties">
Image Properties</h2>

	Note: This section has been moved to [[CSS-IMAGES-3]].

<h2 class="no-num" id="properties-list">
Appendix A: Applicable CSS2.1 Properties</h2>

<h3 class="no-num" id="page-property-list">
	CSS 2.1 Properties that apply within the page context</h3>

	This list defines the <dfn export lt="page property">page properties</dfn>.
	They are further described in [[#page-properties]].

	<table class="data">
		<tbody>
			<tr>
				<td><a href="https://www.w3.org/TR/CSS2/visuren.html#direction">bidi properties</a>
				<td>direction
		<tbody>
			<tr>
				<td rowspan="6"><a href="https://www.w3.org/TR/CSS2/colors.html#background-properties">background properties</a>
				<td>background-color
			<tr><td>background-image
			<tr><td>background-repeat
			<tr><td>background-attachment
			<tr><td>background-position
			<tr><td>background
		<tbody>
			<tr>
				<td rowspan="20"><a href="https://www.w3.org/TR/CSS2/box.html#border-properties">border properties</a>
				<td>border-top-width
			<tr><td>border-right-width
			<tr><td>border-bottom-width
			<tr><td>border-left-width
			<tr><td>border-width
			<tr><td>border-top-color
			<tr><td>border-right-color
			<tr><td>border-bottom-color
			<tr><td>border-left-color
			<tr><td>border-color
			<tr><td>border-top-style
			<tr><td>border-right-style
			<tr><td>border-bottom-style
			<tr><td>border-left-style
			<tr><td>border-style
			<tr><td>border-top
			<tr><td>border-right
			<tr><td>border-bottom
			<tr><td>border-left
			<tr><td>border
		<tbody>
			<tr>
				<td rowspan="2"><a href="https://www.w3.org/TR/CSS2/generate.html#counters">counter properties</a>
				<td>counter-reset
			<tr><td>counter-increment
		<tbody>
			<tr>
				<td colspan="2"><a href="https://www.w3.org/TR/CSS2/colors.html#propdef-color">color</a>
		<tbody>
			<tr>
				<td rowspan="6"><a href="https://www.w3.org/TR/CSS2/fonts.html">font properties</a>
				<td>font-family
			<tr><td>font-size
			<tr><td>font-style
			<tr><td>font-variant
			<tr><td>font-weight
			<tr><td>font
		<tbody>
			<tr>
				<td rowspan="3"><a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">height</a> <a href="https://www.w3.org/TR/CSS2/visudet.html#min-max-heights">properties</a>
				<td>height
			<tr><td>min-height
			<tr><td>max-height
		<tbody>
			<tr>
				<td colspan="2"><a href="https://www.w3.org/TR/CSS2/visudet.html#line-height">line-height</a>
		<tbody>
			<tr>
				<td rowspan="5"><a href="https://www.w3.org/TR/CSS2/box.html#margin-properties">margin properties</a>
				<td>margin-top
			<tr><td>margin-right
			<tr><td>margin-bottom
			<tr><td>margin-left
			<tr><td>margin
		<tbody>
			<tr>
				<td rowspan="4"><a href="https://www.w3.org/TR/CSS2/ui.html#dynamic-outlines">outline properties</a>
				<td>outline-width
			<tr><td>outline-style
			<tr><td>outline-color
			<tr><td>outline
		<tbody>
			<tr>
				<td rowspan="5"><a href="https://www.w3.org/TR/CSS2/box.html#padding-properties">padding properties</a>
				<td>padding-top
			<tr><td>padding-right
			<tr><td>padding-bottom
			<tr><td>padding-left
			<tr><td>padding
		<tbody>
			<tr>
				<td colspan="2"><a href="https://www.w3.org/TR/CSS2/generate.html#quotes-specify">quotes</a>
		<tbody>
			<tr>
				<td rowspan="7"><a href="https://www.w3.org/TR/CSS2/text.html">text properties</a>
				<td>letter-spacing
			<tr><td>text-align
			<tr><td>text-decoration
			<tr><td>text-indent
			<tr><td>text-transform
			<tr><td>white-space
			<tr><td>word-spacing
		<tbody>
			<tr>
				<td colspan="2"><a href="https://www.w3.org/TR/CSS2/visufx.html#visibility">visibility</a>
		<tbody>
			<tr>
				<td rowspan="3"><a href="https://www.w3.org/TR/CSS2/visudet.html#the-width-property">width</a> <a href="https://www.w3.org/TR/CSS2/visudet.html#min-max-widths">properties</a>
				<td>width
			<tr><td>min-width
			<tr><td>max-width
	</table>

<h3 class="no-num" id="margin-property-list">
CSS 2.1 properties that apply within the margin contexts</h3>

	This list defines the <dfn export lt="page-margin property">page-margin properties</dfn>.
	They are further described in [[#page-properties]].

	<table class="data">
		<tbody>
			<tr><td rowspan="2"><a href="https://www.w3.org/TR/CSS2/visuren.html#direction">bidi properties</a>
				<td>direction
			<tr><td>unicode-bidi
		<tbody>
			<tr><td rowspan="6"><a href="https://www.w3.org/TR/CSS2/colors.html#background-properties">background properties</a>
				<td>background-color
			<tr><td>background-image
			<tr><td>background-repeat
			<tr><td>background-attachment
			<tr><td>background-position
			<tr><td>background
		<tbody>
			<tr><td rowspan="20"><a href="https://www.w3.org/TR/CSS2/box.html#border-properties">border properties</a>
				<td>border-top-width
			<tr><td>border-right-width
			<tr><td>border-bottom-width
			<tr><td>border-left-width
			<tr><td>border-width
			<tr><td>border-top-color
			<tr><td>border-right-color
			<tr><td>border-bottom-color
			<tr><td>border-left-color
			<tr><td>border-color
			<tr><td>border-top-style
			<tr><td>border-right-style
			<tr><td>border-bottom-style
			<tr><td>border-left-style
			<tr><td>border-style
			<tr><td>border-top
			<tr><td>border-right
			<tr><td>border-bottom
			<tr><td>border-left
			<tr><td>border
		<tbody>
			<tr><td rowspan="2"><a href="https://www.w3.org/TR/CSS2/generate.html#counters">counter properties</a>
				<td>counter-reset
			<tr><td>counter-increment
		<tbody>
			<tr><td colspan="2">content
		<tbody>
			<tr><td colspan="2"><a href="https://www.w3.org/TR/CSS2/colors.html#propdef-color">color</a>
		<tbody>
			<tr><td rowspan="6"><a href="https://www.w3.org/TR/CSS2/fonts.html">font properties</a>
				<td>font-family
			<tr><td>font-size
			<tr><td>font-style
			<tr><td>font-variant
			<tr><td>font-weight
			<tr><td>font
		<tbody>
			<tr><td rowspan="3"><a href="https://www.w3.org/TR/CSS2/visudet.html#the-height-property">height</a> <a href="https://www.w3.org/TR/CSS2/visudet.html#min-max-heights">properties</a>
				<td>height
			<tr><td>min-height
			<tr><td>max-height
		<tbody>
			<tr><td colspan="2"><a href="https://www.w3.org/TR/CSS2/visudet.html#line-height">line-height</a>
		<tbody>
			<tr><td rowspan="5"><a href="https://www.w3.org/TR/CSS2/box.html#margin-properties">margin properties</a>
				<td>margin-top
			<tr><td>margin-right
			<tr><td>margin-bottom
			<tr><td>margin-left
			<tr><td>margin
		<tbody>
			<tr><td rowspan="4"><a href="https://www.w3.org/TR/CSS2/ui.html#dynamic-outlines">outline properties</a>
				<td>outline-width
			<tr><td>outline-style
			<tr><td>outline-color
			<tr><td>outline
		<tbody>
			<tr><td colspan="2"><a href="https://www.w3.org/TR/CSS2/visufx.html#overflow">overflow</a>
		<tbody>
			<tr><td rowspan="5"><a href="https://www.w3.org/TR/CSS2/box.html#padding-properties">padding properties</a>
				<td>padding-top
			<tr><td>padding-right
			<tr><td>padding-bottom
			<tr><td>padding-left
			<tr><td>padding
		<tbody>
			<tr><td colspan="2"><a href="https://www.w3.org/TR/CSS2/generate.html#quotes-specify">quotes</a>
		<tbody>
			<tr><td rowspan="7"><a href="https://www.w3.org/TR/CSS2/text.html">text properties</a>
				<td>letter-spacing
			<tr><td>text-align
			<tr><td>text-decoration
			<tr><td>text-indent
			<tr><td>text-transform
			<tr><td>white-space
			<tr><td>word-spacing
		<tbody>
			<tr><td colspan="2"><a href="https://www.w3.org/TR/CSS2/visudet.html#line-height">vertical-align</a>
		<tbody>
			<tr><td colspan="2"><a href="https://www.w3.org/TR/CSS2/visufx.html#visibility">visibility</a>
		<tbody>
			<tr><td rowspan="3"><a href="https://www.w3.org/TR/CSS2/visudet.html#the-width-property">width</a> <a href="https://www.w3.org/TR/CSS2/visudet.html#min-max-widths">properties</a>
				<td>width
			<tr><td>min-width
			<tr><td>max-width
		<tbody>
			<tr><td colspan="2"><a href="https://www.w3.org/TR/CSS2/visuren.html#z-index">z-index</a>
	</table>

<h2 class="no-num" id="transfer-possibilities">
Appendix B: Transfer Possibilities</h2>

	Often, but not always, the page box has a one-to-one correspondence to the
	physical surface onto which the document is ultimately rendered. The CSS3 page
	model specifies formatting within the page box, but it is the user agent's
	responsibility to transfer the page box to the sheet. Some user agent transfer
	possibilities that are not addressed by CSS3 include:

	<ul id="complex-usecases">
		<li>Transferring one page box to one sheet (e.g. single-sided printing);
		<li>Transferring two page boxes to the front and back surfaces of the same
		sheet (e.g. double-sided printing);
		<li>Transferring N (small) page boxes to one sheet (called "N-up");
		<li>Transferring one (large) page box to N x M sheets (called "tiling");
		<li>Creating signatures. A <dfn export>signature</dfn> is a group of pages printed on
		a sheet, which, when folded and trimmed like a book, appear in their proper
		sequence;
		<li>Printing one document to multiple output trays;
		<li>Generating files containing print instructions.
	</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="changes">
Changes</h2>

	Changes since the <a href="https://www.w3.org/TR/2018/WD-css-page-3-20181018/">18 October 2018 Working Draft</a> are:
	<ul>
		<li>Added '@page/page-orientation' descriptor.
	</ul>

	Changes since the <a href="https://www.w3.org/TR/2013/WD-css3-page-20130314/">14 March 2013 Working Draft</a> are:

	<ul>
		<li>Imported the '@page/marks' and '@page/bleed' properties from [[CSS3GCPM]].
		<li>Added ''@page/bleed/auto'' as the initial value of '@page/bleed' and allowed it to apply even when '@page/marks' is ''@page/marks/none''.
		<li>Added JIS-B4 and JIS-B5.
	</ul>

<h2 class="no-num" id="acknowledgements">Acknowledgements</h2>

	The CSS Working Group would like to give very special thanks
	to this module's former editors:
	Robert Stevahn (Hewlett-Packard),
	Håkon Wium Lie (Opera Software),
	Jim Bigelow (Hewlett-Packard),
	Jacob Refstrup (Hewlett-Packard),
	and
	Melinda Grant (Hewlett-Packard).

	We would also like to acknowledge our expert contributors
	Michael Day (YesLogic),
	Shinyu Murakami (Antenna House),
	Peter Linss (Hewlett-Packard),
	and the other members of the CSS Working Group and www-style community
	who have provided review and comment on CSS Paged Media Level 3.

