<pre class='metadata'>
Title: CSS Grid Layout Module Level 2
Shortname: css-grid
Level: 2
Status: ED
Group: csswg
Work Status: exploring
TR: https://www.w3.org/TR/css-grid-2/
ED: https://drafts.csswg.org/css-grid-2/
Previous version: https://www.w3.org/TR/2018/WD-css-grid-2-20180804/
Previous version: https://www.w3.org/TR/2018/WD-css-grid-2-20180628/
Editor: Tab Atkins Jr., Google, http://www.xanthir.com/contact/, w3cid 42199
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Rossen Atanassov, Microsoft, ratan@microsoft.com, w3cid 49885
Abstract: This CSS module defines a two-dimensional grid-based layout system, optimized for user interface design. In the grid layout model, the children of a grid container can be positioned into arbitrary slots in a predefined flexible or fixed-size layout grid. Level 2 expands Grid by adding “subgrid” capabilities for nested grids to participate in the sizing of their parent grids; and aspect-ratio&ndash;controlled gutters.
Status Text: <strong>The CSSWG has <a href="https://lists.w3.org/Archives/Public/www-style/2019Nov/0007.html">resolved</a> to move CSS Grid Level 2 to Candidate Recommendation. This transition is merely pending editorial work to merge the <a href="https://www.w3.org/TR/css-grid-1/">CSS Grid Level 1</a> prose into this document.
</pre>

<pre class=link-defaults>
spec:css-align-3;
	type:property; text:column-gap
	type:value; for:column-gap; text:normal
</pre>

Introduction {#intro}
=====================

	This level is currently maintained as a diff spec over the level 1 module [[!CSS-GRID-1]].
	The main addition to Level 1 is the “subgrid” feature:
	a subgridded axis is one which matches up its grid lines
	to lines in the element's parent's grid,
	and which derives the sizes of its tracks
	through this integration with the parent grid.

	Issue: The full text of the Grid specification will be folded in when this draft reaches CR.

<!--
 ██████  ██     ██ ████████   ██████   ████████  ████ ████████
██    ██ ██     ██ ██     ██ ██    ██  ██     ██  ██  ██     ██
██       ██     ██ ██     ██ ██        ██     ██  ██  ██     ██
 ██████  ██     ██ ████████  ██   ████ ████████   ██  ██     ██
      ██ ██     ██ ██     ██ ██    ██  ██   ██    ██  ██     ██
██    ██ ██     ██ ██     ██ ██    ██  ██    ██   ██  ██     ██
 ██████   ███████  ████████   ██████   ██     ██ ████ ████████
-->

<h2 id="subgrids">
Subgrids</h2>

	A <a>grid item</a> can itself be a <a>grid container</a> by giving it ''display: grid'';
	in this case the layout of its contents will be independent of the layout of the grid it participates in.

	In some cases it might be necessary for the contents of multiple <a>grid items</a> to align to each other.
	A <a>grid container</a> that is itself a <a>grid item</a>
	can defer the definition of its rows and columns to its parent <a>grid container</a>,
	making it a <dfn export>subgrid</dfn>.
	In this case, the <a>grid items</a> of the <a>subgrid</a>
	participate in sizing the <a>grid</a> of the parent <a>grid container</a>,
	allowing the contents of both grids to align.

	<div class="example">
		For example, suppose we have a form consisting of a list of inputs with labels:

		<pre class="lang-html">
			&lt;ul>
				&lt;li>&lt;label>Name:&lt;/label> &lt;input name=fn>
				&lt;li>&lt;label>Address:&lt;/label> &lt;input name=address>
				&lt;li>&lt;label>Phone:&lt;/label> &lt;input name=phone>
			&lt;/ul>
		</pre>

		We want the labels and inputs to align, and we want to style each list item with a border.
		This can be accomplished with subgrid layout:

		<pre>
			ul {
				display: grid;
				grid: auto-flow / auto 1fr;
			}
			li {
				grid-column: span 2;
				display: grid;
				grid-template-columns: subgrid;
				border: solid;
			}
			label {
				grid-column: 1;
			}
			input {
				grid-column: 2;
			}
		</pre>
	</div>

<h3 id="subgrid-per-axis">
Establishing a Subgrid</h3>

	<a>Subgrids</a> provide the ability to pass grid parameters down through nested elements,
	and content-based sizing information back up to their parent grid.

	<pre class="propdef partial">
	Name: grid-template-rows, grid-template-columns
	New values: subgrid <<line-name-list>>?
	New computed values: The ''subgrid'' keyword followed by a <<line-name-list>>.
	</pre>

	<dl dfn-for="grid-template-rows, grid-template-columns" dfn-type=value>
		<dt><dfn id="subgrid-listing">subgrid <<line-name-list>>?</dfn>
		<dd>
			The <dfn value for="grid-template-rows, grid-template-columns">subgrid</dfn> value
			indicates that the grid will adopt the spanned portion of its parent grid in that axis.
			Rather than being specified explicitly,
			the sizes of the grid rows/columns
			will be taken from the parent grid's definition,
			and the <a>subgrid</a>’s items will participate
			in the <a href="https://www.w3.org/TR/css-grid-1/#algo-content">intrinsic size calculations</a> ([[css-grid-1#algo-content]])
			of any tracks shared with the parent grid.

			The <<line-name-list>> argument allows local naming of the grid lines propagated from the parent grid:
			if a <<line-name-list>> is given,
			the specified <<line-names>>s are assigned to the subgrid’s <a>explicit grid lines</a>,
			one per line, starting with line 1.
			Excess <<line-names>> are ignored.

			If there is no parent grid,
			this value is equivalent to
			the initial value, ''grid-template-rows/none''.
	</dl>

	Unlike those of a regular nested grid,
	a subgrid’s contents participate in its parent <a>grid formatting context</a>;
	thus a subgrid does not establish an <a>independent formatting context</a>.

	The syntax of <<line-name-list>> is defined as follows:

	<pre class="prod">
		<dfn>&lt;line-name-list></dfn> = [ <<line-names>> | <<name-repeat>> ]+
		<dfn>&lt;line-names></dfn>     = '[' <<custom-ident>>* ']'
		<dfn>&lt;name-repeat></dfn>    = repeat( [ <<integer [1, Infinity]>> | auto-fill ], <<line-names>>+)
	</pre>

	The <<name-repeat>> variant of the ''repeat()'' notation
	<!-- is for adding line names to <a href="#subgrids">subgrids</a> and -->
	can only be used with the ''grid-template-rows/subgrid'' keyword:
	it only repeats names.
	The ''auto-fill'' keyword is only valid once per <<line-name-list>>,
	and repeats enough times for the name list to match the subgrid’s specified <a>grid span</a>
	(falling back to 0 if the span is already fulfilled).

<h3 id="subgrid-items">
Characteristics of a Subgrid Item</h3>

	A <a>subgrid</a> behaves just like a normal <a>grid container</a> except that:

	<ul style="list-style-type: lower-alpha">
		<li id="subgrid-tracks">
			Placing the <a>subgrid</a>
			creates a correspondence between its subgridded tracks
			and those that it spans in its parent grid.
			The grid lines thus shared between the subgrid and its parent
			form the subgrid’s <a>explicit grid</a>,
			and its track sizes are governed by the parent grid.

		<li id="subgrid-span">
			The number of explicit tracks in the <a>subgrid</a>
			in a subgridded dimension
			always corresponds to the number of <a>grid tracks</a>
			that it spans in its parent <a>grid</a>:

			<ul>
				<li>
					If the <a>subgrid</a>’s <a>grid span</a> in the subgridded dimension is definite,
					then the number of explicit tracks in each subgridded dimension
					is taken from its used <a>grid span</a> in that dimension
					(regardless of its 'grid-template-*' properties).

				<li>
					If it has an <a>indefinite grid span</a>
					(i.e. either the '-start' or '-end' value
					of its <a>grid-placement properties</a> in the subgridded axis
					is ''grid-row-start/auto'')
					then its used <a>grid span</a> is taken
					from the number of explicit tracks specified for that axis
					by its 'grid-template-*' properties,
					floored at one.
			</ul>

		<li id="subgrid-indexing">
			The <a>grid-placement properties</a> of the <a>subgrid</a>’s <a>grid items</a>
			and the line numbers they use
			are scoped to the lines covered by the subgrid,
			exactly consistent with the lines outside the subgrid
			being excluded from its <a>explicit grid</a>.
			E.g. numeric indices count starting from the first line of the subgrid
			rather than the first line of the parent grid.

			Line numbering and placement rules
			obey the subgrid’s own <a>writing mode</a>,
			just as they would for a nested independent grid.

		<li id="subgrid-line-name-inheritance">
			Since <a>subgrids</a> can be placed before their contents are placed,
			the subgridded lines
			automatically receive the explicit line names
			specified on the corresponding lines of the parent <a>grid</a>.

			These names are in <em>addition</em> to
			any line names specified locally on the subgrid.

		<li id="subgrid-area-inheritance">
			When a <a>subgrid</a> overlaps a <a>named grid area</a> in its parent
			that was created by a 'grid-template-areas' property declaration,
			<a>implicit line names</a> are assigned
			to represent the parent’s <a>named grid area</a>
			within the <a>subgrid</a>.

			Note: If a <a>named grid area</a>
			only partially overlaps the <a>subgrid</a>,
			its <a lt="implicit named lines">implicit names</a>
			will be assigned
			to the first and/or last line of the <a>subgrid</a>
			such that a <a>named grid area</a> exists
			representing that partially overlapped area of the <a>subgrid</a>;
			thus the <a>implicit named lines</a> of the <a>subgrid</a>
			might not always correspond exactly
			to the <a>implicit named lines</a> of the parent <a>grid</a>.

			These names are also in <em>addition</em> to
			any line names specified locally on the subgrid.

			<div class="example">
				In the following example,
				the 4-column grand-parent grid has both explicit line names
				and implicit ones generated by 'grid-template-areas':

				<xmp>
					<style type="css">
					  .outer {
					    display: grid;
					    grid-template-columns:
					      [outer-edge] 20px [main-start] 1fr [center] 1fr max-content [main-end];
					    grid-template-areas:
					      "gutter info info photos";
					  }
					  .middle {
					    grid-column: main-start / main-end;
					    display: grid;
					    grid: subgrid / subgrid;
					  }
					  .inner {
					    grid-column: center / -1;
					    display: grid;
					    grid: subgrid / subgrid;
					  }
					</style>

					<div class="outer">
					  <div class="middle">
					    <div class="inner">&hellip;</div>
					  </div>
					</div>
				</xmp>

				After all types of name resolution,
				the names for each grid will be:
				<pre>
					.outer = [outer-edge gutter-start] [gutter-end info-start main-start] [center] [info-end photos-start] [main-end photos-end]
					.middle = [info-start main-start] [center] [info-end photos-start] [main-end photos-end]
					.inner = [center info-start] [info-end photos-start] [main-end photos-end]
				</pre>

				Notice that all the explicit names inherit straight through to .inner,
				but the implicit names are calculated based on
				each subgrid's overlap of the original <a>named area</a>.
			</div>

		<li id="subgrid-implicit">
			The <a>subgrid</a> does not have any <a>implicit grid tracks</a>
			in the subgridded dimension(s).
			Hypothetical <a>implicit grid lines</a> are used to resolve placement
			as usual when the <a>explicit grid</a> does not have enough lines;
			however
			each <a>grid item</a>’s <a>grid area</a>
			is <a>clamped</a> to the subgrid’s <a>explicit grid</a>
			(using the same procedure as for clamping placement in an overly-large grid).

			<div class="example">
				For example, if a ''span 1'' subgrid has a <a>grid item</a> with ''grid-column: 2 / span 3;'',
				then that item is instead forced into (and limited to) the first (only) track in the subgrid.
			</div>

		<li id="subgrid-size-contribution">
			The <a>subgrid</a> itself lays out as an ordinary <a>grid item</a> in its parent grid,
			but acts as if it was completely empty for track sizing purposes
			in the subgridded dimension.

		<li id="subgrid-item-contribution">
			The <a>subgrid</a>'s own <a>grid items</a> participate
			in the sizing of its parent grid in the subgridded dimension(s)
			and are aligned to it in those dimensions.

			<p id="subgrid-margins">
			In this process, the sum of the <a>subgrid</a>'s
			margin, padding, and borders at each edge
			are applied as an extra layer of (potentially negative) margin
			to the items at those edges.
			This extra layer of “margin” accumulates
			through multiple levels of subgrids.

			<div class="example">
				For example, if we have a 3&times;3 grid with the following tracks:

				<pre>#parent-grid { grid-template-columns: 300px auto 300px; }</pre>

				If a subgrid covers the last two tracks,
				its first two columns correspond to the parent grid's last two columns,
				and any items positioned into those tracks participate in sizing the parent grid.
				Specifically, an item positioned in the first track of the subgrid
				influences the auto-sizing of the parent grid's middle track.

				<pre>
					#subgrid { grid-column: 2 / span 2; } /* cover parent's 2nd and 3rd tracks */
					#subgrid > :first-child { grid-column: 1; } /* subgrid's 1st track, parent grid's 2nd track */
				</pre>

				If the subgrid has margins/borders/padding,
				the size of those margins/borders/padding also influences sizing.
				For example, if the subgrid has 100px padding:

				<pre>#subgrid { padding: 100px; }</pre>

				Then a <a>grid item</a> in the <a>subgrid's</a> first track
				acts as if it has an additional ''100px'' of top, left, and bottom margin,
				influencing the sizing of the parent grid's tracks
				and the <a>grid item's</a> own position.
			</div>

			<p id="subgrid-gaps">
			Meanwhile,
			half the size of the difference between
			the subgrid’s <a>gutters</a> ('row-gap'/'column-gap')
			and its parent grid’s <a>gutters</a>
			is applied as an extra layer of (potentially negative) margin
			to the items not at those edges.
			This extra layer of “margin” also accumulates
			through multiple levels of subgrids.
			A value of ''row-gap/normal''
			indicates that the subgrid has the same size <a>gutters</a>
			as its parent grid,
			i.e. the applied difference is zero.

			Note: The end result will be that the parent’s grid tracks
			will be sized as specified,
			and that the subgrid’s gaps will visually center-align
			with the parent grid’s gaps.

			<div class="example">
				<p>For example,
				suppose we have a 300px-wide outer grid
				with 50px gaps
				and its columns specified as ''100px 1fr''.
				A subgrid spanning both tracks would have&hellip;

				<dl>
					<dt>&hellip; if its 'column-gap' were ''column-gap/normal'' (or ''50px''):
					<dd>
						<ul>
							<li>A grid item in its left column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								without any special adjustment,
								thus stretching to 100px wide
								while remaining aligned
								to the subgrid’s left edge.
							<li>A grid item in its right column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								without any special adjustment,
								thus stretching to 150px wide,
								while remaining aligned
								to the subgrid’s right edge.
							<li>An effective visual <a>gutter</a> between the items
								of 50px, exactly matching its parent grid.
						</ul>

						<img src="images/subgrid-gap-normal.png" alt="">

					<dt>&hellip; if its 'column-gap' were ''0'':
					<dd>
						<ul>
							<li>A grid item in its left column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								as if it had a -25px right margin,
								thus stretching to 125px wide
								while remaining aligned
								to the subgrid’s left edge.
							<li>A grid item in its right column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								as if it had a -25px left margin,
								thus stretching to 175px wide,
								while remaining aligned
								to the subgrid’s right edge.
							<li>An effective visual <a>gutter</a> between the items
								of zero, as specified by its 'column-gap'.
						</ul>

						<img src="images/subgrid-gap-0px.png" alt="">

					<dt>&hellip; if its 'column-gap' were ''25px'':
					<dd>
						<ul>
							<li>A grid item in its left column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								as if it had a -12.5px right margin,
								thus stretching to 112.5px wide
								while remaining aligned
								to the subgrid’s left edge.
							<li>A grid item in its right column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								as if it had a -12.5px left margin,
								thus stretching to 162.5px wide,
								while remaining aligned
								to the subgrid’s right edge.
							<li>An effective visual <a>gutter</a> between the items
								of 25px, as specified by its 'column-gap'.
						</ul>

						<img src="images/subgrid-gap-25px.png" alt="">

					<dt>&hellip; if its 'column-gap' were ''75px'':
					<dd>
						<ul>
							<li>A grid item in its left column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								as if it had a 12.5px right margin,
								thus stretching to 87.5px wide
								while remaining aligned
								to the subgrid’s left edge.
							<li>A grid item in its right column
								sized and laid out
								(and contributing its size to the parent grid’s sizing calculations)
								as if it had a 12.5px left margin,
								thus stretching to 137.5px wide,
								while remaining aligned
								to the subgrid’s right edge.
							<li>An effective visual <a>gutter</a> between the items
								of 75px, as specified by its 'column-gap'.
						</ul>

						<img src="images/subgrid-gap-75px.png" alt="">
				</dl>
			</div>

		<li id="subgrid-edge-placeholders">
			For each edge of a non-empty subgrid,
			to account for the subgrid’s margin/border/padding at that edge,
			a hypothetical item is contributed to the track sizing algorithm
			for each span size
			in the set of items spanning into
			the occupied track closest to that edge of the subgrid.
			This item’s sizes are taken from the sizes of the largest such item
			of each span size,
			and are additionally inflated by the subgrid’s own margin/border/padding
			at that edge (or both edges,
			if it happens to be the most extreme item on both sides
			and is also the smallest span size).
			Similarly, the hypothetical item’s span is taken
			from that same real item’s span,
			and inflated by the number of empty tracks between it
			and the relevant subgrid’s edge(s).

			Note: This step can be shortcut if
			the tracks closest to the subgrid’s edges contain real items,
			which would have already
			<a href="#subgrid-item-contribution">accounted for the subgrid’s margin/border/padding</a>
			as described above.

			<div class="example">
				For example, in the following subgrid layout:
				<pre>
					5px auto auto 5px
					.   aaaaaaaaa .
					.   bbbb cccc .
				</pre>

				Assuming subgrid items <var>a</var>, <var>b</var>, and <var>c</var>
				occupying their corresponding grid areas
				and a subgrid padding of 25px,
				two hypothetical grid items would be contributed
				to the track sizing algorithm
				for the purpose of handling the subgrid’s inline-start padding:
				one with the size of <var>b</var> plus 25px,
				spanning the first two columns;
				and one with the size of <var>a</var> plus 25px,
				spanning the first three columns.

				If only item <var>a</var> existed,
				which would make it both
				span into the closest occupied columns on both sides
				and be the smallest-spanning item on each side,
				then the hypothetical item it contributes
				would be its size inflated by 50px
				and would span all four columns.
			</div>

		<li id="subgrid-box-alignment">
			The <a>subgrid</a> is always stretched in its subgridded dimension(s:
			the 'align-self'/'justify-self' properties on it are ignored,
			as are any specified width/height constraints.

		<li id="subgrid-grid-alignment">
			Layoutwise, the <a>subgrid</a>’s <a>grid</a>
			is always aligned with the corresponding section of the parent <a>grid</a>;
			the 'align-content'/'justify-content' properties on it are also ignored
			in the subgridded dimension.

		<li id="subgrid-overflow">
			The 'overflow' property does apply to <a>subgrids</a>,
			so that overflowing contents of the subgrid can be scrolled into view.
			(Note: the act of scrolling does not affect layout.)
	</ul>

<!--
████████  ████████  ██████   ███████  ██       ██     ██ ████████ ████████
██     ██ ██       ██    ██ ██     ██ ██       ██     ██ ██       ██     ██
██     ██ ██       ██       ██     ██ ██       ██     ██ ██       ██     ██
████████  ██████    ██████  ██     ██ ██       ██     ██ ██████   ██     ██
██   ██   ██             ██ ██     ██ ██        ██   ██  ██       ██     ██
██    ██  ██       ██    ██ ██     ██ ██         ██ ██   ██       ██     ██
██     ██ ████████  ██████   ███████  ████████    ███    ████████ ████████
-->

<h3 id='resolved-track-list'>
Resolved Value of a Track Listing</h3>

	When an element generates a [=grid container=] box that is a [=subgrid=],
	the [=resolved value=]
	of the 'grid-template-rows' and 'grid-template-columns' properties
	represents the [=used value|used=] number of columns,
	serialized as the ''subgrid'' keyword
	followed by a list representing each of its lines
	as a [=line name set=] of all the line's names
	explicitly defined on the subgrid
	(not including those adopted from the parent grid),
	without using the ''repeat()'' notation.

	<div class="example">
		For example,
		when applied to a [=subgrid=] with ''grid-column: span 4'',
		each of the following 'grid-template-columns' [=specified values=]
		becomes the corresponding [=resolved values=]:

		<pre class="lang-css">
			specified: subgrid [a] repeat(auto-fill, [b]) [c]
			resolved:  subgrid [a] [b] [b] [b] [c]
		</pre>

		<pre class=lang-css>
			specified: subgrid [a] [a] [a] [a] repeat(auto-fill, [b]) [c] [c]
			resolved:  subgrid [a] [a] [a] [a] [c]
		</pre>

		<pre class="lang-css">
			specified: subgrid [] [a]
			resolved:  subgrid [] [a] [] [] []
		</pre>

		<pre class="lang-css">
			specified: subgrid [a] [b] [c] [d] [e] [f]
			resolved:  subgrid [a] [b] [c] [d] [e]
		</pre>
	</div>

	Note: This violates the general
	"shortest equivalent serialization" principle
	by serializing empty trailing [=line name sets=],
	as the trailing [=line name sets=] provide potentially-useful information
	about how many tracks the subgrid is spanning.

<h3 id="subgrid-sizing">
Subgrid Sizing Algorithm</h3>

	Note: Placement of all grid items,
	including subgrids and their sub-items,
	occurs before sizing.

	Track sizing in a subgridded dimension
	treats each item in a given track in that axis
	as members of the parent grid.
	This interlacing requires that grid sizing
	drills down per axis into subgrids,
	rather than completing both axes in its recursion.
	Thus the <a href="https://www.w3.org/TR/css-grid-1/#algo-overview">Grid Sizing Algorithm</a>
	is modified as follows:

	<blockquote>

	<ol>
		<li>
			First, the <a>track sizing algorithm</a> is used to resolve the sizes of the <a>grid columns</a>.

			In this process,
			any <a>grid item</a> which is subgridded
			in the <a>grid container</a>’s <a>inline axis</a>
			is treated as empty
			and its <a>grid items</a> (the grandchildren)
			are treated as direct children of the <a>grid container</a> (their grandparent).
			This introspection is recursive.

			Items which are subgridded only in the <a>block axis</a>,
			and whose <a>grid container</a> size in the <a>inline axis</a>
			depends on the size of its contents
			are also introspected:
			since the size of the item in this dimension
			can be dependent on the sizing of its subgridded tracks in the other,
			the size contribution of any such item to this grid’s column sizing
			(see <a href="https://www.w3.org/TR/css-grid-1/#algo-content">Resolve Intrinsic Track Sizes</a>)
			is taken under the provision
			of having determined its track sizing only up to the same point
			in the Grid Sizing Algorithm as this parent grid itself.
			E.g. for the first pass through this step,
			the item will have its tracks sized only through this first step;
			if a second pass of this step is triggered then
			the item will have completed a first pass through steps 1-3
			as well as the second pass of this step
			prior to returning its size for consideration in this grid’s column sizing.
			Again, this introspection is recursive.

			If calculating the layout of a <a>grid item</a> in this step
			depends on the <a>available space</a> in the <a>block axis</a>,
			assume the <a>available space</a> that it would have
			if any row with a <a>definite</a> <a>max track sizing function</a>
			had that size and all other rows were infinite.

		<li>
			Next, the <a>track sizing algorithm</a> resolves the sizes of the <a>grid rows</a>,
			using the <a>grid column</a> sizes calculated in the previous step.

			In this process,
			any <a>grid item</a> which is subgridded
			in the <a>grid container</a>’s <a>block axis</a>
			is treated as empty
			and its <a>grid items</a> (the grandchildren)
			are treated as direct children of the <a>grid container</a> (their grandparent).
			This introspection is recursive.

			As with sizing columns,
			items which are subgridded only in the <a>inline axis</a>,
			and whose <a>grid container</a> size in the <a>block axis</a>
			depends on the size of its contents
			are also introspected.
			(As with sizing columns,
			the size contribution to this grid’s row sizing
			is taken under the provision
			of having determined its track sizing
			only up to this corresponding point in the algorithm;
			and again, this introspection is recursive.)

		<li>
			Then, if the <a>min-content contribution</a> of any grid items have changed
			based on the row sizes calculated in step 2,
			steps 1 and 2 are repeated with the new <a>min-content contribution</a>
			and <a>max-content contribution</a> (once only).

			<div class="note">
				This cycle is necessary for cases where the <a>inline size</a> of a <a>grid item</a>
				depends on the <a>block size</a> of its <a>grid area</a>.
				Examples include wrapped column <a>flex containers</a> (''flex-flow: column wrap''),
				<a>orthogonal flows</a> ('writing-mode'),
				and <a spec=css-multicol>multi-column containers</a>.
			</div>

		<li>
			Finally, the <a>grid container</a> is sized
			using the resulting size of the <a>grid</a> as its content size,
			and the tracks are aligned within the <a>grid container</a>
			according to the 'align-content' and 'justify-content' properties.

			Note: This can introduce extra space between tracks,
			potentially enlarging the grid area of any grid items spanning the gaps
			beyond the space allotted to during track sizing.
	</ol>

	Once the size of each <a>grid area</a> is thus established,
	the <a>grid items</a> are laid out into their respective containing blocks.
	The <a>grid area’s</a> width and height are considered <a>definite</a> for this purpose.

	Note: Since formulas calculated using only definite sizes,
	such as the <a>stretch fit</a> formula,
	are also definite,
	the size of a grid item which is stretched
	is also considered definite.

	</blockquote>

	Issue: Note, this means that a subgrid establishing an orthogonal flow
	would have the order of its track sizing inverted compared to a nested grid.
	We could simplify this by saying that an orthogonal flow
	cannot establish a subgrid; it can only be a nested grid.

	<div class="example">
		The following example illustrates how per-axis subgrids are sized:

		Suppose we have a parent grid container <var>A</var>
		which contains an item <var>B</var> that has subgridded columns
		and contains a grandchild <var>B</var> that has subgridded rows
		and grandchild <var>D</var> that is simply a nested grid.

		<xmp>
			<grid-A>
				<grid-B subgrid=columns>
					<grid-C subgrid=rows/>
					<grid-D>
				</grid-B>
			<grid-A>
		</xmp>

		When <var>A</var> sizes its columns
		it treats <var>B</var>'s items
		as slotted into to <var>A</var>'s corresponding columns,
		but when <var>A</var> sizes its rows
		it treats <var>B</var> as a single item
		(a grid container with its own rows and some items including items <var>C</var> and <var>D</var>).
		Similarly when <var>B</var> sizes its rows,
		it treats <var>C</var>'s items as slotted into <var>B</var>'s rows,
		but when <var>B</var> sizes its columns,
		it treats <var>C</var> as a single item,
		just as it does with <var>D</var>.
		There is no relationship between <var>C</var>'s rows and <var>A</var>'s rows,
		because the rows in <var>B</var> are nested, not subgridded.

		At a high level, the grid algorithm is:

		<ol>
			<li>Size the columns
			<li>Size the rows
			<li>Adjust the columns (if needed based on final row sizes)
		</ol>

		The grid sizing algorithm in this example would thus look like this:
		<ol>
			<li>
				<strong>Resolve sizes of <var>A</var>’s grid columns,
				using the sizes of <var>A</var>’s grid items,
				treating <var>B</var> as empty
				but treating its children
				(including <var>C</var> and <var>D</var>)
				as items in grid <var>A</var>.</strong>

				The grid algorithm simply recurses into <var>D</var>.
				For <var>C</var>, it's more complicated:

				<ol>
					<li>Size <var>C</var>'s columns.
					<li>Size <var>C</var>'s rows by sizing <var>B</var>'s rows.
					<li>Adjust <var>C</var>'s columns.
					<li>Return <var>C</var>'s final column sizes.
				</ol>

				A correct size for <var>B</var>'s rows
				requires <var>C</var>'s final column sizes,
				because the row size depends on the column size,
				and thus <var>B</var>'s rows could very well depend
				on <var>C</var>'s final column sizes.
				To break this cyclic dependency,
				we need to split the algorithm to depend on
				the initial approximation of <var>C</var>'s final column sizes,
				and do the adjustment pass later.
				So for <var>C</var>, we need to recurse into column sizing only,
				and pass that initial size up to <var>A</var>
				for its initial column sizing.

				When we size <var>B</var>'s rows later on,
				we will size <var>C</var>'s rows (which are subgridded),
				and finish up <var>C</var>'s sizing by finalizing its columns.
				If this resulted in a change, we have the opportunity
				to trigger an adjustment pass for <var>A</var>'s columns
				during its adjustment pass.

			<li>
				<strong>Next, resolve sizes of <var>A</var>'s rows,
				using the sizes of <var>A</var>’s grid items,
				treating <var>B</var> as a single item.</strong>

				Since <var>B</var>, as a subgrid,
				has its sizing is split out into the multiple passes,
				the grid algorithm issues only a row-sizing recursion into <var>B</var>:
				Size <var>B</var>’s rows, treating D as a single item, requesting its final size,
				and treating <var>C</var> as an empty item
				and hoisting its children as items into grid <var>B</var>.

				<var>B</var> returns its final row size,
				which factors into <var>A</var>’s row sizing pass.

			<li>
				<strong>Last, finalize <var>A</var>’s column sizes.</strong>
				If <var>C</var>’s final size changes
				as a result of the row-sizing pass through <var>B</var>,
				this should trigger a resizing of <var>B</var>’s columns,
				which should trigger a resizing pass on <var>A</var>’s column.
		</ol>
	</div>

<h2 id="changes">
Changes</h2>

	<h3 class="no-num" id="changes-20180904">
	Changes since the
	<a href="https://www.w3.org/TR/2018/WD-css-grid-2-20180804/">August 2018
	CSS Grid Layout Level 2 Working Draft</a></h3>

	<ul>
		<li>Adjusted the interaction of [=implicit named lines=] to be smarter about partially-overlapped areas. (<a href="https://github.com/w3c/csswg-drafts/issues/4411">Issue 4411</a>)
		<li>Defined [=resolved value=] of 'grid-template-rows' and 'grid-template-columns' for [=subgrids=].
		<li>Removed the aspect-ratio-controlled gutters feature (which will be moved to CSS Box Alignment Level 4 instead).
	</ul>

	<h3 class="no-num" id="changes-20180628">
	Changes since the
	<a href="https://www.w3.org/TR/2018/WD-css-grid-2-20180628/">June 2018
	CSS Grid Layout Level 2 Working Draft</a></h3>

	<ul>
		<li>Defined handling of the subgrid’s margins/borders/padding
		when the track closest to its edge is empty.
		(<a href="https://github.com/w3c/csswg-drafts/issues/2592">Issue 2592</a>)
		<li>Defined that subgrids with an automatic span
		use the number of explicit tracks from their 'grid-template-*' properties
		rather than defaulting to one.
		(<a href="https://github.com/w3c/csswg-drafts/issues/2565">Issue 2565</a>
	</ul>

	<h3 class="no-num" id="changes-20180427">
	Changes since the
	<a href="https://www.w3.org/TR/2018/WD-css-grid-2-20180427/">April 2018
	CSS Grid Layout Level 2 Working Draft</a></h3>

	<ul>
		<li>Added back syntax for specifying subgrid-local line names.
		<li>Defined that subgrid’s own gap properties are honored, and how exactly that works.
		<li>Clarified interactions of parent line names and subgrid line names.
	</ul>

<h2 id="acknowledgements">
Acknowledgements</h2>

	Many thanks to Mats Palmgren of Mozilla,
	without whose support and feedback the subgrid feature
	would not be able to move forward.
	Thanks also to Daniel Tonon,
	who insisted on intelligent handling of gaps in subgrids
	and contributed illustrations;
<!-- add this in once we spec it
	to Eric Meyer,
	who asked us to define useful behavior for <<flex>> min track sizes;
-->
	and Rachel Andrew and Jen Simmons
	who helped bridge the feedback gap between the CSS Working Group
	and the Web design/authoring community.

	Lastly,
	the acknowledgements section of CSS Grid Level 2
	would be incomplete without acknowledgement
	of everyone who made the monumental task of
	<a href="https://www.w3.org/TR/css-grid-1/">CSS Grid Level 1</a> possible.
