css-grid/Overview.bs

Sun, 31 Jan 2016 15:42:31 -0800

author
Peter Linss <[email protected]>
date
Sun, 31 Jan 2016 15:42:31 -0800
changeset 16986
5be73fbc8592
parent 16923
e651a6b8d78c
child 16989
255258410d1b
permissions
-rw-r--r--

change //dev.w3.org/csswg/ urls to //drafts.csswg.org/

     1 <h1>CSS Grid Layout Module Level 1</h1>
     3 <pre class='metadata'>
     4 Status: ED
     5 Work Status: Refining
     6 Shortname: css-grid
     7 Level: 1
     8 Group: csswg
     9 ED: https://drafts.csswg.org/css-grid/
    10 TR: http://www.w3.org/TR/css-grid-1/
    11 Previous version: http://www.w3.org/TR/2015/WD-css-grid-1-20150917/
    12 Previous version: http://www.w3.org/TR/2015/WD-css-grid-1-20150806/
    13 Previous version: http://www.w3.org/TR/2015/WD-css-grid-1-20150317/
    14 Previous version: http://www.w3.org/TR/2014/WD-css-grid-1-20140513/
    15 Previous version: http://www.w3.org/TR/2014/WD-css-grid-1-20140123/
    16 Previous version: http://www.w3.org/TR/2013/WD-css3-grid-layout-20130402/
    17 Previous version: http://www.w3.org/TR/2012/WD-css3-grid-layout-20121106/
    18 Editor: Tab Atkins Jr., Google, http://www.xanthir.com/contact/
    19 Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
    20 Editor: Rossen Atanassov, Microsoft, [email protected]
    21 Former editor: Alex Mogilevsky, Microsoft Corporation, [email protected]
    22 Former editor: Phil Cupp, Microsoft Corporation, [email protected]
    23 Issue Tracking: Disposition of Comments https://drafts.csswg.org/css-grid-1/issues
    24 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.
    25 Ignored Terms: containing block, <positive-integer>, <ident>, auto, grid-*-start, grid-*-end, flex factor, flex factors, block formatting context, grid-auto-position, min size property, max size property
    26 Ignored Vars: A, B, C, size-contribution, track-sizes, extra-space
    27 Link Defaults: css21 (property) margin/min-height/max-height/min-width/max-width, css-align-3 (dfn) alignment container/alignment subject/box alignment properties, css-align-3 (value) stretch/baseline, css-position-3 (property) left, css-position-3 (property) position, css-writing-modes-3 (dfn) start/end
    28 At Risk: the ''grid-template-rows/subgrid'' value of 'grid-template-columns' and 'grid-template-rows', and its component parts individually
    29 </pre>
    31 <pre class="link-defaults">
    32 spec:css-break-3; type:dfn; text:fragment
    33 </pre>
    35 <style type="text/css">
    36 .example {
    37 	clear:both
    38 }
    40 .pseudo-code {
    41 	font-family:monospace
    42 }
    43 .pseudo-code > ol {
    44 	list-style-type:decimal
    45 }
    46 .pseudo-code > ol > li > ol {
    47 	list-style-type:lower-latin
    48 }
    49 .pseudo-code > ol > li > ol > li > ol {
    50 	list-style-type:lower-roman
    51 }
    52 .pseudo-code ul {
    53 	list-style-type:disc
    54 }
    56 dd > p:nth-child(1) {
    57 	margin-top:0
    58 }
    60 dd:last-child {
    61 	margin-bottom: 0;
    62 }
    64 dl.phase {
    65 	padding-left: .5em;
    66 	border-left: .5em #e0e0e0 solid;
    67 }
    68 #grid-property-breakdown tr:nth-child(3) td {
    69 	width: 25%;
    70 	border-style: solid;
    71 }
    72 </style>
    74 <h2 id='intro'>
    75 Introduction and Overview</h2>
    77 	Grid layout contains features targeted at web application authors.
    78 	The grid can be used to achieve many different layouts.
    79 	It excels at dividing up space for major regions of an application,
    80 	as well as defining the relative size, position, and painting order
    81 	for the parts of a control built from HTML primitives.
    83 	Like tables,
    84 	grid layout enables an author to align elements into columns and rows,
    85 	but unlike tables,
    86 	grid layout doesn't have content structure,
    87 	and thus enables a wide variety of layouts not possible with tables.
    88 	For example, the children of a grid container can position themselves
    89 	such that they overlap similar to positioned elements.
    91 	In addition, the absence of content structure in grid layout helps to manage changes to layout
    92 	by using fluid and source order independent layout techniques.
    93 	By combining media queries with the CSS properties that control layout of the grid container and its children,
    94 	authors can adapt their layout to changes in device form factors, orientation, and available space,
    95 	without needing to alter the semantic nature of their content.
    98 <h3 id='background'>
    99 Background and Motivation</h3>
   101 	<figure class="sidefigure">
   102 		<img class="figure" alt="Image: Application layout example requiring horizontal and vertical alignment." src="images/basic-form.png" />
   103 		<figcaption>Application layout example requiring horizontal and vertical alignment.</figcaption>
   104 	</figure>
   106 	As websites evolved from simple documents into complex, interactive applications,
   107 	tools for document layout, e.g. floats,
   108 	were not necessarily well suited for application layout.
   109 	By using a combination of tables, JavaScript, or careful measurements on floated elements,
   110 	authors discovered workarounds to achieve desired layouts.
   111 	Layouts that adapted to the available space were often brittle
   112 	and resulted in counter-intuitive behavior as space became constrained.
   113 	As an alternative, authors of many web applications opted for a fixed layout
   114 	that cannot take advantage of changes in the available rendering space on a screen.
   116 	The capabilities of grid layout address these problems.
   117 	It provides a mechanism for authors to divide available space for layout into columns and rows
   118 	using a set of predictable sizing behaviors.
   119 	Authors can then precisely position and size the building block elements of their application
   120 	into <a>grid areas</a> defined by the intersection of these columns and rows.
   121 	Figure 1 illustrates a basic layout which can be achieved with grid layout.
   123 <h3 id='adapting-to-available-space'>
   124 Adapting Layouts to Available Space</h3>
   126 	<figure class="sidefigure">
   127 			<img alt="Image: Five grid items arranged according to content size and available space." src="images/game-smaller.png" />
   129 		<figcaption>Five grid items arranged according to content size and available space.</figcaption>
   130 	</figure>
   132 	<figure class="sidefigure">
   133 			<img alt="Image: Growth in the grid due to an increase in available space." src="images/game-larger.png" />
   135 		<figcaption>Growth in the grid due to an increase in available space.</figcaption>
   136 	</figure>
   138 	Grid layout can be used to intelligently reflow elements within a webpage.
   139 	Figure 2 represents a game with five major components in the layout:
   140 	the game title, stats area, game board, score area, and control area.
   141 	The author's intent is to divide the space for the game such that:
   143 	<ul>
   144 		<li>
   145 			The stats area always appears immediately under the game title.
   146 		<li>
   147 			The game board appears to the right of the stats and title.
   148 		<li>
   149 			The top of the game title and the game board should always align.
   150 		<li>
   151 			The bottom of the game board and the stats area align when the game has reached its minimum height,
   152 			but otherwise the game board will stretch to take advantage of all the screen real-estate available to it.
   153 		<li>
   154 			The score area should align into the column created by the game and stats area,
   155 			while the controls are centered under the board.
   156 	</ul>
   158 	As an alternative to using script to control the absolute position, width, and height of all elements,
   159 	the author can use grid layout,
   160 	as shown in Figure 3.
   161 	The following example shows how an author might achieve all the sizing, placement, and alignment rules declaratively.
   163 	Note that there are multiple ways to specify the structure of the grid
   164 	and to position and size <a>grid items</a>,
   165 	each optimized for different scenarios.
   166 	This example illustrates one that an author may use to define the position and space for each <a>grid item</a>
   167 	using the 'grid-template-rows' and 'grid-template-columns' properties on the <a>grid container</a>,
   168 	and the 'grid-row' and 'grid-column' properties on each <a>grid item</a>.
   170 	<div class="example">
   171 		<pre class="lang-css">
   172 		#grid {
   173 			/**
   174 			 * Two columns:
   175 			 *  1. the first sized to content,
   176 			 *  2. the second receives the remaining space
   177 			 *     (but is never smaller than the minimum size of the board
   178 			 *     or the game controls, which occupy this column [3])
   179 			 *
   180 			 * Three rows:
   181 			 *  3. the first sized to content,
   182 			 *  4. the middle row receives the remaining space
   183 			 *     (but is never smaller than the minimum height
   184 			 *      of the board or stats areas)
   185 			 *  5. the last sized to content.
   186 			 */
   187 			display: grid;
   188 			grid-template-columns:
   189 				/* 1 */ auto
   190 				/* 2 */ 1fr;
   191 			grid-template-rows:
   192 				/* 3 */ auto
   193 				/* 4 */ 1fr
   194 				/* 5 */ auto;
   195 		}
   197 		/* Each part of the game is positioned between grid lines by
   198 		 * referencing the starting grid line and then specifying, if more
   199 		 * than one, the number of rows or columns spanned to determine
   200 		 * the ending grid line, which establishes bounds for the part. */
   201 		#title    { grid-column: 1; grid-row: 1; }
   202 		#score    { grid-column: 1; grid-row: 3; }
   203 		#stats    { grid-column: 1; grid-row: 2; align-self: start; }
   204 		#board    { grid-column: 2; grid-row: 1 / span 2; }
   205 		#controls { grid-column: 2; grid-row: 3; justify-self: center; }
   206 		</pre>
   208 		<pre class="lang-markup">
   209 			&lt;div id="grid">
   210 			  &lt;div id="title">Game Title&lt;/div>
   211 			  &lt;div id="score">Score&lt;/div>
   212 			  &lt;div id="stats">Stats&lt;/div>
   213 			  &lt;div id="board">Board&lt;/div>
   214 			  &lt;div id="controls">Controls&lt;/div>
   215 			&lt;/div>
   216 		</pre>
   217 	</div>
   219 <h3 id='source-independence'>
   220 Source-Order Independence</h3>
   222 	<figure class="sidefigure">
   223 		<img alt="Image: An arrangement suitable for portrait orientation." src="images/game-portrait.png" />
   225 		<figcaption>An arrangement suitable for “portrait” orientation.</figcaption>
   226 	</figure>
   228 	<figure class="sidefigure">
   229 		<img alt="Image: An arrangement suitable for landscape orientation." src="images/game-landscape.png" />
   231 		<figcaption>An arrangement suitable for “landscape“ orientation.</figcaption>
   232 	</figure>
   234 	Continuing the prior example,
   235 	the author also wants the game to adapt to the space available on traditional computer monitors, handheld devices, or tablet computers.
   236 	Also, the game should optimize the placement of the components when viewed either in portrait or landscape orientation (Figures 4 and 5).
   237 	By combining grid layout with media queries,
   238 	the author is able to use the same semantic markup,
   239 	but rearrange the layout of elements independent of their source order,
   240 	to achieve the desired layout in both orientations.
   242 	The following example leverages grid layout’s ability to name the space which will be occupied by a <a>grid item</a>.
   243 	This allows the author to avoid rewriting rules for <a>grid items</a>
   244 	as the grid’s definition changes.
   246 	<div class="example">
   247 		<pre class="lang-css">
   248 		@media (orientation: portrait) {
   249 			#grid {
   250 				display: grid;
   252 				/* The rows, columns and areas of the grid are defined visually
   253 				* using the grid-template-areas property.  Each string is a row,
   254 				* and each word an area.  The number of words in a string
   255 				* determines the number of columns. Note the number of words
   256 				* in each string must be identical. */
   257 				grid-template-areas: "title stats"
   258 				                     "score stats"
   259 				                     "board board"
   260 				                     "ctrls ctrls";
   262 				/* Columns and rows created with the template property can be
   263 				* assigned a sizing function with the grid-template-columns
   264 				* and grid-template-rows properties. */
   265 				grid-template-columns: auto 1fr;
   266 				grid-template-rows: auto auto 1fr auto;
   267 			}
   268 		}
   270 		@media (orientation: landscape) {
   271 			#grid {
   272 				display: grid;
   274 				/* Again the template property defines areas of the same name,
   275 				* but this time positioned differently to better suit a
   276 				* landscape orientation. */
   277 				grid-template-areas: "title board"
   278 				                     "stats board"
   279 				                     "score ctrls";
   281 				grid-template-columns: auto 1fr;
   282 				grid-template-rows: auto 1fr auto;
   283 			}
   284 		}
   286 		/* The grid-area property places a grid item into a named
   287 		* region (area) of the grid. */
   288 		#title    { grid-area: title }
   289 		#score    { grid-area: score }
   290 		#stats    { grid-area: stats }
   291 		#board    { grid-area: board }
   292 		#controls { grid-area: ctrls }
   293 		</pre>
   294 		<pre class="lang-markup">
   295 		&lt;div id="grid">
   296 			&lt;div id="title">Game Title&lt;/div>
   297 			&lt;div id="score">Score&lt;/div>
   298 			&lt;div id="stats">Stats&lt;/div>
   299 			&lt;div id="board">Board&lt;/div>
   300 			&lt;div id="controls">Controls&lt;/div>
   301 		&lt;/div>
   302 		</pre>
   303 	</div>
   305 	Note: The reordering capabilities of grid layout intentionally affect
   306 	<em>only the visual rendering</em>,
   307 	leaving speech order and navigation based on the source order.
   308 	This allows authors to manipulate the visual presentation
   309 	while leaving the source order intact and optimized for non-CSS UAs
   310 	and for linear models such as speech and sequential navigation.
   312 	Advisement: Grid item placement and reordering must not be used
   313 	as a substitute for correct source ordering,
   314 	as that can ruin the accessibility of the document.
   316 <h3 id='grid-layering'>
   317 Grid Layering of Elements</h3>
   319 	<figure class="sidefigure">
   320 		<img alt="Image: A control composed of layered HTML elements." src="images/control-layering-and-alignment.png" />
   322 		<figcaption>A control composed of layered HTML elements.</figcaption>
   323 	</figure>
   325 	In the example shown in Figure 6,
   326 	the author is creating a custom slider control.
   327 	The control has six parts.
   328 	The lower-limit and upper-limit labels align to the left and right edges of the control.
   329 	The track of the slider spans the area between the labels.
   330 	The lower-range and upper-range fill parts touch beneath the thumb,
   331 	and the thumb is a fixed width and height that can be moved along the track
   332 	by updating the two flex-sized columns.
   334 	Prior to the introduction of grid layout,
   335 	the author would have likely used absolute positioning to control the top and left coordinates,
   336 	along with the width and height of each HTML element that comprises the control.
   337 	By leveraging grid layout,
   338 	the author can instead limit script usage to handling mouse events on the thumb,
   339 	which snaps to various positions along the track
   340 	as the 'grid-template-columns' property of the <a>grid container</a> is updated.
   342 	<div class="example">
   343 		<pre class="lang-css">
   344 		#grid {
   345 			display: grid;
   347 			/* The grid-template-columns and rows properties also support
   348 			* naming grid lines which can then be used to position grid
   349 			* items.  The line names are assigned on either side of a column
   350 			* or row sizing function where the line would logically exist. */
   351 			grid-template-columns:
   352 				[start]        auto
   353 				[track-start]  0.5fr
   354 				[thumb-start]  auto
   355 				[fill-split]   auto
   356 				[thumb-end]    0.5fr
   357 				[track-end]    auto
   358 				[end];
   359 		}
   361 		/* The grid-placement properties accept named lines. Below the
   362 		* lines are referred to by name. Beyond any
   363 		* semantic advantage, the names also allow the author to avoid
   364 		* renumbering the grid-column-start and grid-row-start properties of the
   365 		* grid items.  This is similar to the concept demonstrated in the
   366 		* prior example with the grid-template-areas property during orientation
   367 		* changes, but grid lines can also work with layered grid items
   368 		* that have overlapping areas of different shapes like the thumb
   369 		* and track parts in this example. */
   370 		#low-label  { grid-column-start: start; }
   371 		#track      { grid-column: track-start / track-end; justify-self: center; }
   372 		#high-label { grid-column-end: end; }
   374 		/* Fill parts are drawn above the track so set z-index to 5. */
   375 		#low-fill  { grid-column: track-start / fill-split;
   376 		             justify-self: end;
   377 		             z-index: 5; }
   378 		#high-fill  { grid-column: fill-split / track-end;
   379 		              justify-self: start;
   380 		              z-index: 5; }
   382 		/* Thumb is the topmost part; assign it the highest z-index value. */
   383 		#thumb       { grid-column: thumb-start / thumb-end; z-index: 10 }
   384 		</pre>
   385 		<pre class="lang-markup">
   386 		&lt;div id="grid">
   387 			&lt;div id="low-label">0&lt;/div>
   388 			&lt;div id="high-label">50&lt;/div>
   389 			&lt;div id="track">&lt;/div>
   390 			&lt;div id="low-fill">&lt;/div>
   391 			&lt;div id="high-fill">&lt;/div>
   392 			&lt;div id="thumb">&lt;/div>
   393 		&lt;/div>
   394 		</pre>
   395 	</div>
   397 <!--
   398  ██████   ███████  ██    ██  ██████  ████████ ████████  ████████  ██████
   399 ██    ██ ██     ██ ███   ██ ██    ██ ██       ██     ██    ██    ██    ██
   400 ██       ██     ██ ████  ██ ██       ██       ██     ██    ██    ██
   401 ██       ██     ██ ██ ██ ██ ██       ██████   ████████     ██     ██████
   402 ██       ██     ██ ██  ████ ██       ██       ██           ██          ██
   403 ██    ██ ██     ██ ██   ███ ██    ██ ██       ██           ██    ██    ██
   404  ██████   ███████  ██    ██  ██████  ████████ ██           ██     ██████
   405 -->
   407 <h2 id='grid-concepts'>
   408 Grid Layout Concepts and Terminology</h2>
   410 	In <dfn export>grid layout</dfn>,
   411 	the content of a <a>grid container</a> is laid out
   412 	by positioning and aligning it into a <a>grid</a>.
   413 	The <dfn export>grid</dfn> is an intersecting set of horizontal and vertical <a>grid lines</a>
   414 	that divides the <a>grid container</a>’s space into <a>grid areas</a>,
   415 	into which <a>grid items</a> (representing the <a>grid container</a>’s content) can be placed.
   416 	There are two sets of <a>grid lines</a>:
   417 	one set defining <dfn export lt="grid column | column">columns</dfn>
   418 	that run along the <a href="http://www.w3.org/TR/css3-writing-modes/#block-axis-">block axis</a> (the <dfn export>column axis</dfn>),
   419 	and an orthogonal set defining <dfn export lt="grid row | row">rows</dfn>
   420 	along the <a href="http://www.w3.org/TR/css3-writing-modes/#inline-axis-">inline axis</a> (the <dfn export>row axis</dfn>).
   421 	[[!CSS3-WRITING-MODES]]
   423 <!--
   424 	<div class="figure">
   425 		<img class="figure" alt="Image: A diagram illustrating the relationship between the Grid Element and its Tracks, Lines, Areas and Items." src="images/grid-concepts.png" />
   426 		<p class="caption">A diagram illustrating the relationship between the <a>grid container</a> and its tracks, lines, areas and items.
   427 	</div>
   428 -->
   430 	<figure>
   431 		<img class="figure" alt="Image: Grid Lines." src="images/grid-lines.png" />
   432 		<figcaption>Grid lines: Three in the block axis and four in the inline axis.</figcaption>
   433 	</figure>
   435 <h3 id="grid-line-concept">
   436 Grid Lines</h3>
   438 	<dfn id='grid-line' export lt='grid line|grid row line|grid column line'>Grid lines</dfn> are the horizontal and vertical dividing lines of the <a>grid</a>.
   439 	A <a>grid line</a> exists on either side of a column or row.
   440 	They can be referred to by numerical index,
   441 	or by an author-specified name.
   442 	A <a>grid item</a> references the <a>grid lines</a> to determine its position within the <a>grid</a>
   443 	using the <a href="#placement">grid-placement properties</a>.
   445 	<div class="example">
   446 		The following two examples both create three column <a>grid lines</a> and four row <a>grid lines</a>.
   448 		This first example demonstrates how an author would position a <a>grid item</a> using <a>grid line</a> numbers:
   449 		<pre>
   450 			#grid {
   451 				display: grid;
   452 				grid-template-columns: 150px 1fr;
   453 				grid-template-rows: 50px 1fr 50px;
   454 			}
   456 			#item1 { grid-column: 2;
   457 			         grid-row-start: 1; grid-row-end: 4; }
   458 		</pre>
   460 		This second example uses explicitly named <a>grid lines</a>:
   462 		<pre>
   463 			/* equivalent layout to the prior example, but using named lines */
   464 			#grid {
   465 				display: grid;
   466 				grid-template-columns: 150px [item1-start] 1fr [item1-end];
   467 				grid-template-rows: [item1-start] 50px 1fr 50px [item1-end];
   468 			}
   470 			#item1 {
   471 				grid-column: item1-start / item1-end;
   472 				grid-row: item1-start / item1-end;
   473 			}
   474 		</pre>
   475 	</div>
   477 <h3 id="grid-track-concept">
   478 Grid Tracks and Cells</h3>
   480 	<dfn export>Grid track</dfn> is a generic term for a <a>grid column</a> or <a>grid row</a>&mdash;in
   481 	other words, it is the space between two adjacent <a>grid lines</a>.
   482 	Each <a>grid track</a> is assigned a sizing function,
   483 	which controls how wide or tall the column or row may grow,
   484 	and thus how far apart its bounding <a>grid lines</a> are.
   485 	Adjacent <a>grid tracks</a> can be separated by <a href="#gutters">gutters</a> or <a href="#grid-align">alignment spacing</a>,
   486 	but are otherwise packed tightly.
   488 	A <dfn export>grid cell</dfn> is the intersection of a grid row and a grid column.
   489 	It is the smallest unit of the grid that can be referenced when positioning <a>grid items</a>.
   491 	<div class="example">
   492 		In the following example there are two columns and three rows.
   493 		The first column is fixed at 150px.
   494 		The second column uses flexible sizing, which is a function of the unassigned space in the Grid,
   495 		and thus will vary as the width of the <a>grid container</a> changes.
   496 		If the used width of the <a>grid container</a> is 200px, then the second column 50px wide.
   497 		If the used width of the <a>grid container</a> is 100px, then the second column is 0px
   498 		and any content positioned in the column will overflow the <a>grid container</a>.
   500 		<pre>
   501 				#grid {
   502 					display: grid;
   503 					grid-template-columns: 150px 1fr;  /* two columns */
   504 					grid-template-rows: 50px 1fr 50px; /* three rows  */
   505 				}
   506 		</pre>
   507 	</div>
   509 <h3 id="grid-area-concept">
   510 Grid Areas</h3>
   512 	A <dfn export>grid area</dfn> is the logical space used to lay out one or more <a>grid items</a>.
   513 	It is bound by four <a>grid lines</a>, one on each side of the <a>grid area</a>,
   514 	and participates in the sizing of the <a>grid tracks</a> it intersects.
   515 	A <a>grid area</a> can be named explicitly using the 'grid-template-areas' property of the <a>grid container</a>,
   516 	or referenced implicitly by its bounding <a>grid lines</a>.
   517 	A <a>grid item</a> is assigned to a <a>grid area</a>
   518 	using the <a href="#placement">grid-placement properties</a>.
   520 	<div class="example">
   521 		<pre>
   522 			/* using the template syntax */
   523 			#grid  {
   524 			display: grid;
   525 			grid-template-areas: ". a"
   526 			                     "b a"
   527 			                     ". a";
   528 			grid-template-columns: 150px 1fr;
   529 			grid-template-rows: 50px 1fr 50px;
   530 			}
   532 			#item1 { grid-area: a }
   533 			#item2 { grid-area: b }
   534 			#item3 { grid-area: b }
   536 			/* Align items 2 and 3 at different points in the Grid Area "b".  */
   537 			/* By default, Grid Items are stretched to fit their Grid Area    */
   538 			/* and these items would layer one over the other. */
   539 			#item2 { align-self: start; }
   540 			#item3 { justify-self: end; align-self: end; }
   541 		</pre>
   542 	</div>
   544 	A <a>grid item</a>’s <a>grid area</a> forms the containing block into which it is laid out.
   545 	Percentage lengths specified on a <a>grid item</a> resolve against this containing block.
   546 	Percentages specified for 'margin-top', 'padding-top', 'margin-bottom', and 'padding-bottom' on a <a>grid item</a>
   547 	resolve against the height of its containing block,
   548 	rather than the width (as for blocks).
   550 	Issue: This margin/padding behavior is disputed.
   551 	<a href="https://lists.w3.org/Archives/Public/www-style/2015Mar/0273.html">(see discussion)</a>
   553 	<a>Grid items</a> placed into the same <a>grid area</a> do not directly affect each other's layout.
   554 	Indirectly, a <a>grid item</a> can affect the position of a <a>grid line</a> in a column or row that uses a content-based relative size,
   555 	which in turn can affect the position or size of another <a>grid item</a>.
   557 <!--
   558 ████████  ████  ██████  ████████  ██          ███    ██    ██  ██   ██████   ████████  ████ ████████
   559 ██     ██  ██  ██    ██ ██     ██ ██         ██ ██    ██  ██  ████ ██    ██  ██     ██  ██  ██     ██
   560 ██     ██  ██  ██       ██     ██ ██        ██   ██    ████    ██  ██        ██     ██  ██  ██     ██
   561 ██     ██  ██   ██████  ████████  ██       ██     ██    ██         ██   ████ ████████   ██  ██     ██
   562 ██     ██  ██        ██ ██        ██       █████████    ██     ██  ██    ██  ██   ██    ██  ██     ██
   563 ██     ██  ██  ██    ██ ██        ██       ██     ██    ██    ████ ██    ██  ██    ██   ██  ██     ██
   564 ████████  ████  ██████  ██        ████████ ██     ██    ██     ██   ██████   ██     ██ ████ ████████
   565 -->
   567 <h2 id="grid-model">
   568 Grid Containers</h2>
   570 <h3 id='grid-containers'>
   571 Establishing Grid Containers: the ''display/grid'' and ''inline-grid'' 'display' values</h3>
   573 	<pre class="propdef">
   574 	Name: display
   575 	New values: grid | inline-grid
   576 	</pre>
   578 	<dl dfn-for="display" dfn-type=value>
   579 		<dt><dfn>grid</dfn>
   580 		<dd>
   581 			This value causes an element to generate a block-level <a>grid container</a> box.
   583 		<dt><dfn>inline-grid</dfn>
   584 		<dd>
   585 			This value causes an element to generate an inline-level <a>grid container</a> box.
   586 	</dl>
   588 	A <dfn export>grid container</dfn> establishes a new <dfn export>grid formatting context</dfn> for its contents.
   589 	This is the same as establishing a block formatting context,
   590 	except that grid layout is used instead of block layout:
   591 	floats do not intrude into the grid container,
   592 	and the grid container's margins do not collapse with the margins of its contents.
   593 	The contents of a <a>grid container</a> are laid out into a <a>grid</a>,
   594 	with <a>grid lines</a> forming the boundaries of each <a>grid items</a>’ containing block.
   595 	The 'overflow' property applies to <a>grid containers</a>.
   597 	Grid containers are not block containers,
   598 	and so some properties that were designed with the assumption of block layout
   599 	don't apply in the context of grid layout.
   600 	In particular:
   602 	<ul>
   603 		<li>
   604 			the 'column-*' properties in the Multi-column Layout module [[!CSS3COL]] have no effect on a grid container.
   606 		<li>
   607 			'float' and 'clear' have no effect on a <a>grid item</a>.
   608 			(However, the 'float' property still affects the computed value of 'display' on children of a grid container,
   609 			as this occurs <em>before</em> <a>grid items</a> are determined.)
   611 		<li>
   612 			'vertical-align' has no effect on a grid item.
   614 		<li>
   615 			the ''::first-line'' and ''::first-letter'' pseudo-elements do not apply to <a>grid containers</a>,
   616 			and <a>grid containers</a> do not contribute a first formatted line or first letter to their ancestors.
   617 	</ul>
   619 	If an element's specified 'display' is ''inline-grid''
   620 	and the element is floated or absolutely positioned,
   621 	the computed value of 'display' is <a value>grid</a>.
   622 	The table in <a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS 2.1 Chapter 9.7</a> is thus amended
   623 	to contain an additional row,
   624 	with ''inline-grid'' in the "Specified Value" column
   625 	and ''grid'' in the "Computed Value" column.
   627 <h3 id='intrinsic-sizes'>
   628 Sizing Grid Containers</h3>
   630 	A <a>grid container</a> is sized
   631 	using the rules of the formatting context in which it participates.
   632 	As a block-level box in a <a>block formatting context</a>,
   633 	it is sized like a block box that establishes a formatting context,
   634 	with an ''auto'' inline size calculated as for in-flow block boxes.
   635 	As an inline-level box in an inline formatting context,
   636 	it is sized as an atomic inline-level box (such as an inline-block).
   637 	In both inline and block formatting contexts,
   638 	the <a>grid container</a>’s ''auto'' block size is its max-content size.
   639 	<span class="issue">The block layout spec should define this?</span>
   641 	The <a>max-content size</a> of a <a>grid container</a> is
   642 	the sum of the <a>grid container’s</a> track sizes in the appropriate axis,
   643 	when the grid is sized under a <a>max-content constraint</a>.
   645 	The <a>min-content size</a> of a <a>grid container</a> is
   646 	the sum of the <a>grid container’s</a> track sizes in the appropriate axis,
   647 	when the grid is sized under a <a>min-content constraint</a>.
   649 	See [[!CSS3-SIZING]] for a definition of the terms in this section.
   651 <!--
   652  ██████   ████████  ████ ████████        ████ ████████ ████████ ██     ██  ██████
   653 ██    ██  ██     ██  ██  ██     ██        ██     ██    ██       ███   ███ ██    ██
   654 ██        ██     ██  ██  ██     ██        ██     ██    ██       ████ ████ ██
   655 ██   ████ ████████   ██  ██     ██        ██     ██    ██████   ██ ███ ██  ██████
   656 ██    ██  ██   ██    ██  ██     ██        ██     ██    ██       ██     ██       ██
   657 ██    ██  ██    ██   ██  ██     ██        ██     ██    ██       ██     ██ ██    ██
   658  ██████   ██     ██ ████ ████████        ████    ██    ████████ ██     ██  ██████
   659 -->
   661 <h2 id="grid-items">
   662 Grid Items</h2>
   664 	The content of a <a>grid container</a> consists of zero or more <dfn export id="grid-item" lt="grid item">grid items</dfn>:
   665 	each child of a <a>grid container</a>
   666 	becomes a <a>grid item</a>,
   667 	and each contiguous run of text that is directly contained inside a <a>grid container</a>
   668 	is wrapped in an anonymous <a>grid item</a>.
   669 	However, an anonymous grid item that contains only
   670 	<a href="http://www.w3.org/TR/css-text/#white-space-processing">white space</a>
   671 	is not rendered, as if it were ''display:none''.
   673 	<div class="example">
   674 		<p>Examples of grid items:
   675 		<pre class="lang-markup">
   676 		&lt;div style="display:grid">
   678 		    &lt;!-- grid item: block child -->
   679 		    &lt;div id="item1">block&lt;/div>
   681 		    &lt;!-- grid item: floated element; floating is ignored -->
   682 		    &lt;div id="item2" style="float: left;">float&lt;/div>
   684 		    &lt;!-- grid item: anonymous block box around inline content -->
   685 		    anonymous item 3
   687 		    &lt;!-- grid item: inline child -->
   688 		    &lt;span>
   689 		        item 4
   690 		        &lt;!-- grid items do not <a href="http://www.w3.org/TR/CSS2/visuren.html#anonymous-block-level">split</a> around blocks -->
   691 		        &lt;q style="display: block" id=not-an-item>item 4&lt;/q>
   692 		        item 4
   693 		    &lt;/span>
   694 		&lt;/div>
   695 		</pre>
   697 		<figure>
   698 			<figcaption>grid items determined from above code block</figcaption>
   699 			<a href="examples/grid-item-determination.html">
   700 				<object type="image/png" data="images/grid-item-determination.png">
   701 					<ol>
   702 						<li>grid item containing <samp>block</samp>.
   703 						<li>grid item containing <samp>float</samp>.
   704 						<li>(Anonymous, unstyleable) grid item containing <samp>anonymous item 3</samp>.
   705 						<li>grid item containing three blocks in succession:
   706 							<ul>
   707 								<li>Anonymous block containing <samp>item 4</samp>.
   708 								<li><code>&lt;q></code> element block containing <samp>item 4</samp>.
   709 								<li>Anonymous block containing <samp>item 4</samp>.
   710 							</ul>
   711 					</ol>
   712 				</object>
   713 			</a>
   714 		</figure>
   716 		Note that the inter-element white space disappears:
   717 		it does not become its own grid item,
   718 		even though the inter-element text <em>does</em> get wrapped in an anonymous grid item.
   720 		Note also that the anonymous item's box is unstyleable,
   721 		since there is no element to assign style rules to.
   722 		Its contents will however inherit styles (such as font settings) from the grid container.
   723 	</div>
   725 	A <a>grid item</a> establishes a new formatting context for its contents.
   726 	The type of this formatting context is determined by its 'display' value, as usual.
   727 	However, grid items are <dfn>grid-level</dfn> boxes, not block-level boxes:
   728 	they participate in their container's <a>grid formatting context</a>,
   729 	not in a block formatting context.
   731 	A <a>grid item</a> is sized within the containing block defined by its <a>grid area</a>
   732 	similarly to an equivalent block-level box in an equivalently-sized containing block,
   733 	except that ''margin/auto'' margins and the <a>box alignment properties</a>
   734 	have special effects. (See [[#alignment]].)
   736 	The ''min-width/auto'' value of 'min-width' and 'min-height'
   737 	behaves on <a>grid items</a> in the relevant axis
   738 	analogously to its behavior on <a>flex items</a> in the <a>main axis</a>.
   739 	See [[#min-size-auto]].
   741 	ISSUE: Review implications of intrinsic ratio and Grid's 2D nature.
   743 	The 'display' value of a <a>grid item</a> is <a>blockified</a>:
   744 	if the specified 'display' of an in-flow child of an element generating a <a>flex container</a>
   745 	is an inline-level value, it computes to its block-level equivalent.
   746 	(See <a href="http://www.w3.org/TR/CSS2/visuren.html#dis-pos-flo">CSS2.1&sect;9.7</a> [[!CSS21]]
   747 	and <a href="http://www.w3.org/TR/css-display/#transformations">CSS Display</a> [[!CSS3-DISPLAY]]
   748 	for details on this type of 'display' value conversion.)
   750 	Note: Some values of 'display' normally trigger the creation of anonymous boxes around the original box.
   751 	If such a box is a <a>grid item</a>,
   752 	it is blockified first,
   753 	and so anonymous box creation will not happen.
   754 	For example, two contiguous <a>grid items</a> with ''display: table-cell''
   755 	will become two separate ''display: block'' <a>grid items</a>,
   756 	instead of being wrapped into a single anonymous table.
   758 <!--
   759 <h3 id="position-grid">
   760 Non-children Grid Items</h3>
   762 	<p class="issue">
   763 		This is a proposal to create the ability to have descendants of a grid item participate in a grid layout,
   764 		similar to the behavior defined by the Template Layout module.
   766 		A descendant of the grid can be pulled out of flow and participate directly in the grid
   767 		by assigning it ''position: grid''.
   768 		An element with ''position: grid'' is pulled out of flow and participates as a grid item
   769 		belonging to the first ancestor with ''display: grid''.
   770 		If the element is positioned using named lines or slots,
   771 		it belongs to the first ancestor with ''display: grid'' that has all of the corresponding named lines/slots.
   772 		If no such ancestor exists, the item remains in flow.
   774 	<p class="issue">
   775 		Alternatively, the item can just go into the first grid,
   776 		and missing names are treated as <a value for="<grid-line>">auto</a>.
   777 -->
   779 <h3 id="visibility-collapse">
   780 	Collapsed Grid Items: the 'visibility' property</h3>
   782 	<p class='issue'>
   783 		We want the ability to collapse grid tracks
   784 		(similar to <a href="http://www.w3.org/TR/css3-flexbox/#visibility-collapse">collapsing flex items</a>
   785 		 or <a href="http://www.w3.org/TR/CSS21/tables.html#dynamic-effects">table rows/columns</a>),
   786 		but we're not sure exactly how to do it.
   787 		Ideas welcome, please <a href="mailto:[email protected]?Subject=%5Bcss-grid%5D%20Collapsing%20Grid%20Tracks">post them to [email protected]</a>.
   789 <h3 id='order-property'>
   790 Reordered Grid Items: the 'order' property</h3>
   792 	The 'order' property also applies to <a>grid items</a>.
   793 	It affects their <a href="#grid-auto-flow-property">auto-placement</a> and <a href="#z-order">painting order</a>.
   795 	Advisement: As with reordering flex items,
   796 	the 'order' property must only be used
   797 	when the visual order needs to be <em>out-of-sync</em>
   798 	with the speech and navigation order;
   799 	otherwise the underlying document source should be reordered instead.
   800 	See <a href="https://drafts.csswg.org/css-flexbox-1/#order-accessibility">Reordering and Accessibility</a>
   801 	in [[CSS-FLEXBOX-1]].
   803 <h3 id='z-order'>
   804 Z-axis Ordering: the 'z-index' property</h3>
   806 	<a>Grid items</a> can overlap when they are positioned into intersecting <a>grid areas</a>,
   807 	or even when positioned in non-intersecting areas because of negative margins or positioning.
   808 	The painting order of <a>grid items</a> is exactly the same as inline blocks [[CSS21]],
   809 	except that <a>order-modified document order</a> is used in place of raw document order,
   810 	and 'z-index' values other than <a value for=z-index>auto</a> create a stacking context even if 'position' is ''static''.
   811 	Thus the 'z-index' property can easily be used to control the z-axis order of grid items.
   813 	<p class='note'>
   814 		Note: Descendants that are positioned outside a grid item still participate in any stacking context established by the grid item.
   816 	<div class="example">
   817 		The following diagram shows several overlapping grid items,
   818 		with a combination of implicit source order
   819 		and explicit 'z-index'
   820 		used to control their stacking order.
   822 		<figure>
   823 			<img src="images/drawing-order.png" />
   825 			<figcaption>Drawing order controlled by z-index and source order.</figcaption>
   826 		</figure>
   828 		<pre>
   829 			&lt;style type="text/css">
   830 			#grid {
   831 				display: grid;
   832 				grid-template-columns: 1fr 1fr;
   833 				grid-template-rows: 1fr 1fr
   834 			}
   835 			#A { grid-column: 1 / span 2; grid-row: 2; align-self: end; }
   836 			#B { grid-column: 1; grid-row: 1; z-index: 10; }
   837 			#C { grid-column: 2; grid-row: 1; align-self: start; margin-left: -20px; }
   838 			#D { grid-column: 2; grid-row: 2; justify-self: end; align-self: start; }
   839 			#E { grid-column: 1 / span 2; grid-row: 1 / span 2;
   840 			     z-index: 5; justify-self: center; align-self: center; }
   841 			&lt;/style>
   843 			&lt;div id="grid">
   844 				&lt;div id="A">A&lt;/div>
   845 				&lt;div id="B">B&lt;/div>
   846 				&lt;div id="C">C&lt;/div>
   847 				&lt;div id="D">D&lt;/div>
   848 				&lt;div id="E">E&lt;/div>
   849 			&lt;/div>
   850 		</pre>
   851 	</div>
   853 <!--
   854 ██     ██ ████ ██    ██
   855 ███   ███  ██  ███   ██          ██   ██
   856 ████ ████  ██  ████  ██           ██ ██
   857 ██ ███ ██  ██  ██ ██ ██ ███████ █████████
   858 ██     ██  ██  ██  ████           ██ ██
   859 ██     ██  ██  ██   ███          ██   ██
   860 ██     ██ ████ ██    ██
   861 -->
   863 <h3 id="min-size-auto">
   864 Implied Minimum Size of Grid Items</h3>
   866 	To provide a more reasonable default minimum size for <a>grid items</a>,
   867 	this specification defines the effects of the 'min-width'/'min-height' ''min-width/auto'' value
   868 	for <a>grid items</a>.
   870 	On a <a>grid item</a> whose 'overflow' is ''overflow/visible'',
   871 	when ''min-width/auto'' is specified on the <a>grid item</a>,
   872 	the following table gives the minimum size in that dimension:
   874 	<table class=data>
   875 		<colgroup span=2></colgroup>
   876 		<colgroup span=1></colgroup>
   877 		<thead>
   878 			<tr>
   879 				<th>Specified Size
   880 				<th>Transferred Size
   881 				<th>Minimum Size
   882 		<tbody>
   883 			<tr>
   884 				<td>
   885 				<td>
   886 				<td><var>content size</var>
   887 			<tr>
   888 				<td>✓
   889 				<td>
   890 				<td>min(<var>specified size</var>, <var>content size</var>)
   891 			<tr>
   892 				<td>
   893 				<td>✓
   894 				<td>min(<var>transferred size</var>, <var>content size</var>)
   895 			<tr>
   896 				<td>✓
   897 				<td>✓
   898 				<td>min(<var>specified size</var>, <var>content size</var>)
   899 	</table>
   901 	Where:
   903 	<dl>
   904 		<dt><var>specified size</var>
   905 		<dd>
   906 			If the item’s computed width/height is <a>definite</a>,
   907 			then the <var>specified size</var> is that size
   908 			(clamped by its <a>max size property</a> in that dimension if it's <a>definite</a>).
   909 			It is otherwise undefined.
   911 		<dt><var>transferred size</var>
   912 		<dd>
   913 			If the item has an intrinsic aspect ratio
   914 			and its computed height/width is <a>definite</a>,
   915 			then the <var>transferred size</var> is that size
   916 			(clamped by its <a lt="min size property">min and max size properties</a> in that dimension if they are <a>definite</a>),
   917 			converted through the aspect ratio.
   918 			It is otherwise undefined.
   920 		<dt><var>content size</var>
   921 		<dd>
   922 			The <var>content size</var> is the <a>min-content size</a> in that dimension,
   923 			clamped, if it has an aspect ratio, by any <a>definite</a> <a lt="min size property">min and max size properties</a>
   924 			in the perpendicular dimension
   925 			converted through the aspect ratio,
   926 			and then further clamped by the <a>max size property</a> in the relevant dimension if that is <a>definite</a>.
   927 	</dl>
   930 	<div class="note" id="min-size-opt">
   931 		Note that while a content-based minimum size is often appropriate,
   932 		and helps prevent content from overlapping or spilling outside its container,
   933 		in some cases it is not:
   935 		In particular, if flex sizing is being used for a major content area of a document,
   936 		it is better to set an explicit font-relative minimum width such as ''min-width: 12em''.
   937 		A content-based minimum width could result in a large table or large image
   938 		stretching the size of the entire content area into an overflow zone,
   939 		and thereby making lines of text gratuitously long and hard to read.
   941 		Note also, when content-based sizing is used on an item with large amounts of content,
   942 		the layout engine must traverse all of this content before finding its minimum size,
   943 		whereas if the author sets an explicit minimum, this is not necessary.
   944 		(For items with small amounts of content, however,
   945 		this traversal is trivial and therefore not a performance concern.)
   946 	</div>
   948 <!--
   949 ████████ ██     ██ ████████  ██       ████  ██████  ████ ████████
   950 ██        ██   ██  ██     ██ ██        ██  ██    ██  ██     ██
   951 ██         ██ ██   ██     ██ ██        ██  ██        ██     ██
   952 ██████      ███    ████████  ██        ██  ██        ██     ██
   953 ██         ██ ██   ██        ██        ██  ██        ██     ██
   954 ██        ██   ██  ██        ██        ██  ██    ██  ██     ██
   955 ████████ ██     ██ ██        ████████ ████  ██████  ████    ██
   956 -->
   958 <h2 id='grid-definition'>
   959 The Explicit Grid</h2>
   961 	The three properties 'grid-template-rows', 'grid-template-columns', and 'grid-template-areas'
   962 	together define the <dfn export local-lt="explicit">explicit grid</dfn> of a <a>grid container</a>.
   963 	The 'grid-template' property is a <a>shorthand</a> that sets all three at the same time.
   964 	The final grid may end up larger due to <a>grid items</a> placed outside the <a>explicit grid</a>;
   965 	in this case, any implicit tracks are sized by the 'grid-auto-rows' and 'grid-auto-columns' properties.
   967 	The size of the <a>explicit grid</a> is determined by the larger of
   968 	the number of rows/columns defined by 'grid-template-areas'
   969 	and the number of rows/columns sized by 'grid-template-rows'/'grid-template-columns'.
   970 	Any rows/columns defined by 'grid-template-areas' but not sized by 'grid-template-rows'/'grid-template-columns'
   971 	take their size from the 'grid-auto-rows'/'grid-auto-columns' properties.
   972 	If these properties don't define <em>any</em> <a>explicit</a> tracks,
   973 	the <a>explicit grid</a> still contains one <a>grid line</a> in each axis.
   975 	Numeric indexes in the <a>grid-placement properties</a>
   976 	count from the edges of the <a>explicit grid</a>.
   977 	Positive indexes count from the <a>start</a> side
   978 	(starting from 1 for the <a>start</a>-most <a>explicit</a> line),
   979 	while negative indexes count from the <a>end</a> side
   980 	(starting from -1 for the <a>end</a>-most <a>explicit</a> line).
   982 <h3 id='track-sizing'>
   983 Track Sizing: the 'grid-template-rows' and 'grid-template-columns' properties</h3>
   985 	<pre class='propdef'>
   986 	Name: grid-template-columns, grid-template-rows
   987 	Value: none | <<track-list>> | <<auto-track-list>> | subgrid <<line-name-list>>?
   988 	Initial: none
   989 	Applies to: <a>grid containers</a>
   990 	Inherited: no
   991 	Percentages: refer to corresponding dimension of the content area
   992 	Media: visual
   993 	Computed value: As specified, with lengths made absolute
   994 	Animatable: as a <a href="http://www.w3.org/TR/css3-transitions/#animtype-simple-list">simple list</a> of <a href="http://www.w3.org/TR/css3-transitions/#animtype-lpcalc">length, percentage, or calc</a>, provided the only differences are the values of the <a href="http://www.w3.org/TR/css3-transitions/#animtype-lpcalc">length, percentage, or calc</a> components in the list
   995 	</pre>
   997 	These properties specify,
   998 	as a space-separated <dfn export>track list</dfn>,
   999 	the line names and <a>track sizing functions</a> of the <a>grid</a>.
  1000 	The 'grid-template-columns' property specifies the <a>track list</a> for the grid's columns,
  1001 	while 'grid-template-rows' specifies the <a>track list</a> for the grid's rows.
  1003 	Values have the following meanings:
  1005 	<dl dfn-type="value" dfn-for="grid-template-rows, grid-template-columns">
  1006 		<dt><dfn>none</dfn>
  1007 		<dd>
  1008 			This value indicates that there is no <a>explicit grid</a>;
  1009 			any rows/columns will be <a href="#implicit-grids">implicitly generated</a>,
  1010 			and their size will be determined by the 'grid-auto-rows' and 'grid-auto-columns' properties.
  1012 		<dt><dfn id="track-listing"><<track-list>> | <<auto-track-list>></dfn>
  1013 		<dd>
  1014 			Specifies the <a>track list</a> as a series of <a>track sizing functions</a>
  1015 			and line names.
  1016 			Each <dfn dfn lt="track sizing function|sizing function">track sizing function</dfn> can be specified as a length,
  1017 			a percentage of the <a>grid container</a>’s size,
  1018 			a measurement of the contents occupying the column or row,
  1019 			or a fraction of the free space in the grid.
  1020 			It can also be specified as a range using the ''minmax()'' notation,
  1021 			which can combine any of the previously mentioned mechanisms
  1022 			to specify separate <a lt="min track sizing function">min</a>
  1023 			and <a>max track sizing functions</a> for the column or row.
  1025 		<dt><dfn id="subgrid-listing">subgrid <<line-name-list>></dfn>
  1026 		<dd>
  1027 			The <dfn value for="grid-template-rows, grid-template-columns">subgrid</dfn> value
  1028 			indicates that the grid will adopt the spanned portion of its parent grid in that axis.
  1029 			Rather than being specified explicitly, the sizes of the grid rows/columns
  1030 			will be taken from the parent grid's definition.
  1031 			See [[#subgrids]].
  1033 			The <<line-name-list>> argument allows local naming of the grid lines propagated from the parent grid.
  1034 	</dl>
  1036 	The syntax of a <a>track list</a> is:
  1038 	<pre>
  1039 		<dfn>&lt;track-list></dfn>       = [ <<line-names>>? [ <<track-size>> | <<track-repeat>> ] ]+ <<line-names>>?
  1040 		<dfn>&lt;auto-track-list></dfn>  = [ <<line-names>>? [ <<fixed-size>> | <<fixed-repeat>> ] ]+ <<auto-repeat>>
  1041 		                     [ <<line-names>>? [ <<fixed-size>> | <<fixed-repeat>> ] ]+ <<line-names>>?
  1042 		<dfn>&lt;line-name-list></dfn>   = [ <<line-names>> | <<name-repeat>> ]+
  1044 		<dfn>&lt;track-size></dfn>       = <<track-breadth>> | minmax( <<track-breadth>> , <<track-breadth>> )
  1045 		<dfn>&lt;fixed-size></dfn>       = <<fixed-breadth>> | minmax( <<fixed-breadth>> , <<track-breadth>> )
  1046 		<dfn>&lt;track-breadth></dfn>    = <<length>> | <<percentage>> | <<flex>> | min-content | max-content | auto
  1047 		<dfn>&lt;fixed-breadth></dfn>    = <<length>> | <<percentage>>
  1048 		<dfn>&lt;line-names></dfn>       = '[' <<custom-ident>>* ']'
  1049 	</pre>
  1051 	Where:
  1053 	<dl dfn-for="grid-template-columns, grid-template-rows" dfn-type=value>
  1054 		<dt><dfn><<length>></dfn>
  1055 		<dd>
  1056 			A non-negative length, as defined by CSS3 Values. [[!CSS3VAL]]
  1058 		<dt><dfn><<percentage>></dfn>
  1059 		<dd>
  1060 			A non-negative percentage, as defined by CSS3 Values. [[!CSS3VAL]]
  1061 			<<percentage>> values are relative to the <a>inline size</a> of the <a>grid container</a> in column <a>grid tracks</a>,
  1062 			and the <a>block size</a> of the <a>grid container</a> in row <a>grid tracks</a>.
  1063 			If the <a lt="inline size">inline</a> or <a>block size</a> of the <a>grid container</a>
  1064 			is <a>indefinite</a>,
  1065 			<<percentage>> values relative to that size are treated as <a value for=width>auto</a>.
  1067 		<dt><dfn><<flex>></dfn>
  1068 		<dd>
  1069 			A non-negative dimension with the unit ''fr'' specifying the track's <dfn dfn noexport>flex factor</dfn>.
  1070 			Each <<flex>>-sized track takes a share of the remaining space in proportion to its <a>flex factor</a>.
  1071 			See <a href="#fr-unit">Flexible Lengths</a> for more details.
  1073 			When appearing outside a ''minmax()'' notation,
  1074 			implies an automatic minimum (i.e. ''minmax(auto, <<flex>>)'').
  1076 		<dt><dfn>max-content</dfn>
  1077 		<dd>
  1078 			Represents the largest <a>max-content contribution</a>
  1079 			of the <a>grid items</a> occupying the <a>grid track</a>.
  1081 		<dt><dfn>min-content</dfn>
  1082 		<dd>
  1083 			Represents the largest <a>min-content contribution</a>
  1084 			of the  <a>grid items</a> occupying the <a>grid track</a>.
  1086 		<dt><dfn lt="minmax()">minmax(min, max)</dfn>
  1087 		<dd>
  1088 			Defines a size range
  1089 			greater than or equal to <var>min</var>
  1090 			and less than or equal to <var>max</var>.
  1091 			If <var>max</var> &lt; <var>min</var>,
  1092 			then <var>max</var> is ignored and ''minmax(min,max)'' is treated as <var>min</var>.
  1093 			As a maximum, a <<flex>> value sets the track's <a>flex factor</a>.
  1094 			As a minimum, it is treated as zero
  1095 			(or ''min-content'', if the <a>grid container</a> is sized under a <a>min-content constraint</a>).
  1097 		<dt><dfn>auto</dfn>
  1098 		<dd>
  1099 			As a maximum, identical to ''max-content''.
  1100 			As a minimum, represents the largest minimum size (as specified by 'min-width'/'min-height')
  1101 			of the <a>grid items</a> occupying the <a>grid track</a>.
  1103 			Note: ''grid-template-rows/auto'' track sizes (and only ''grid-template-rows/auto'' track sizes)
  1104 			can be streched by the 'align-content' and 'justify-content' properties.
  1105 	</dl>
  1107 	<div class='example'>
  1108 		Given the following 'grid-template-columns' declaration:
  1110 		<pre>grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);</pre>
  1112 		Five grid lines are created:
  1114 		<ol>
  1115 			<li>
  1116 				At the start edge of the <a>grid container</a>.
  1118 			<li>
  1119 				100px from the start edge of the <a>grid container</a>.
  1121 			<li>
  1122 				A distance from the previous line equal to half the <a>free space</a>
  1123 				(the width of the <a>grid container</a>, minus the width of the non-flexible <a>grid tracks</a>).
  1125 			<li>
  1126 				A distance from the previous line equal to the maximum size of any <a>grid items</a>
  1127 				belonging to the column between these two lines.
  1129 			<li>
  1130 				A distance from the previous line at least as large as the largest minimum size of any <a>grid items</a>
  1131 				belonging to the column between these two lines,
  1132 				but no larger than the other half of the <a>free space</a>.
  1133 		</ol>
  1135 		If the non-flexible sizes
  1136 		(''100px'', ''max-content'', and ''min-content'')
  1137 		sum to larger than the <a>grid container</a>’s width,
  1138 		the final <a>grid line</a> will be a distance equal to their sum away from the start edge of the <a>grid container</a>
  1139 		(the ''1fr'' sizes both resolve to ''0'').
  1140 		If the sum is less than the <a>grid container</a>’s width,
  1141 		the final <a>grid line</a> will be exactly at the end edge of the <a>grid container</a>.
  1142 		This is true in general whenever there's at least one <<flex>> value among the <a>grid track</a> sizes.
  1143 	</div>
  1145 	<div class='example'>
  1146 		Additional examples of valid <a>grid track</a> definitions:
  1148 		<pre>
  1149 			/* examples of valid track definitions */
  1150 			grid-template-rows: 1fr minmax(min-content, 1fr);
  1151 			grid-template-rows: 10px repeat(2, 1fr auto minmax(30%, 1fr));
  1152 			grid-template-rows: calc(4em - 5px);
  1153 		</pre>
  1154 	</div>
  1156 	Note: The size of the grid is not purely the sum of the track sizes,
  1157 	as 'grid-row-gap', 'grid-column-gap' and  'justify-content', 'align-content'
  1158 	can add additional space between tracks.
  1160 <!--
  1161 ██    ██    ███    ██     ██ ████████ ████████        ██       ████ ██    ██ ████████  ██████
  1162 ███   ██   ██ ██   ███   ███ ██       ██     ██       ██        ██  ███   ██ ██       ██    ██
  1163 ████  ██  ██   ██  ████ ████ ██       ██     ██       ██        ██  ████  ██ ██       ██
  1164 ██ ██ ██ ██     ██ ██ ███ ██ ██████   ██     ██       ██        ██  ██ ██ ██ ██████    ██████
  1165 ██  ████ █████████ ██     ██ ██       ██     ██       ██        ██  ██  ████ ██             ██
  1166 ██   ███ ██     ██ ██     ██ ██       ██     ██       ██        ██  ██   ███ ██       ██    ██
  1167 ██    ██ ██     ██ ██     ██ ████████ ████████        ████████ ████ ██    ██ ████████  ██████
  1168 -->
  1170 <h4 id='named-lines'>
  1171 Named Grid Lines: the <css>[<<custom-ident>>*]</css> syntax</h4>
  1173 	While <a>grid lines</a> can always be referred to by their numerical index,
  1174 	<dfn export lt="named line">named lines</dfn>
  1175 	can make the <a>grid-placement properties</a> easier to understand and maintain.
  1176 	Lines can be explicitly named in the 'grid-template-rows' and 'grid-template-columns' properties,
  1177 	or <a href="#implicit-named-lines">implicitly named</a> by creating <a>named grid areas</a> with the 'grid-template-areas' property.
  1179 	<div class='example'>
  1180 		For example,
  1181 		the following code gives meaningful names to all of the lines in the grid.
  1182 		Note that some of the lines have multiple names.
  1184 		<pre>
  1185 			#grid {
  1186 				display: grid;
  1187 				grid-template-columns: [first nav-start] 150px [main-start] 1fr [last];
  1188 				grid-template-rows: [first header-start] 50px [main-start] 1fr [footer-start] 50px [last];
  1190 		</pre>
  1192 		<figure class="figure">
  1193 			<img class="figure" alt="Image: Named Grid Lines." src="images/grid-named-lines.png" />
  1194 			<figcaption>Named Grid Lines.</figcaption>
  1195 		</figure>
  1196 	</div>
  1198 <!--
  1199 ████████  ████████ ████████  ████████    ███    ████████   ███ ███
  1200 ██     ██ ██       ██     ██ ██         ██ ██      ██     ██     ██
  1201 ██     ██ ██       ██     ██ ██        ██   ██     ██    ██       ██
  1202 ████████  ██████   ████████  ██████   ██     ██    ██    ██       ██
  1203 ██   ██   ██       ██        ██       █████████    ██    ██       ██
  1204 ██    ██  ██       ██        ██       ██     ██    ██     ██     ██
  1205 ██     ██ ████████ ██        ████████ ██     ██    ██      ███ ███
  1206 -->
  1208 <h4 id='repeat-notation'>
  1209 Repeating Rows and Columns: the ''repeat()'' notation</h4>
  1211 	The <dfn>repeat()</dfn> notation represents a repeated fragment of the <a>track list</a>,
  1212 	allowing a large number of columns or rows that exhibit a recurring pattern
  1213 	to be written in a more compact form.
  1214 	The syntax of the ''repeat()'' notation
  1215 	has several forms:
  1217 	<pre class='prod'>
  1218 		<dfn><<track-repeat>></dfn> = repeat( [ <<positive-integer>> ]  , [ <<line-names>>? <<track-size>> ]+ <<line-names>>? )
  1219 		<dfn><<auto-repeat>></dfn>  = repeat( [ auto-fill | auto-fit ],   <<line-names>>? <<fixed-size>>    <<line-names>>? )
  1220 		<dfn><<fixed-repeat>></dfn> = repeat( [ <<positive-integer>> ]  , [ <<line-names>>? <<fixed-size>> ]+ <<line-names>>? )
  1221 		<dfn><<name-repeat>></dfn>  = repeat( [ <<positive-integer>> | auto-fill ], <<line-names>>+)
  1222 	</pre>
  1224 	The first argument specifies the number of repetitions.
  1225 	The second argument is a <a>track list</a>,
  1226 	which is repeated that number of times.
  1228 	* The <<track-repeat>> variant can represent the repetition of any <<track-size>>,
  1229 		but is limited to a fixed number of repetitions.
  1230 	* The <<auto-repeat>> variant can repeat automatically to fill a space,
  1231 		but requires <a>definite</a> minimum track sizes so that the number of repetitions can be calculated.
  1232 		It can only appear once in the <a>track list</a>,
  1233 		but the same <a>track list</a> can also contain <<fixed-repeat>>s.
  1234 	* The <<name-repeat>> variant is for adding line names to <a href="#subgrids">subgrids</a>
  1235 		and can only be used with the ''grid-template-rows/subgrid'' keyword:
  1236 		it only repeats names.
  1237 		The ''auto-fill'' keyword is only valid once per <<line-name-list>>,
  1238 		and repeats enough times for the name list to match the subgrid’s specified <a>grid span</a>
  1239 		(defaulting to 0 if that is ''auto'' or if the span is already fulfilled).
  1241 	<div class='example'>
  1242 		This example shows two equivalent ways of writing the same grid definition.
  1243 		Both ways produce a grid with a single row and four "main" columns, each 250px wide,
  1244 		surrounded by 10px "gutter" columns.
  1246 		<pre>
  1247 			#grid {
  1248 				display: grid;
  1249 				grid-template-columns: 10px [col-start] 250px [col-end]
  1250 				                       10px [col-start] 250px [col-end]
  1251 				                       10px [col-start] 250px [col-end]
  1252 				                       10px [col-start] 250px [col-end] 10px;
  1253 				grid-template-rows: 1fr;
  1256 			/* Equivalent definition. */
  1257 			#grid {
  1258 				display: grid;
  1259 				grid-template-columns: repeat(4, 10px [col-start] 250px [col-end]) 10px;
  1260 				grid-template-rows: 1fr;
  1262 		</pre>
  1263 	</div>
  1265 	If the ''repeat()'' function ends up placing two <<line-names>> adjacent to each other,
  1266 	the name lists are merged.
  1267 	For example, ''repeat(2, [a] 1fr [b])'' is equivalent to ''[a] 1fr [b a] 1fr [b]''.
  1269 	When <dfn value for="repeat()">auto-fill</dfn> is given as the repetition number,
  1270 	if the <a>grid container</a> has a <a>definite</a> size or max size in the relevant axis,
  1271 	then the number of repetitions is the largest possible positive integer
  1272 	that does not cause the <a>grid</a> to overflow its <a>grid container</a>
  1273 	(treating each track as its <a>max track sizing function</a> if that is <a>definite</a>
  1274 	or as its minimum track sizing function otherwise,
  1275 	and taking 'grid-gap' into account);
  1276 	if any number of repetitions would overflow,
  1277 	then 1 repetition.
  1278 	Otherwise, if the <a>grid container</a> has a <a>definite</a> min size in the relevant axis,
  1279 	the number of repetitions is the smallest possible positive integer that fulfills that minimum requirement.
  1280 	Otherwise, the specified <a>track list</a> repeats only once.
  1282 	For the purpose of finding the number of auto-repeated tracks,
  1283 	the UA must floor the track size to a UA-specified value
  1284 	to avoid division by zero.
  1285 	It is suggested that this floor be ''1px''.
  1287 	The <dfn value for="repeat()">auto-fit</dfn> keyword behaves the same as ''auto-fill'',
  1288 	except that after <a href="#auto-placement-algo">grid item placement</a>
  1289 	any empty repetitions are dropped.
  1290 	(An empty track is one with no in-flow grid items placed into or spanning across it.)
  1291 	(This can result in <em>all</em> tracks being dropped,
  1292 	if they're all empty.)
  1294 	Issue: In order to simplify implementation and testing requirements for Level 1,
  1295 	the <<auto-repeat>> syntax only accepts a single <<fixed-size>>.
  1296 	Now that we have gutters, most use cases for auto-repetition will need only one track size.
  1297 	However, if there are important use cases for having a full track listing,
  1298 	the CSSWG is not opposed to expanding the syntax;
  1299 	please send such use cases to [email protected]
  1300 	for consideration.
  1302 <!--
  1303 ████████ ████████        ██     ██ ██    ██ ████ ████████
  1304 ██       ██     ██       ██     ██ ███   ██  ██     ██
  1305 ██       ██     ██       ██     ██ ████  ██  ██     ██
  1306 ██████   ████████        ██     ██ ██ ██ ██  ██     ██
  1307 ██       ██   ██         ██     ██ ██  ████  ██     ██
  1308 ██       ██    ██        ██     ██ ██   ███  ██     ██
  1309 ██       ██     ██        ███████  ██    ██ ████    ██
  1310 -->
  1312 <h4 id='fr-unit'>
  1313 Flexible Lengths: the ''fr'' unit</h4>
  1315 	A <dfn export>flexible length</dfn> or <dfn><<flex>></dfn> is a dimension with the ''fr'' unit,
  1316 	which represents a fraction of the <a>free space</a> in the <a>grid container</a>.
  1318 	The distribution of <a>free space</a> occurs after all non-flexible <a>track sizing functions</a> have reached their maximum.
  1319 	The total size of such rows or columns is subtracted from the available space, yielding the <a>free space</a>,
  1320 	which is then divided among the flex-sized rows and columns in proportion to their <a>flex factor</a>.
  1322 	Note: Flexible lengths in a <a>track list</a> work similarly to flexible lengths with a zero base size in [[CSS3-FLEXBOX]].
  1324 	Each column or row's share of the <a>free space</a> can be computed as the column or row's
  1325 	<code>&lt;flex> * &lt;free space> / &lt;sum of all <a>flex factors</a>&gt;</code>.
  1326 	For the purpose of this calculation,
  1327 	a flexible length in the <var>min</var> position of a ''minmax()'' function is treated as ''0'' (an inflexible length).
  1329 	Note: If the sum of the <a>flex factors</a> is less than 1,
  1330 	they'll take up only a corresponding fraction of the <a>free space</a>,
  1331 	rather than expanding to fill the entire thing.
  1332 	This is similar to how Flexbox [[CSS-FLEXBOX-1]] acts when the sum of the 'flex' values is less than 1.
  1334 	When the available space is infinite
  1335 	(which happens when the <a>grid container</a>’s width or height is <a>indefinite</a>),
  1336 	flex-sized <a>grid tracks</a> are sized to their contents while retaining their respective proportions.
  1337 	The used size of each flex-sized <a>grid track</a> is computed by
  1338 	determining the ''max-content'' size of each flex-sized <a>grid track</a>
  1339 	and dividing that size by the respective <a>flex factor</a>
  1340 	to determine a “hypothetical ''1fr'' size”.
  1341 	The maximum of those is used as the resolved ''1fr'' length (the <dfn>flex fraction</dfn>),
  1342 	which is then multiplied by each <a>grid track</a>’s <a>flex factor</a> to determine its final size.
  1344 <!--
  1345  ██████  ██     ██ ████████   ██████   ████████  ████ ████████
  1346 ██    ██ ██     ██ ██     ██ ██    ██  ██     ██  ██  ██     ██
  1347 ██       ██     ██ ██     ██ ██        ██     ██  ██  ██     ██
  1348  ██████  ██     ██ ████████  ██   ████ ████████   ██  ██     ██
  1349       ██ ██     ██ ██     ██ ██    ██  ██   ██    ██  ██     ██
  1350 ██    ██ ██     ██ ██     ██ ██    ██  ██    ██   ██  ██     ██
  1351  ██████   ███████  ████████   ██████   ██     ██ ████ ████████
  1352 -->
  1354 <h4 id="subgrids">
  1355 Subgrids: the ''grid-template-rows/subgrid'' keyword</h4>
  1357 	A <a>grid item</a> can itself be a <a>grid container</a> by giving it ''display: grid'';
  1358 	in this case the layout of its contents will be independent of the layout of the grid it participates in.
  1360 	In some cases it might be necessary for the contents of multiple <a>grid items</a> to align to each other.
  1361 	A <a>grid container</a> that is itself a <a>grid item</a>
  1362 	can defer the definition of its rows or columns to its parent <a>grid container</a>
  1363 	by using the ''grid-template-rows/subgrid'' keyword in 'grid-template-rows' and/or 'grid-template-columns',
  1364 	making it a <dfn export>subgrid</dfn> in that dimension.
  1365 	In this case, the <a>grid items</a> of the <a>subgrid</a>
  1366 	participate in sizing the <a>grid</a> of the parent <a>grid container</a>,
  1367 	allowing the contents of both grids to align.
  1369 	If a <a>grid container</a> that is <em>not</em> a <a>grid item</a> uses the ''grid-template-rows/subgrid'' keyword,
  1370 	its 'grid-template-rows'/'grid-template-columns' value is treated identically to ''grid-template-rows/none''
  1371 	(i.e. it doesn't have an <a>explicit grid</a> in that dimension).
  1373 	<div class="example">
  1374 			For example, suppose we have a form consisting of a list of inputs with labels:
  1375 		<pre>
  1376 			&lt;ul>
  1377 				&lt;li>&lt;label>Name:&lt;/label> &lt;input name=fn>
  1378 				&lt;li>&lt;label>Address:&lt;/label> &lt;input name=address>
  1379 				&lt;li>&lt;label>Phone:&lt;/label> &lt;input name=phone>
  1380 			&lt;/ul>
  1381 		</pre>
  1383 		We want the labels and inputs to align, and we want to style each list item with a border.
  1384 		This can be accomplished with subgrid layout:
  1386 		<pre>
  1387 			ul {
  1388 				display: grid;
  1389 				grid-auto-flow: row;
  1390 				grid-template-columns: auto 1fr;
  1392 			li {
  1393 				display: grid;
  1394 				grid: subgrid;
  1395 				margin: 0.5em;
  1396 				border: solid;
  1397 				padding: 0.5em;
  1399 			label {
  1400 				grid-column: 1;
  1402 			input {
  1403 				grid-column: 2;
  1405 		</pre>
  1406 	</div>
  1408 	A <a>subgrid</a> behaves just like a normal <a>grid container</a> except that:
  1410 	<ul style="list-style-type: lower-alpha">
  1411 		<li>
  1412 			The number of explicit tracks is given by its <a>grid span</a>,
  1413 			rather than by 'grid-template-rows'/'grid-template-columns'.
  1414 			If the grid has an <a>automatic grid span</a>,
  1415 			the number of tracks is determined by the size of the <a>subgrid</a>’s <a>implicit grid</a>.
  1417 		<li>
  1418 			The <a>grid-placement properties</a> of the <a>subgrid</a>’s <a>grid items</a>
  1419 			are scoped to the lines covered by the subgrid.
  1420 			E.g., numeric indices count starting from the first line of the subgrid
  1421 			rather than the first line of the parent grid.
  1423 		<li>
  1424 			The <a>subgrid</a>'s own grid items participate in the sizing of its parent grid and are aligned to it.
  1425 			In this process, the sum of the <a>subgrid</a>'s margin, padding, and borders are applied as an extra layer of margin to the items at those edges.
  1427 			<div class="example">
  1428 				For example, if we have a 3&times;3 grid with the following tracks:
  1430 				<pre>#parent-grid { grid-template-columns: 300px auto 300px; }</pre>
  1432 				If a subgrid covers the last two tracks, its first two columns correspond to the parent grid's last two columns,
  1433 				and any items positioned into those tracks participate in sizing the parent grid.
  1434 				Specifically, an item positioned in the first track of the subgrid
  1435 				influences the auto-sizing of the parent grid's middle track.
  1437 				<pre>
  1438 					#subgrid { grid-column: 2 / span 2; } /* cover parent's 2nd and 3rd tracks */
  1439 					#subgrid :first-child { grid-column: 1; } /* subgrid's 1st track, parent grid's 2nd track */
  1440 				</pre>
  1442 				If the subgrid has margins/borders/padding,
  1443 				the the size of those margins/borders/padding also influence sizing.
  1444 				For example, if the subgrid has 100px padding:
  1446 				<pre>#subgrid { padding: 100px; }</pre>
  1448 				Then when the parent grid auto-sizes its second track,
  1449 				it will be at least 100px wider than any items in the subgrid's first track,
  1450 				and any items in the subgrid's second track will be sized to fit a slot 200px wide (instead of 300px wide).
  1451 			</div>
  1453 			However, any overflow tracks
  1454 			(i.e. those outside the <a>explicit grid</a> when the <a>subgrid</a> has a <a>definite grid span</a>)
  1455 			do not correspond to any tracks in the parent grid;
  1456 			they effectively extend in a third dimension.
  1458 			<div class="example">
  1459 				For example, if a parent grid has adjacent tracks <var>A</var>, <var>B</var>, and <var>C</var>,
  1460 				and a ''span 1'' subgrid with an extra <a>implicit grid track</a> is placed in track <var>B</var>,
  1461 				the items in that <a>implicit grid track</a> are not considered part of track <var>B</var>.
  1462 			</div>
  1464 		<li>
  1465 			The <a>subgrid</a> is always stretched in its subgridded dimension:
  1466 			the 'align-self'/'justify-self' properties on it are ignored in that dimension,
  1467 			and any specified width/height constraints are also ignored in that dimension.
  1469 		<li>
  1470 			Layoutwise, the <a>subgrid</a>’s <a>explicit grid</a> is always aligned with the corresponding section of the parent <a>grid</a>;
  1471 			the 'align-content'/'justify-content' properties on it are ignored.
  1472 			However, 'overflow' does apply,
  1473 			so the contents of the subgrid can be scrolled aside.
  1474 			(Note: the act of scrolling does not affect layout.)
  1476 		<li>
  1477 			Explicit named lines can also be specified together with the ''grid-template-rows/subgrid'' keyword;
  1478 			these names apply (within the <a>subgrid</a>) to the corresponding lines of the parent <a>grid</a>.
  1479 			If the <a>subgrid</a> has an explicit <a>grid span</a>,
  1480 			any names specified for lines beyond the span are ignored.
  1482 			<div class="example">
  1483 				For example, if the subgrid above were specified with 5 names:
  1485 				<pre>#subgrid { grid-template-columns: subgrid [first] [second] [third] [fourth] [fifth]; }</pre>
  1487 				Items within the subgrid could be positioned using the first four line names;
  1488 				the last name would be ignored (as if it didn't exist),
  1489 				since the subgrid only covers four lines.
  1490 			</div>
  1492 			If the <a>subgrid</a> has an explicit <a>grid position</a> as well as an explicit <a>grid span</a>,
  1493 			it also automatically receives the line names specified for its parent <a>grid</a>.
  1494 			(In such cases the author can rely on the names specified in the parent grid,
  1495 			and does not need to duplicate those names in each subgrid declaration.)
  1497 			Issue: People should review how subgrid line names are assigned, to ensure it is sane and useful.
  1498 	</ul>
  1500 <!--
  1501 ████████  ████████  ██████   ███████  ██       ██     ██ ████████ ████████
  1502 ██     ██ ██       ██    ██ ██     ██ ██       ██     ██ ██       ██     ██
  1503 ██     ██ ██       ██       ██     ██ ██       ██     ██ ██       ██     ██
  1504 ████████  ██████    ██████  ██     ██ ██       ██     ██ ██████   ██     ██
  1505 ██   ██   ██             ██ ██     ██ ██        ██   ██  ██       ██     ██
  1506 ██    ██  ██       ██    ██ ██     ██ ██         ██ ██   ██       ██     ██
  1507 ██     ██ ████████  ██████   ███████  ████████    ███    ████████ ████████
  1508 -->
  1510 <h4 id='resolved-track-list'>
  1511 Resolved Values</h4>
  1513 	When an element's 'display' is ''grid'' or ''inline-grid'' and it generates a box,
  1514 	the <a href="http://www.w3.org/TR/cssom/#resolved-values">resolved value</a>
  1515 	of the 'grid-template-rows' and 'grid-template-columns' properties is the used value,
  1516 	serialized as follows:
  1518 	<ul>
  1519 		<li>
  1520 			Every track listed,
  1521 			whether implicitly or explicitly created.
  1523 		<li>
  1524 			Every track size given as a length in pixels,
  1525 			regardless of sizing function.
  1527 		<li>
  1528 			A contiguous run of two or more tracks that have the same size and associated line names
  1529 			may be serialized with the ''repeat()'' notation.
  1530 	</ul>
  1532 	Otherwise, (e.g. when the element has ''display: none'' or is not a grid)
  1533 	the resolved value is simply the computed value.
  1535 	<div class="example">
  1536 		<pre>
  1537 			#grid {
  1538 				width: 500px;
  1539 				grid-template-columns:
  1540 				  [a]     auto
  1541 				  [b]     minmax(min-content, 1fr)
  1542 				  [b c d] repeat(2, [e] 40px)
  1543 				          repeat(5, auto);
  1545 			&lt;/style>
  1546 			&lt;div id="grid">
  1547 			  &lt;div style="grid-column-start:1; width:50px">&lt;/div>
  1548 			  &lt;div style="grid-column-start:9; width:50px">&lt;/div>
  1549 			&lt;/div>
  1550 			&lt;script>
  1551 			  var gridElement = document.getElementById("grid");
  1552 			  getComputedStyle(gridElement).gridTemplateColumns;
  1553 			  // [a] 50px [b] 320px [b c d] repeat(2, [e] 40px) repeat(4, 0px) 50px
  1554 		</pre>
  1555 	</div>
  1557 	Note: In general, resolved values are the computed values,
  1558 	except for a small list of legacy 2.1 properties.
  1559 	However, compatibility with early implementations of this module
  1560 	requires us to define 'grid-template-rows' and 'grid-template-columns' as returning used values.
  1561 	Authors are recommended to use the
  1562 	<a href="https://drafts.csswg.org/cssom/#the-getstyleutils-interface"><code>.rawComputedStyle</code> and <code>.usedStyle</code> attributes</a>
  1563 	instead of <code>getComputedStyle()</code>.
  1565 <!--
  1566  ██████   ████████  ████ ████████           ███    ████████  ████████    ███     ██████
  1567 ██    ██  ██     ██  ██  ██     ██         ██ ██   ██     ██ ██         ██ ██   ██    ██
  1568 ██        ██     ██  ██  ██     ██        ██   ██  ██     ██ ██        ██   ██  ██
  1569 ██   ████ ████████   ██  ██     ██       ██     ██ ████████  ██████   ██     ██  ██████
  1570 ██    ██  ██   ██    ██  ██     ██       █████████ ██   ██   ██       █████████       ██
  1571 ██    ██  ██    ██   ██  ██     ██       ██     ██ ██    ██  ██       ██     ██ ██    ██
  1572  ██████   ██     ██ ████ ████████        ██     ██ ██     ██ ████████ ██     ██  ██████
  1573 -->
  1575 <h3 id="grid-template-areas-property">
  1576 Named Areas: the 'grid-template-areas' property</h3>
  1578 	<pre class='propdef'>
  1579 	Name: grid-template-areas
  1580 	Value: none | <<string>>+
  1581 	Initial: none
  1582 	Applies to: <a>grid containers</a>
  1583 	Inherited: no
  1584 	Percentages: n/a
  1585 	Media: visual
  1586 	Computed value: specified value
  1587 	</pre>
  1589 	This property specifies <dfn export lt="named grid area">named grid areas</dfn>,
  1590 	which are not associated with any particular <a>grid item</a>,
  1591 	but can be referenced from the <a>grid-placement properties</a>.
  1592 	The syntax of the 'grid-template-areas' property also provides a visualization
  1593 	of the structure of the <a>grid</a>,
  1594 	making the overall layout of the <a>grid container</a> easier to understand.
  1596 	Values have the following meanings:
  1598 	<dl dfn-for="grid-template-areas" dfn-type=value>
  1599 		<dt><dfn>none</dfn>
  1600 		<dd>
  1601 			The <a>grid container</a> doesn't define any <a>named grid areas</a>.
  1603 		<dt><dfn><<string>>+</dfn>
  1604 		<dd>
  1605 			A row is created for every separate string listed for the 'grid-template-areas' property,
  1606 			and a column is created for each cell in the string,
  1607 			when parsed as follows:
  1609 			Tokenize the string into a list of the following tokens,
  1610 			using longest-match semantics:
  1612 			<ul dfn-type="dfn">
  1613 				<li>
  1614 					A sequence of <a>name code points</a>,
  1615 					representing a <dfn>named cell token</dfn>
  1616 					with a name consisting of its code points.
  1617 				<li>
  1618 					A sequence of one or more "." (U+002E FULL STOP),
  1619 					representing a <dfn>null cell token</dfn>.
  1621 				<li>
  1622 					A sequence of <a>whitespace</a>,
  1623 					representing nothing
  1624 					(do not produce a token).
  1626 				<li>
  1627 					A sequence of any other characters,
  1628 					representing a <dfn>trash token</dfn>.
  1629 			</ul>
  1631 			Note: These rules can produce cell names that do not match the <<ident>> syntax,
  1632 			such as "1st 2nd 3rd",
  1633 			which requires escaping when referencing those areas by name in other properties,
  1634 			like ''grid-row: \31st;'' to reference the area named ''1st''.
  1636 			<ul>
  1637 				<li>
  1638 					A <a>null cell token</a> represents an unnamed area in the <a>grid container</a>.
  1640 				<li>
  1641 					A <a>named cell token</a> creates a <a>named grid area</a> with the same name.
  1642 					Multiple <a>named cell tokens</a> within and between rows
  1643 					create a single <a>named grid area</a> that spans the corresponding <a>grid cells</a>.
  1645 				<li>
  1646 					A <a>trash token</a> is a syntax error,
  1647 					and makes the declaration invalid.
  1648 			</ul>
  1650 			All strings must have the same number of columns,
  1651 			or else the declaration is invalid.
  1652 			If a <a>named grid area</a> spans multiple <a>grid cells</a>,
  1653 			but those cells do not form a single filled-in rectangle,
  1654 			the declaration is invalid.
  1656 			Note: Non-rectangular or disconnected regions may be permitted in a future version of this module.
  1657 	</dl>
  1660 	<div class='example'>
  1661 		In this example, the 'grid-template-areas' property is used to create a page layout
  1662 		where areas are defined for header content (<code>head</code>),
  1663 		navigational content (<code>nav</code>),
  1664 		footer content (<code>foot</code>),
  1665 		and main content (<code>main</code>).
  1666 		Accordingly, the template creates three rows and two columns,
  1667 		with four <a>named grid areas</a>.
  1668 		The <code>head</code> area spans both columns and the first row of the grid.
  1670 		<pre>
  1671 			#grid {
  1672 				display: grid;
  1673 				grid-template-areas: "head head"
  1674 				                     "nav  main"
  1675 				                     "foot ...."
  1677 			#grid > header { grid-area: head; }
  1678 			#grid > nav    { grid-area: nav; }
  1679 			#grid > main   { grid-area: main; }
  1680 			#grid > footer { grid-area: foot; }
  1681 		</pre>
  1682 	</div>
  1684 <h4 id="implicit-named-lines">
  1685 Implicit Named Lines</h4>
  1687 	The 'grid-template-areas' property creates <dfn export lt="implicit named line">implicit named lines</dfn> from the <a>named grid areas</a> in the template.
  1688 	For each <a>named grid area</a> <var>foo</var>, four <a>implicit named lines</a> are created:
  1689 	two named <css><var>foo</var>-start</css>, naming the row-start and column-start lines of the <a>named grid area</a>,
  1690 	and two named <css><var>foo</var>-end</css>, naming the row-end and column-end lines of the <a>named grid area</a>.
  1692 	These named lines behave just like any other named line,
  1693 	except that they do not appear in the value of 'grid-template-rows'/'grid-template-columns'.
  1694 	Even if an explicit line of the same name is defined,
  1695 	the implicit named lines are just more lines with the same name.
  1697 <h4 id="implicit-named-areas">
  1698 Implicit Named Areas</h4>
  1700 	Since a <a>named grid area</a> is referenced by the <a>implicit named lines</a> it produces,
  1701 	explicitly adding named lines of the same form (''foo-start''/''foo-end'')
  1702 	effectively creates a <a>named grid area</a>.
  1703 	Such <dfn export lt="implicit named area">implicit named areas</dfn> do not appear in the value of 'grid-template-areas',
  1704 	but can still be referenced by the <a>grid-placement properties</a>.
  1706 <!--
  1707  ██████   ████████  ████ ████████          ████████ ████████ ██     ██ ████████  ██          ███    ████████ ████████
  1708 ██    ██  ██     ██  ██  ██     ██            ██    ██       ███   ███ ██     ██ ██         ██ ██      ██    ██
  1709 ██        ██     ██  ██  ██     ██            ██    ██       ████ ████ ██     ██ ██        ██   ██     ██    ██
  1710 ██   ████ ████████   ██  ██     ██ ███████    ██    ██████   ██ ███ ██ ████████  ██       ██     ██    ██    ██████
  1711 ██    ██  ██   ██    ██  ██     ██            ██    ██       ██     ██ ██        ██       █████████    ██    ██
  1712 ██    ██  ██    ██   ██  ██     ██            ██    ██       ██     ██ ██        ██       ██     ██    ██    ██
  1713  ██████   ██     ██ ████ ████████             ██    ████████ ██     ██ ██        ████████ ██     ██    ██    ████████
  1714 -->
  1716 <h3 id='explicit-grid-shorthand'>
  1717 Explicit Grid Shorthand: the 'grid-template' property</h3>
  1719 	<pre class='propdef'>
  1720 	Name: grid-template
  1721 	Value: none | subgrid | <nobr>[ <<'grid-template-rows'>> / <<'grid-template-columns'>> ]</nobr> | <nobr>[ <<line-names>>? <<string>> <<track-size>>? <<line-names>>? ]+ [ / <<track-list>> ]?</nobr>
  1722 	Initial: see individual properties
  1723 	Applies to: <a>grid containers</a>
  1724 	Inherited: see individual properties
  1725 	Percentages: see individual properties
  1726 	Media: visual
  1727 	Computed value: see individual properties
  1728 	</pre>
  1730 	The 'grid-template' property is a <a>shorthand</a> for setting
  1731 	'grid-template-columns', 'grid-template-rows', and 'grid-template-areas' in a single declaration.
  1732 	It has several distinct syntax forms:
  1734 	<dl dfn-for=grid-template dfn-type=value>
  1735 		<dt><dfn>none</dfn>
  1736 		<dd>
  1737 			Sets all three properties to their initial values (<a value for=grid-template-rows>none</a>).
  1739 		<dt><dfn>subgrid</dfn>
  1740 		<dd>
  1741 			Sets 'grid-template-rows' and 'grid-template-columns' to ''grid-template-rows/subgrid'',
  1742 			and 'grid-template-areas' to its initial value.
  1744 		<dt><dfn id='grid-template-rowcol'><<'grid-template-rows'>> / <<'grid-template-columns'>></dfn>
  1745 		<dd>
  1746 			Sets 'grid-template-rows' and 'grid-template-columns' to the specified values, respectively,
  1747 			and sets 'grid-template-areas' to ''grid-template-areas/none''.
  1749 			<div class='example'>
  1750 				<pre>grid-template: auto 1fr / auto 1fr auto;</pre>
  1752 					is equivalent to
  1754 				<pre>
  1755 					grid-template-rows: auto 1fr;
  1756 					grid-template-columns: auto 1fr auto;
  1757 					grid-template-areas: none;
  1758 				</pre>
  1759 			</div>
  1761 		<dt><dfn id='grid-template-ascii'>[ <<line-names>>? <<string>> <<track-size>>? <<line-names>>? ]+ [ / <<track-list>> ]?</dfn>
  1762 		<dd>
  1763 			* Sets 'grid-template-areas' to the strings listed.
  1764 			* Sets 'grid-template-rows' to the <<track-size>>s following each string
  1765 				(filling in ''grid-template-rows/auto'' for any missing sizes),
  1766 				and splicing in the named lines defined before/after each size.
  1767 			* Sets 'grid-template-columns' to the track listing specified after the slash
  1768 				(or ''grid-template-columns/none'', if not specified).
  1770 			This syntax allows the author to align track names and sizes inline with their respective grid areas.
  1772 			<div class='example'>
  1773 				<pre>
  1774 					grid-template: [header-top] "a   a   a"     [header-bottom]
  1775 					                 [main-top] "b   b   b" 1fr [main-bottom]
  1776 					                          / auto 1fr auto;
  1777 				</pre>
  1779 					is equivalent to
  1781 				<pre>
  1782 					grid-template-areas: "a a a"
  1783 					                     "b b b";
  1784 					grid-template-rows: [header-top] auto [header-bottom main-top] 1fr [main-bottom];
  1785 					grid-template-columns: auto 1fr auto;
  1786 				</pre>
  1787 			</div>
  1788 	</dl>
  1790 	Note: The 'grid' shorthand accepts the same syntax,
  1791 	but also resets the implicit grid properties to their initial values.
  1792 	Unless authors want those to cascade in separately,
  1793 	it is therefore recommended to use 'grid' instead of 'grid-template'.
  1795 <!--
  1796 ████ ██     ██ ████████  ██       ████  ██████  ████ ████████
  1797  ██  ███   ███ ██     ██ ██        ██  ██    ██  ██     ██
  1798  ██  ████ ████ ██     ██ ██        ██  ██        ██     ██
  1799  ██  ██ ███ ██ ████████  ██        ██  ██        ██     ██
  1800  ██  ██     ██ ██        ██        ██  ██        ██     ██
  1801  ██  ██     ██ ██        ██        ██  ██    ██  ██     ██
  1802 ████ ██     ██ ██        ████████ ████  ██████  ████    ██
  1803 -->
  1805 <h2 id='implicit-grids'>
  1806 The Implicit Grid</h2>
  1808 	The 'grid-template' property and its longhands define a fixed number of tracks that form the <a>explicit grid</a>.
  1809 	When <a>grid items</a> are positioned outside of these bounds,
  1810 	the <a>grid container</a> generates
  1811 	<dfn export lt="implicit grid track|implicit grid row|implicit grid column">implicit grid tracks</dfn>
  1812 	by adding <dfn>implicit grid lines</dfn> to the <a>grid</a>.
  1813 	These lines together with the <a>explicit grid</a> form the <dfn export local-lt="implicit">implicit grid</dfn>.
  1814 	The 'grid-auto-rows' and 'grid-auto-columns' properties size these <a>implicit grid tracks</a>.
  1816 	The 'grid-auto-flow' property controls auto-placement of <a>grid items</a>
  1817 	without an explicit position.
  1818 	Once the <a>explicit grid</a> is filled
  1819 	(or if there is no <a>explicit grid</a>)
  1820 	auto-placement will also cause the generation of <a>implicit grid tracks</a>.
  1822 	<div class='example'>
  1823 		This example illustrates the sizing of <a>implicit grid tracks</a>.
  1824 		Note that <a>grid item</a> B is positioned on <a>grid line</a> 5,
  1825 		which automatically creates <strong>four</strong> <a>implicit grid columns</a>.
  1826 		However, only two of them
  1827 		(the first and the last)
  1828 		are occupied by any <a>grid items</a>,
  1829 		so the two empty <a>grid tracks</a>
  1830 		collapse to zero width.
  1832 		<figure class="figure">
  1833 			<img alt="" src="images/implicit-columns-and-rows.svg">
  1835 			<figcaption>
  1836 				A Grid with an implicit row and four implicit columns, two of which are zero-sized.
  1837 				The black grid lines are from the <a>explicit grid</a>,
  1838 				the gray grid lines are from the <a>implicit grid</a>.
  1839 				The numbers indicate the line indexes.
  1840 			</figcaption>
  1841 		</figure>
  1843 		<pre>
  1844 			&lt;style>
  1845 				#grid {
  1846 					display: grid;
  1847 					grid-template-columns: 20px;
  1848 					grid-template-rows: 20px }
  1849 				#A { grid-column: 1;          grid-row: 1; }
  1850 				#B { grid-column: 5;          grid-row: 1 / span 2; }
  1851 				#C { grid-column: 1 / span 2; grid-row: 2; }
  1852 			&lt;/style>
  1854 			&lt;div id="grid">
  1855 				&lt;div id="A">A&lt;/div>
  1856 				&lt;div id="B">B&lt;/div>
  1857 				&lt;div id="C">C&lt;/div>
  1858 			&lt;/div>
  1859 		</pre>
  1860 	</div>
  1862 <!--
  1863    ███    ██     ██ ████████  ███████        ████████ ████████     ███     ██████  ██    ██  ██████
  1864   ██ ██   ██     ██    ██    ██     ██          ██    ██     ██   ██ ██   ██    ██ ██   ██  ██    ██
  1865  ██   ██  ██     ██    ██    ██     ██          ██    ██     ██  ██   ██  ██       ██  ██   ██
  1866 ██     ██ ██     ██    ██    ██     ██          ██    ████████  ██     ██ ██       █████     ██████
  1867 █████████ ██     ██    ██    ██     ██          ██    ██   ██   █████████ ██       ██  ██         ██
  1868 ██     ██ ██     ██    ██    ██     ██          ██    ██    ██  ██     ██ ██    ██ ██   ██  ██    ██
  1869 ██     ██  ███████     ██     ███████           ██    ██     ██ ██     ██  ██████  ██    ██  ██████
  1870 -->
  1872 <h3 id='auto-tracks'>
  1873 Sizing Auto-generated Rows and Columns: the 'grid-auto-rows' and 'grid-auto-columns' properties</h3>
  1875 	<pre class='propdef'>
  1876 	Name: grid-auto-columns, grid-auto-rows
  1877 	Value: <<track-size>>
  1878 	Initial: auto
  1879 	Applies to: <a>grid containers</a>
  1880 	Inherited: no
  1881 	Percentages: see <a href="#track-sizing">Track Sizing</a>
  1882 	Media: visual
  1883 	Computed value: see <a href="#track-sizing">Track Sizing</a>
  1884 	</pre>
  1886 	If a grid item is positioned into a row or column that is not explicitly sized
  1887 	by 'grid-template-rows' or 'grid-template-columns',
  1888 	<a>implicit grid tracks</a> are created to hold it.
  1889 	This can happen either by explicitly positioning into a row or column that is out of range,
  1890 	or by the <a>auto-placement algorithm</a> creating additional rows or columns.
  1891 	The 'grid-auto-columns' and 'grid-auto-rows' properties specify the size of such implicitly-created tracks.
  1893 	Issue: Provide example.
  1895 <!--
  1896  ██████   ████████  ████ ████████             ███    ██     ██ ████████  ███████          ████████ ██        ███████  ██      ██
  1897 ██    ██  ██     ██  ██  ██     ██           ██ ██   ██     ██    ██    ██     ██         ██       ██       ██     ██ ██  ██  ██
  1898 ██        ██     ██  ██  ██     ██          ██   ██  ██     ██    ██    ██     ██         ██       ██       ██     ██ ██  ██  ██
  1899 ██   ████ ████████   ██  ██     ██ ███████ ██     ██ ██     ██    ██    ██     ██ ███████ ██████   ██       ██     ██ ██  ██  ██
  1900 ██    ██  ██   ██    ██  ██     ██         █████████ ██     ██    ██    ██     ██         ██       ██       ██     ██ ██  ██  ██
  1901 ██    ██  ██    ██   ██  ██     ██         ██     ██ ██     ██    ██    ██     ██         ██       ██       ██     ██ ██  ██  ██
  1902  ██████   ██     ██ ████ ████████          ██     ██  ███████     ██     ███████          ██       ████████  ███████   ███  ███
  1903 -->
  1905 <h3 id="grid-auto-flow-property">
  1906 <dfn lt="auto-placement|automatic placement">Automatic Placement</dfn>: the 'grid-auto-flow' property</h3>
  1908 	<pre class='propdef'>
  1909 	Name: grid-auto-flow
  1910 	Value: [ row | column ] || dense
  1911 	Initial: row
  1912 	Applies to: <a>grid containers</a>
  1913 	Inherited: no
  1914 	Percentages: n/a
  1915 	Media: visual
  1916 	Computed value: specified value
  1917 	</pre>
  1919 	<a>Grid items</a> that aren't explicitly placed are automatically placed
  1920 	into an unoccupied space in the <a>grid container</a>
  1921 	by the <a>auto-placement algorithm</a>.
  1922 	'grid-auto-flow' controls how the <a>auto-placement algorithm</a> works,
  1923 	specifying exactly how auto-placed items get flowed into the grid.
  1924 	See [[#auto-placement-algo]] for details on precisely how the auto-placement algorithm works.
  1926 	<dl dfn-for="grid-auto-flow" dfn-type=value>
  1927 		<dt><dfn>row</dfn>
  1928 		<dd>
  1929 			The <a>auto-placement algorithm</a> places items
  1930 			by filling each row in turn,
  1931 			adding new rows as necessary.
  1932 			If neither ''row'' nor ''column'' is provided,
  1933 			''row'' is assumed.
  1935 		<dt><dfn>column</dfn>
  1936 		<dd>
  1937 			The <a>auto-placement algorithm</a> places items
  1938 			by filling each column in turn,
  1939 			adding new columns as necessary.
  1941 		<dt><dfn>dense</dfn>
  1942 		<dd>
  1943 			If specified, the <a>auto-placement algorithm</a> uses a “dense” packing algorithm,
  1944 			which attempts to fill in holes earlier in the grid if smaller items come up later.
  1945 			This may cause items to appear out-of-order,
  1946 			when doing so would fill in holes left by larger items.
  1948 			If omitted, a “sparse” algorithm is used,
  1949 			where the placement algorithm only ever moves “forward” in the grid when placing items,
  1950 			never backtracking to fill holes.
  1951 			This ensures that all of the auto-placed items appear “in order”,
  1952 			even if this leaves holes that could have been filled by later items.
  1953 	</dl>
  1955 	Note: A future level of this module is expected to add a value that flows auto-positioned items together into a single “default” cell.
  1957 	Auto-placement takes <a>grid items</a> in <a>order-modified document order</a>.
  1959 	<div class='example'>
  1960 		In the following example, there are three columns, each auto-sized to their contents.
  1961 		No rows are explicitly defined.
  1962 		The 'grid-auto-flow' property is ''grid-auto-flow/row''
  1963 		which instructs the grid to search across its three columns starting with the first row,
  1964 		then the next,
  1965 		adding rows as needed until sufficient space is located to accommodate the position of any auto-placed <a>grid item</a>.
  1967 		<div class="figure">
  1968 				<img alt="Image: A form arranged using automatic placement." src="images/auto-placed-form.png" />
  1970 			<p class="caption">A form arranged using automatic placement.
  1971 		</div>
  1973 		<pre>
  1974 			&lt;style type="text/css">
  1975 			form {
  1976 				display: grid;
  1977 				/* Define three columns, all content-sized,
  1978 				   and name the corresponding lines. */
  1979 				grid-template-columns: [labels] auto [controls] auto [oversized] auto;
  1980 				grid-auto-flow: row dense;
  1982 			form > label {
  1983 				/* Place all labels in the "labels" column and
  1984 				   automatically find the next available row. */
  1985 				grid-column: labels;
  1986 				grid-row: auto;
  1988 			form > input, form > select {
  1989 				/* Place all controls in the "controls" column and
  1990 				   automatically find the next available row. */
  1991 				grid-column: controls;
  1992 				grid-row: auto;
  1995 			#department-block {
  1996 				/* Auto place this item in the "oversized" column
  1997 				   in the first row where an area that spans three rows
  1998 				   won't overlap other explicitly placed items or areas
  1999 				   or any items automatically placed prior to this area. */
  2000 				grid-column: oversized;
  2001 				grid-row: span 3;
  2004 			/* Place all the buttons of the form
  2005 			   in the explicitly defined grid area. */
  2006 			#buttons {
  2007 				grid-row: auto;
  2009 				/* Ensure the button area spans the entire grid element
  2010 				   in the row axis. */
  2011 				grid-column: 1 / -1;
  2012 				text-align: end;
  2014 			&lt;/style>
  2015 			&lt;form>
  2016 				&lt;label for="firstname">First name:&lt;/label>
  2017 				&lt;input type="text" id="firstname" name="firstname" />
  2018 				&lt;label for="lastname">Last name:&lt;/label>
  2019 				&lt;input type="text" id="lastname" name="lastname" />
  2020 				&lt;label for="address">Address:&lt;/label>
  2021 				&lt;input type="text" id="address" name="address" />
  2022 				&lt;label for="address2">Address 2:&lt;/label>
  2023 				&lt;input type="text" id="address2" name="address2" />
  2024 				&lt;label for="city">City:&lt;/label>
  2025 				&lt;input type="text" id="city" name="city" />
  2026 				&lt;label for="state">State:&lt;/label>
  2027 				&lt;select type="text" id="state" name="state">
  2028 					&lt;option value="WA">Washington&lt;/option>
  2029 				&lt;/select>
  2030 				&lt;label for="zip">Zip:&lt;/label>
  2031 				&lt;input type="text" id="zip" name="zip" />
  2033 				&lt;div id="department-block">
  2034 					&lt;label for="department">Department:&lt;/label>
  2035 					&lt;select id="department" name="department" multiple>
  2036 						&lt;option value="finance">Finance&lt;/option>
  2037 						&lt;option value="humanresources">Human Resources&lt;/option>
  2038 						&lt;option value="marketing">Marketing&lt;/option>
  2039 					&lt;/select>
  2040 				&lt;/div>
  2042 				&lt;div id="buttons">
  2043 					&lt;button id="cancel">Cancel&lt;/button>
  2044 					&lt;button id="back">Back&lt;/button>
  2045 					&lt;button id="next">Next&lt;/button>
  2046 				&lt;/div>
  2047 			&lt;/form>
  2048 		</pre>
  2049 	</div>
  2051 <!--
  2052  ██████   ████████  ████ ████████
  2053 ██    ██  ██     ██  ██  ██     ██
  2054 ██        ██     ██  ██  ██     ██
  2055 ██   ████ ████████   ██  ██     ██
  2056 ██    ██  ██   ██    ██  ██     ██
  2057 ██    ██  ██    ██   ██  ██     ██
  2058  ██████   ██     ██ ████ ████████
  2059 -->
  2061 <h2 id='grid-shorthand'>
  2062 Grid Definition Shorthand: the 'grid' property</h2>
  2064 	<pre class='propdef'>
  2065 	Name: grid
  2066 	Value: <<'grid-template'>> | [ <<'grid-auto-flow'>> [ <<'grid-auto-rows'>> [ / <<'grid-auto-columns'>> ]? ]? ]
  2067 	Initial: see individual properties
  2068 	Applies to: <a>grid containers</a>
  2069 	Inherited: see individual properties
  2070 	Percentages: see individual properties
  2071 	Media: visual
  2072 	Computed value: see individual properties
  2073 	</pre>
  2075 	The 'grid' property is a <a>shorthand</a> that sets
  2076 	all of the explicit grid properties
  2077 	('grid-template-rows', 'grid-template-columns', and 'grid-template-areas'),
  2078 	all the implicit grid properties
  2079 	('grid-auto-rows', 'grid-auto-columns', and 'grid-auto-flow'),
  2080 	and the gutter properties
  2081 	('grid-column-gap' and 'grid-row-gap')
  2082 	in a single declaration.
  2083 	If <<'grid-auto-columns'>> value is omitted,
  2084 	it is set to the value specified for <<'grid-auto-rows'>>.
  2085 	Other omitted values are set to their initial values.
  2087 	Note: Note that you can only specify the explicit <em>or</em> the implicit grid properties in a single 'grid' declaration.
  2088 	The sub-properties you don't specify are set to their initial value,
  2089 	as normal for <a>shorthands</a>.
  2090 	Also, the gutter properties are <a lt="reset-only sub-property">reset</a> by this shorthand,
  2091 	even though they can't be set by it.
  2093 	<div class='example'>
  2094 		In addition to accepting the 'grid-template' shorthand syntax for setting up the <a>explicit grid</a>,
  2095 		the 'grid' shorthand can also easily set up parameters for an auto-formatted grid.
  2096 		For example, ''grid: row 1fr;'' is equivalent to
  2098 		<pre>
  2099 			grid-template: none;
  2100 			grid-auto-flow: row;
  2101 			grid-auto-rows: 1fr;
  2102 			grid-auto-columns: 1fr;
  2103 		</pre>
  2105 		Similarly, ''grid: column 1fr / auto'' is equivalent to
  2106 		<pre>
  2107 			grid-template: none;
  2108 			grid-auto-flow: column;
  2109 			grid-auto-rows: 1fr;
  2110 			grid-auto-columns: auto;
  2111 		</pre>
  2112 	</div>
  2114 <!--
  2115  ██████  ██          ███    ██     ██ ████████  ████ ██    ██  ██████
  2116 ██    ██ ██         ██ ██   ███   ███ ██     ██  ██  ███   ██ ██    ██
  2117 ██       ██        ██   ██  ████ ████ ██     ██  ██  ████  ██ ██
  2118 ██       ██       ██     ██ ██ ███ ██ ████████   ██  ██ ██ ██ ██   ████
  2119 ██       ██       █████████ ██     ██ ██         ██  ██  ████ ██    ██
  2120 ██    ██ ██       ██     ██ ██     ██ ██         ██  ██   ███ ██    ██
  2121  ██████  ████████ ██     ██ ██     ██ ██        ████ ██    ██  ██████
  2122 -->
  2124 <h2 id="overlarge-grids">
  2125 Clamping Overlarge Grids</h2>
  2127 	Since memory is not infinite,
  2128 	UAs may clamp the possible size of the <a>grid</a>
  2129 	to within a UA-defined limit,
  2130 	dropping all lines outside that limit.
  2131 	If a grid item is placed outside this limit,
  2132 	its grid area must be <a>clamped</a> to within this limited grid.
  2134 	To <dfn local-lt=clamp>clamp a grid area</dfn>:
  2135 	* If the <a>grid area</a> would span outside the limited grid,
  2136 		its span is clamped to the last line of the limited <a>grid</a>.
  2137 	* If the <a>grid area</a> would be placed completely outside the limited grid
  2138 		its span must be truncated to 1
  2139 		and the area repositioned into the last <a>grid track</a> on that side of the grid.
  2141 	<div class='example'>
  2142 		For example, if a UA only supported grids with at most 1000 tracks in each dimension,
  2143 		the following placement properties:
  2145 		<pre class="lang-css">
  2146 		.grid-item {
  2147 			grid-row: 500 / 1500;
  2148 			grid-column: 2000 / 3000;
  2150 		</pre>
  2152 		Would end up being equivalent to:
  2154 		<pre class="lang-css">
  2155 		.grid-item {
  2156 			grid-row: 500 / 1001;
  2157 			grid-column: 1000 / 1001;
  2159 		</pre>
  2160 	</div>
  2162 <!--
  2163 ████████  ██          ███     ██████  ████ ██    ██  ██████
  2164 ██     ██ ██         ██ ██   ██    ██  ██  ███   ██ ██    ██
  2165 ██     ██ ██        ██   ██  ██        ██  ████  ██ ██
  2166 ████████  ██       ██     ██ ██        ██  ██ ██ ██ ██   ████
  2167 ██        ██       █████████ ██        ██  ██  ████ ██    ██
  2168 ██        ██       ██     ██ ██    ██  ██  ██   ███ ██    ██
  2169 ██        ████████ ██     ██  ██████  ████ ██    ██  ██████
  2170 -->
  2172 <h2 id="placement">
  2173 Placing Grid Items</h2>
  2175 	Every <a>grid item</a> has a <a>grid area</a>,
  2176 	a rectangular set of <a>grid cells</a> that the <a>grid item</a> occupies.
  2177 	This <a>grid area</a> defines the <a>containing block</a> for the <a>grid item</a>
  2178 	within which the alignment properties ('justify-self' and 'align-self') determine their actual position.
  2179 	The cells that a <a>grid item</a> occupies also influence the sizing of the grid's rows and columns,
  2180 	defined in [[#layout-algorithm]].
  2182 	The location of a <a>grid item’s</a> <a>grid area</a> within the <a>grid</a>
  2183 	is defined by its <dfn export lt="grid placement" local-lt="placement">placement</dfn>,
  2184 	which consists of a <a>grid position</a> and a <a>grid span</a>:
  2186 	<dl export>
  2187 		<dt><dfn export local-lt="position|row position|column position">grid position</dfn>
  2188 		<dd>
  2189 			The <a>grid item</a>’s location in the <a>grid</a>.
  2190 			A <a>grid position</a> can be either
  2191 			<dfn export lt="definite grid position|definite row position|definite column position|definite position">definite</dfn> (explicitly specified)
  2192 			or <dfn export lt="automatic grid position|automatic row position|automatic column position|automatic position">automatic</dfn> (determined by <a>auto-placement</a>).
  2194 		<dt><dfn export local-lt="span|row span|column span">grid span</dfn>
  2195 		<dd>
  2196 			How many <a>grid tracks</a> the <a>grid item</a> occupies.
  2197 			A <a>subgrid</a>’s <a>grid span</a> can be <dfn lt="automatic grid span|automatic row span|automatic column span|automatic span">automatic</dfn>
  2198 			(determined by its <a>implicit grid</a>) if not specified or implied;
  2199 			a <a>grid item</a>’s <a>grid span</a> is otherwise always <dfn export lt="definite grid span|definite row span|definite column span|definite span">definite</dfn> (defaulting to 1).
  2200 	</dl>
  2202 	The <dfn export lt="grid-placement property">grid-placement properties</dfn>--
  2203 	the longhands 'grid-row-start', 'grid-row-end', 'grid-column-start', 'grid-column-end', and their shorthands 'grid-row', 'grid-column', and 'grid-area'--
  2204 	allow the author to specify a <a>grid item</a>’s <a>placement</a>
  2205 	by providing any (or none) of the following six pieces of information:
  2207 	<table class=data style="width: auto">
  2208 		<thead>
  2209 			<tr>
  2210 				<td>
  2211 				<th>Row
  2212 				<th>Column
  2213 		<tbody>
  2214 			<tr>
  2215 				<th>|Start|
  2216 				<td>row-start line
  2217 				<td>column-start line
  2218 			<tr>
  2219 				<th>|End|
  2220 				<td>row-end line
  2221 				<td>column-end line
  2222 			<tr>
  2223 				<th>|Span|
  2224 				<td>row span
  2225 				<td>column span
  2226 	</table>
  2228 	A definite value for any two of <var>Start</var>, <var>End</var>, and <var>Span</var> in a given dimension implies a definite value for the third.
  2230 	The following table summarizes the conditions under which a grid position or span is <i lt>definite</i> or <i lt>automatic</i>:
  2232 	<table class='data'>
  2233 		<thead>
  2234 			<tr>
  2235 				<td>
  2236 				<th>Position
  2237 				<th>Span
  2238 		<tbody>
  2239 			<tr>
  2240 				<th>Definite
  2241 				<td>At least one specified line
  2242 				<td>Explicit, implicit, or defaulted span. <br> <span class="note">Note: Non-<a>subgrids</a> default to 1.</span>
  2243 			<tr>
  2244 				<th>Automatic
  2245 				<td>No lines explicitly specified
  2246 				<td><a>Subgrid</a> without an explicit or implied span
  2247 	</table>
  2251 <h3 id='common-uses'>
  2252 Common Patterns for Grid Placement</h3>
  2254 	<em>This section is informative.</em>
  2256 	The <a>grid-placement property</a> longhands are organized into three shorthands:
  2258 	<table class=data id="grid-property-breakdown">
  2259 		<tr>
  2260 			<td colspan=4>'grid-area'
  2261 		<tr>
  2262 			<td colspan=2>'grid-column'
  2263 			<td colspan=2>'grid-row'
  2264 		<tr>
  2265 			<td>'grid-column-start'
  2266 			<td>'grid-column-end'
  2267 			<td>'grid-row-start'
  2268 			<td>'grid-row-end'
  2269 	</table>
  2271 <h4 id='common-uses-named-areas'>
  2272 Named Areas</h4>
  2274 	An item can be placed into a <a>named grid area</a>
  2275 	(such as those produced by the template in 'grid-template-areas')
  2276 	by specifying the area’s name in 'grid-area':
  2278 	<div class='example'>
  2279 		<pre>
  2280 			article {
  2281 				grid-area: main;
  2282 				/* Places item into the named area "main". */
  2284 		</pre>
  2285 	</div>
  2287 	An item can also be <em>partially</em> aligned with a <a>named grid area</a>,
  2288 	with other edges aligned to some other line:
  2290 	<div class='example'>
  2291 		<pre>
  2292 			.one {
  2293 				grid-row-start: main;
  2294 				/* Align the row-start edge to the start edge of the "main" named area. */
  2296 		</pre>
  2297 	</div>
  2299 <h4 id='common-uses-numeric'>
  2300 Numeric Indexes and Spans</h4>
  2302 	Grid items can be positioned and sized by number,
  2303 	which is particularly helpful for script-driven layouts:
  2305 	<div class='example'>
  2306 		<pre>
  2307 			.two {
  2308 				grid-row: 2;    /* Place item in the second row. */
  2309 				grid-column: 3; /* Place item in the third column. */
  2310 				/* Equivalent to grid-area: 2 / 3;
  2312 		</pre>
  2313 	</div>
  2315 	By default, a grid item has a span of 1.
  2316 	Different spans can be given explicitly:
  2318 	<div class='example'>
  2319 		<pre>
  2320 			.three {
  2321 				grid-row: 2 / span 5;
  2322 				/* Starts in the 2nd row,
  2323 				   spans 5 rows down (ending in the 7th row). */
  2326 			.four {
  2327 				grid-row: span 5 / 7;
  2328 				/* <em>Ends</em> in the 7th row,
  2329 				   spans 5 rows up (starting in the 2nd row). */
  2331 		</pre>
  2332 	</div>
  2334 	Note: Note that grid indexes are <a>writing mode</a> relative.
  2335 	For example, in a right-to-left language like Arabic,
  2336 	the first column is the rightmost column.
  2338 <h4 id='common-uses-named-lines'>
  2339 Named Lines and Spans</h4>
  2341 	Instead of counting lines by number,
  2342 	<a>named lines</a> can be referenced by their name:
  2344 	<div class='example'>
  2345 		<pre>
  2346 			.five {
  2347 				grid-column: first / middle;
  2348 				/* Span from line "first" to line "middle". */
  2350 		</pre>
  2351 	</div>
  2353 	Note: Note that if a <a>named grid area</a> and a <a>named line</a> have the same name,
  2354 	the placement algorithm will prefer to use <a>named grid area</a>’s edge instead.
  2356 	If there are multiple lines of the same name,
  2357 	they effectively establish a named set of grid lines,
  2358 	which can be exclusively indexed by filtering the placement by name:
  2360 	<div class='example'>
  2361 		<pre>
  2362 			.six {
  2363 				grid-row: text 5 / text 7;
  2364 				/* Span between the 5th and 7th lines named "text". */
  2365 				grid-row: text 5 / span text 2;
  2366 				/* Same as above. */
  2368 		</pre>
  2369 	</div>
  2371 <h4 id='common-uses-auto-placement'>
  2372 Auto Placement</h4>
  2374 	A <a>grid item</a> can be automatically placed into the next available empty <a>grid cell</a>,
  2375 	growing the <a>grid</a> if there's no space left.
  2377 	<div class='example'>
  2378 		<pre>
  2379 			.eight {
  2380 				grid-area: auto; /* Initial value */
  2382 		</pre>
  2383 	</div>
  2385 	This can be used, for example, to list a number of sale items on a catalog site
  2386 	in a grid pattern.
  2388 	Auto-placement can be combined with an explicit span,
  2389 	if the item should take up more than one cell:
  2391 	<div class='example'>
  2392 		<pre>
  2393 			.nine {
  2394 				grid-area: span 2 / span 3;
  2395 				/* Auto-placed item, covering two rows and three columns. */
  2397 		</pre>
  2398 	</div>
  2400 	Whether the <a>auto-placement algorithm</a> searchs across and adds rows,
  2401 	or searches across and adds columns,
  2402 	is controlled by the 'grid-auto-flow' property.
  2404 	Note: By default, the <a>auto-placement algorithm</a> looks linearly through the grid without backtracking;
  2405 	if it has to skip some empty spaces to place a larger item,
  2406 	it will not return to fill those spaces.
  2407 	To change this behavior,
  2408 	specify the ''dense'' keyword in 'grid-auto-flow'.
  2410 <h4 id='common-uses-auto-sizing'>
  2411 Auto Sizing Subgrids</h4>
  2413 	A subgrid without a <a>definite grid span</a> is sized to its <a>implicit grid</a>,
  2414 	i.e. all of its items within it are first placed into its own grid,
  2415 	and its span is the resulting size of its grid.
  2417 	<div class='example'>
  2418 		For example, a subgrid spanning two columns can be given an auto-spanning <a>block size</a>:
  2419 		<pre>
  2420 			.adverts {
  2421 				grid: subgrid;
  2422 				grid-column: span 2;
  2424 		</pre>
  2426 		If it contains 10 auto-placed items, it will span 5 rows in its parent grid.
  2427 	</div>
  2429 	Note: Since auto-spanning <a>subgrids</a> determine their span before being positioned,
  2430 	they can also be auto-positioned.
  2431 	The above example would auto-place the <code>.adverts</code> block,
  2432 	if no further rules specified its position.
  2434 <h3 id="placement-a11y">
  2435 Grid Item Placement vs. Source Order</h3>
  2437 	<blockquote>
  2438 		<p>“With great power comes great responsibility.”
  2439 	</blockquote>
  2441 	The abilities of the <a>grid-placement properties</a>
  2442 	allow content to be freely arranged and reordered within the <a>grid</a>,
  2443 	such that the visual presentation can be largely disjoint
  2444 	from the underlying document source order.
  2445 	These abilities allow the author great freedom
  2446 	in tailoring the rendering to different devices
  2447 	and modes of presentation
  2448 	e.g. using <a>media queries</a>.
  2449 	However <strong>they are not a substitute for correct source ordering</strong>.
  2451 	Correct source order is important for speech,
  2452 	for sequential navigation (such as keyboard navigation),
  2453 	and non-CSS UAs such as search engines, tactile browsers, etc.
  2454 	Grid placement <em>only</em> affects the visual presentation!
  2455 	This allows authors to optimize the document source for
  2456 	non-CSS/non-visual interaction modes,
  2457 	and use grid placement techniques to further manipulate the visual presentation
  2458 	so as to leave that source order intact.
  2461 <!--
  2462  ██████   ████████  ████ ████████          ████████   ███████  ██      ██          ██████  ████████    ███    ████████  ████████
  2463 ██    ██  ██     ██  ██  ██     ██         ██     ██ ██     ██ ██  ██  ██         ██    ██    ██      ██ ██   ██     ██    ██
  2464 ██        ██     ██  ██  ██     ██         ██     ██ ██     ██ ██  ██  ██         ██          ██     ██   ██  ██     ██    ██
  2465 ██   ████ ████████   ██  ██     ██ ███████ ████████  ██     ██ ██  ██  ██ ███████  ██████     ██    ██     ██ ████████     ██
  2466 ██    ██  ██   ██    ██  ██     ██         ██   ██   ██     ██ ██  ██  ██               ██    ██    █████████ ██   ██      ██
  2467 ██    ██  ██    ██   ██  ██     ██         ██    ██  ██     ██ ██  ██  ██         ██    ██    ██    ██     ██ ██    ██     ██
  2468  ██████   ██     ██ ████ ████████          ██     ██  ███████   ███  ███           ██████     ██    ██     ██ ██     ██    ██
  2469 -->
  2471 <h3 id='line-placement'>
  2472 Line-based Placement: the 'grid-row-start', 'grid-column-start', 'grid-row-end', and 'grid-column-end' properties</h3>
  2474 	<pre class='propdef'>
  2475 	Name: grid-row-start, grid-column-start, grid-row-end, grid-column-end
  2476 	Value: <<grid-line>>
  2477 	Initial: auto
  2478 	Applies to: <a>grid items</a> and absolutely-positioned boxes whose containing block is a <a>grid container</a>
  2479 	Inherited: no
  2480 	Percentages: n/a
  2481 	Media: visual
  2482 	Computed value: specified value
  2483 	</pre>
  2485 	<pre>
  2486 		<dfn for="grid-row-start, grid-column-start, grid-row-end, grid-column-end"><<grid-line>></dfn> =
  2487 		  auto |
  2488 		  <<custom-ident>> |
  2489 		  [ <<integer>> && <<custom-ident>>? ] |
  2490 		  [ span &amp;&amp; [ <<integer>> || <<custom-ident>> ] ]
  2491 	</pre>
  2493 	The 'grid-row-start', 'grid-column-start', 'grid-row-end', and 'grid-column-end' properties
  2494 	determine a <a>grid item</a>’s size and location within the <a>grid</a>
  2495 	by contributing a line, a span, or nothing (automatic)
  2496 	to its <a>grid placement</a>,
  2497 	thereby specifying the <a>inline-start</a>, <a>block-start</a>, <a>inline-end</a>, and <a>block-end</a> edges of its <a>grid area</a>.
  2499 	Values have the following meanings:
  2501 	<dl dfn-for="<grid-line>" dfn-type=value>
  2502 		<dt><dfn id='grid-placement-slot'><<custom-ident>></dfn>
  2503 		<dd>
  2504 			First attempt to match the <a>grid area</a>’s edge to a <a>named grid area</a>:
  2505 			if there is a <a>named line</a> with the name ''<<custom-ident>>-start'' (for 'grid-*-start') / ''<<custom-ident>>-end'' (for 'grid-*-end'),
  2506 			contributes the first such line to the <a>grid item</a>’s <a>placement</a>.
  2508 			Note: <a>Named grid areas</a> automatically generate <a>implicit named lines</a> of this form,
  2509 			so specifying ''grid-row-start: foo'' will choose the start edge of that <a>named grid area</a>
  2510 			(unless another line named ''foo-start'' was explicitly specified before it).
  2512 			Otherwise,
  2513 			treat this as if the integer ''1'' had been specified along with the <<custom-ident>>.
  2515 		<dt><dfn id='grid-placement-int'><<integer>> && <<custom-ident>>?</dfn>
  2516 		<dd>
  2517 			Contributes the <var>N</var>th <a>grid line</a> to the <a>grid item</a>’s <a>placement</a>.
  2518 			If a negative integer is given,
  2519 			it instead counts in reverse,
  2520 			starting from the end edge of the <a>explicit grid</a>.
  2522 			If a name is given as a <<custom-ident>>,
  2523 			only lines with that name are counted.
  2524 			If not enough lines with that name exist,
  2525 			all <a>implicit grid lines</a>
  2526 			are assumed to have that name for the purpose of finding this position.
  2528 			An <<integer>> value of zero makes the declaration invalid.
  2530 		<dt><dfn id='grid-placement-span-int'>span && [ <<integer>> || <<custom-ident>> ]</dfn>
  2531 		<dd>
  2532 			Contributes a <a>grid span</a> to the <a>grid item</a>’s <a>placement</a>
  2533 			such that the corresponding edge of the <a>grid item</a>’s <a>grid area</a> is <var>N</var> lines from its opposite edge
  2534 			in the corresponding direction.
  2535 			For example, ''grid-column-end: span 2'' indicates the second grid line in the endward direction
  2536 			from the 'grid-column-start' line.
  2538 			If a name is given as a <<custom-ident>>,
  2539 			only lines with that name are counted.
  2540 			If not enough lines with that name exist,
  2541 			all <a>implicit grid lines</a>
  2542 			on the side of the <a>explicit grid</a> corresponding to the search direction
  2543 			are assumed to have that name for the purpose of counting this span.
  2545 			<div class="example">
  2546 				For example, given the following declarations:
  2548 				<pre class="lang-css">
  2549 				.grid { grid-template-columns: 100px; }
  2550 				.griditem { grid-column: span foo / 4; }
  2551 				</pre>
  2553 				The <a>grid container</a> has an <a>explicit grid</a> with two grid lines,
  2554 				numbered 1 and 2.
  2555 				The <a>grid item's</a> column-end edge is specified to be at line 4,
  2556 				so two lines are generated in the endward side of the <a>implicit grid</a>.
  2558 				Its column-start edge must be the first "foo" line it can find startward of that.
  2559 				There is no "foo" line in the grid, though,
  2560 				so the only possibility is a line in the <a>implicit grid</a>.
  2561 				Line 3 is not a candidate, because it's on the endward side of the <a>explicit grid</a>,
  2562 				while the 'grid-column-start' span forces it to search startward.
  2563 				So, the only option is for the <a>implicit grid</a> to generate a line on the startward side of the <a>explicit grid</a>.
  2565 				<figure>
  2566 					<img src="images/implicit-lines-search.svg" width=600>
  2567 					<figcaption>An illustration of the result.
  2568 				</figure>
  2569 			</div>
  2571 			If the <<integer>> is omitted, it defaults to ''1''.
  2572 			Negative integers or zero are invalid.
  2574 		<dt><dfn id='grid-placement-auto'>auto</dfn>
  2575 		<dd>
  2576 			The property contributes nothing to the <a>grid item</a>’s <a>placement</a>,
  2577 			indicating <a>auto-placement</a>, an <a>automatic span</a>, or a default span of one.
  2578 			(See [[#placement]], above.)
  2579 	</dl>
  2581 	<div class='example'>
  2582 			Given a single-row, 8-column grid and the following 9 named lines:
  2584 		<pre>
  2585 			1  2  3  4  5  6  7  8  9
  2586 			+--+--+--+--+--+--+--+--+
  2587 			|  |  |  |  |  |  |  |  |
  2588 			A  B  C  A  B  C  A  B  C
  2589 			|  |  |  |  |  |  |  |  |
  2590 			+--+--+--+--+--+--+--+--+
  2591 		</pre>
  2593 			The following declarations place the grid item between the lines indicated by index:
  2595 		<pre>
  2596 			grid-column-start: 4; grid-column-end: auto;
  2597 			/* Line 4 to line 5 */
  2599 			grid-column-start: auto; grid-column-end: 6;
  2600 			/* Line 5 to line 6 */
  2602 			grid-column-start: C; grid-column-end: C -1;
  2603 			/* Line 3 to line 9 */
  2605 			grid-column-start: C; grid-column-end: span C;
  2606 			/* Line 3 to line 6 */
  2608 			grid-column-start: span C; grid-column-end: C -1;
  2609 			/* Line 6 to line 9 */
  2611 			grid-column-start: span C; grid-column-end: span C;
  2612 			/* Error: The end span is ignored, and an auto-placed
  2613 			   item can't span to a named line.
  2614 			   Equivalent to ''grid-column: span 1;''. */
  2616 			grid-column-start: 5; grid-column-end: C -1;
  2617 			/* Line 5 to line 9 */
  2619 			grid-column-start: 5; grid-column-end: span C;
  2620 			/* Line 5 to line 6 */
  2622 			grid-column-start: 8; grid-column-end: 8;
  2623 			/* Error: line 8 to line 9 */
  2625 			grid-column-start: B 2; grid-column-end: span 1;
  2626 			/* Line 5 to line 6 */
  2627 		</pre>
  2628 	</div>
  2630 <h4 id='grid-placement-errors'>
  2631 Grid Placement Conflict Handling</h4>
  2633 	If the <a>placement</a> for a <a>grid item</a> contains two lines,
  2634 	and the <a>start</a> line is further end-ward than the <a>end</a> line,
  2635 	swap the two lines.
  2636 	If the <a>start</a> line is <em>equal</em> to the <a>end</a> line,
  2637 	remove the <a>end</a> line.
  2639 	If the <a>placement</a> contains two spans,
  2640 	remove the one contributed by the <a>end</a> <a>grid-placement property</a>.
  2642 	If the <a>placement</a> contains only a span for a named line,
  2643 	replace it with a span of 1.
  2645 <!--
  2646  ██████   ████████  ████ ████████           ██████   ███████  ██       ██     ██ ██     ██ ██    ██
  2647 ██    ██  ██     ██  ██  ██     ██         ██    ██ ██     ██ ██       ██     ██ ███   ███ ███   ██
  2648 ██        ██     ██  ██  ██     ██         ██       ██     ██ ██       ██     ██ ████ ████ ████  ██
  2649 ██   ████ ████████   ██  ██     ██ ███████ ██       ██     ██ ██       ██     ██ ██ ███ ██ ██ ██ ██
  2650 ██    ██  ██   ██    ██  ██     ██         ██       ██     ██ ██       ██     ██ ██     ██ ██  ████
  2651 ██    ██  ██    ██   ██  ██     ██         ██    ██ ██     ██ ██       ██     ██ ██     ██ ██   ███
  2652  ██████   ██     ██ ████ ████████           ██████   ███████  ████████  ███████  ██     ██ ██    ██
  2653 -->
  2655 <h3 id='placement-shorthands'>
  2656 Placement Shorthands: the 'grid-column', 'grid-row', and 'grid-area' properties</h3>
  2658 	<pre class='propdef'>
  2659 	Name: grid-row, grid-column
  2660 	Value: <<grid-line>> [ / <<grid-line>> ]?
  2661 	Initial: see individual properties
  2662 	Applies to: <a>grid items</a> and absolutely-positioned boxes whose containing block is a <a>grid container</a>
  2663 	Inherited: see individual properties
  2664 	Percentages: see individual properties
  2665 	Media: visual
  2666 	Computed value: see individual properties
  2667 	</pre>
  2669 	The 'grid-row' and 'grid-column' properties are shorthands for 'grid-row-start'/'grid-row-end' and 'grid-column-start'/'grid-column-end', respectively.
  2671 	If two <<grid-line>> values are specified,
  2672 	the 'grid-row-start'/'grid-column-start' longhand is set to the value before the slash,
  2673 	and the 'grid-row-end'/'grid-column-end' longhand is set to the value after the slash.
  2675 	When the second value is omitted,
  2676 	if the first value is a <<custom-ident>>,
  2677 	the 'grid-row-end'/'grid-column-end' longhand is also set to that <<custom-ident>>;
  2678 	otherwise, it is set to <a value for="<grid-line>">auto</a>.
  2680 	<pre class='propdef'>
  2681 	Name: grid-area
  2682 	Value: <<grid-line>> [ / <<grid-line>> ]{0,3}
  2683 	Initial: see individual properties
  2684 	Applies to: <a>grid items</a> and absolutely-positioned boxes whose containing block is a <a>grid container</a>
  2685 	Inherited: see individual properties
  2686 	Percentages: see individual properties
  2687 	Media: visual
  2688 	Computed value: see individual properties
  2689 	</pre>
  2691 	If four <<grid-line>> values are specified,
  2692 	'grid-row-start' is set to the first value,
  2693 	'grid-column-start' is set to the second value,
  2694 	'grid-row-end' is set to the third value,
  2695 	and 'grid-column-end' is set to the fourth value.
  2697 	When 'grid-column-end' is omitted,
  2698 	if 'grid-column-start' is a <<custom-ident>>,
  2699 	'grid-column-end' is set to that <<custom-ident>>;
  2700 	otherwise, it is set to <a value for="<grid-line>">auto</a>.
  2702 	When 'grid-row-end' is omitted,
  2703 	if 'grid-row-start' is a <<custom-ident>>,
  2704 	'grid-row-end' is set to that <<custom-ident>>;
  2705 	otherwise, it is set to <a value for="<grid-line>">auto</a>.
  2707 	When 'grid-column-start' is omitted,
  2708 	if 'grid-row-start' is a <<custom-ident>>,
  2709 	all four longhands are set to that value.
  2710 	Otherwise, it is set to <a value for="<grid-line>">auto</a>.
  2712 	Note: The resolution order for this shorthand is row-start/column-start/row-end/column-end,
  2713 	which goes CCW for LTR pages,
  2714 	the opposite direction of the related 4-edge properties using physical directions, like 'margin'.
  2716 <!--
  2717    ███    ██     ██ ████████  ███████          ████████  ██          ███     ██████  ████████ ██     ██ ████████ ██    ██ ████████
  2718   ██ ██   ██     ██    ██    ██     ██         ██     ██ ██         ██ ██   ██    ██ ██       ███   ███ ██       ███   ██    ██
  2719  ██   ██  ██     ██    ██    ██     ██         ██     ██ ██        ██   ██  ██       ██       ████ ████ ██       ████  ██    ██
  2720 ██     ██ ██     ██    ██    ██     ██ ███████ ████████  ██       ██     ██ ██       ██████   ██ ███ ██ ██████   ██ ██ ██    ██
  2721 █████████ ██     ██    ██    ██     ██         ██        ██       █████████ ██       ██       ██     ██ ██       ██  ████    ██
  2722 ██     ██ ██     ██    ██    ██     ██         ██        ██       ██     ██ ██    ██ ██       ██     ██ ██       ██   ███    ██
  2723 ██     ██  ███████     ██     ███████          ██        ████████ ██     ██  ██████  ████████ ██     ██ ████████ ██    ██    ██
  2724 -->
  2726 <h3 id='auto-placement-algo'>
  2727 Grid Item Placement Algorithm</h3>
  2729 	The following <dfn export local-lt="auto-placement algorithm">grid item placement algorithm</dfn>
  2730 	resolves <a>automatic positions</a> of <a>grid items</a> into <a>definite positions</a>,
  2731 	ensuring that every <a>grid item</a> has a well-defined <a>grid area</a> to lay out into.
  2732 	(<a>Grid spans</a> need no special resolution;
  2733 		if they're not explicitly specified,
  2734 		they default to either 1 or,
  2735 		for <a>subgrids</a>,
  2736 		the size of their <a>explicit grid</a>.)
  2738 	Note: This algorithm can result in the creation of new rows or columns in the <a>implicit grid</a>,
  2739 	if there is no room in the <a>explicit grid</a> to place an auto-positioned <a>grid item</a>.
  2741 	Every <a>grid cell</a>
  2742 	(in both the <a>explicit</a> and <a>implicit grids</a>)
  2743 	can be <dfn>occupied</dfn> or <dfn>unoccupied</dfn>.
  2744 	A cell is <a>occupied</a>
  2745 	if it's covered by a <a>named grid area</a>,
  2746 	or by the <a>grid area</a> of a <a>grid item</a> with a <a>definite grid position</a>;
  2747 	otherwise,
  2748 	the cell is <a>unoccupied</a>.
  2749 	A cell's <a>occupied</a>/<a>unoccupied</a> status can change during this algorithm.
  2751 	To aid in clarity,
  2752 	this algorithm is written with the assumption that 'grid-auto-flow'
  2753 	has ''grid-auto-flow/row'' specified.
  2754 	If it is instead set to ''grid-auto-flow/column'',
  2755 	swap all mentions of rows and columns, inline and block, etc. in this algorithm.
  2757 	1. <strong>Position anything that's not auto-positioned.</strong>
  2759 	2. <strong>Process the items locked to a given row.</strong>
  2761 		For each <a>grid item</a> with a <a>definite row position</a>
  2762 		(that is, the 'grid-row-start' and 'grid-row-end' properties define a <a>definite grid position</a>),
  2763 		in <a>order-modified document order</a>:
  2765 		: “sparse” packing (omitted ''dense'' keyword)
  2766 		::
  2767 			Set the column-start line of its <a>placement</a>
  2768 			to the earliest (smallest positive index) line index
  2769 			that ensures this item’s <a>grid area</a> will not overlap any <a>occupied</a> grid cells
  2770 			and that is past any <a>grid items</a> previously placed in this row by this step.
  2772 		: “dense” packing (''dense'' specified)
  2773 		::
  2774 			Set the column-start line of its <a>placement</a>
  2775 			to the earliest (smallest positive index) line index
  2776 			that ensures this item’s <a>grid area</a> will not overlap any <a>occupied</a> grid cells.
  2778 	3. <strong>Determine the columns in the implicit grid.</strong>
  2780 		Create columns in the <a>implicit grid</a>:
  2782 		1. Start with the columns from the <a>explicit grid</a>.
  2783 		2. Among all the items with a <a>definite column position</a>
  2784 			(explicitly positioned items, items positioned in the previous step, and items not yet positioned but with a definite column)
  2785 			add columns to the beginning and end of the <a>implicit grid</a>
  2786 			as necessary to accomodate those items.
  2787 		3. If the largest <a>column span</a> among all the items <em>without</em> a <a>definite column position</a>
  2788 			is larger than the width of the <a>implicit grid</a>,
  2789 			add columns to the end of the <a>implicit grid</a> to accomodate that <a>column span</a>.
  2791 		<div class='example'>
  2792 			For example, in the following style fragment:
  2794 			<pre>
  2795 				#grid {
  2796 					display: grid;
  2797 					grid-template-columns: repeat(5, 100px);
  2798 					grid-auto-flow: row;
  2800 				#grid-item {
  2801 					grid-column: 4 / span 3;
  2803 			</pre>
  2805 			The number of columns needed is 6.
  2806 			The <a>explicit grid</a> provides its 5 columns
  2807 			(from 'grid-template-columns')
  2808 			with lines number 1 through 6,
  2809 			but <code>#grid-item</code>’s column position means it ends on line 7,
  2810 			which requires an additional column added to the end of the <a>implicit grid</a>.
  2811 		</div>
  2813 	4. <strong>Position the remaining grid items.</strong>
  2815 		The <dfn export local-lt="cursor">auto-placement cursor</dfn> defines the current “insertion point” in the grid,
  2816 		specified as a pair of row and column <a>grid lines</a>.
  2817 		Initially the <a>auto-placement cursor</a> is set to the start-most row and column lines in the <a>implicit grid</a>.
  2819 		The 'grid-auto-flow' value in use determines how to position the items:
  2821 		: “sparse” packing (omitted ''dense'' keyword)
  2822 		:: For each <a>grid item</a> that hasn't been positioned by the previous steps,
  2823 			in <a>order-modified document order</a>:
  2825 			: If the item has a <a>definite column position</a>:
  2826 			::
  2827 				1. Set the column position of the <a>cursor</a> to the <a>grid item’s</a> column-start line.
  2828 					If this is less than the previous column position of the <a>cursor</a>,
  2829 					increment the row position by 1.
  2830 				2. Increment the <a>cursor</a>’s row position until a value is found
  2831 					where the <a>grid item</a> does not overlap any <a>occupied</a> grid cells
  2832 					(creating new rows in the <a>implicit grid</a> as necessary).
  2833 				3. Set the item's row-start line to the <a>cursor's</a> row position.
  2834 					(Implicitly setting the item's row-end line according to its span, as well.)
  2836 			: If the item has an <a>automatic grid position</a> in both axes:
  2837 			::
  2838 				1. Increment the column position of the <a>auto-placement cursor</a>
  2839 					until either this item’s <a>grid area</a> does not overlap any <a>occupied</a> grid cells,
  2840 					or the <a>cursor's</a> column position,
  2841 					plus the item's column span,
  2842 					overflow the number of columns in the implicit grid,
  2843 					as determined earlier in this algorithm.
  2844 				2. If a non-overlapping position was found in the previous step,
  2845 					set the item's row-start and column-start lines to the <a>cursor's</a> position.
  2846 					Otherwise,
  2847 					increment the <a>auto-placement cursor</a>’s row position
  2848 					(creating new rows in the <a>implicit grid</a> as necessary),
  2849 					set its column position to the start-most column line in the <a>implicit grid</a>,
  2850 					and return to the previous step.
  2852 		: “dense” packing (''dense'' specified)
  2853 		:: For each <a>grid item</a> that hasn't been positioned by the previous steps,
  2854 			in <a>order-modified document order</a>:
  2856 			: If the item has a <a>definite column position</a>:
  2857 			::
  2858 				1. Set the row position of the cursor to the start-most row line in the <a>implicit grid</a>.
  2859 					Set the column position of the cursor to the <a>grid item’s</a> column-start line.
  2860 				2. Increment the <a>auto-placement cursor</a>’s row position until a value is found
  2861 					where the <a>grid item</a> does not overlap any <a>occupied</a> grid cells
  2862 					(creating new rows in the <a>implicit grid</a> as necessary).
  2863 				3. Set the item's row-start line index to the <a>cursor's</a> row position.
  2864 					(Implicitly setting the item's row-end line according to its span, as well.)
  2866 			: If the item has an <a>automatic grid position</a> in both axes:
  2867 			::
  2868 				1. Set the cursor's row and column positions to start-most row and column lines in the <a>implicit grid</a>.
  2869 				2. Increment the column position of the <a>auto-placement cursor</a>
  2870 					until either this item’s <a>grid area</a> does not overlap any <a>occupied</a> grid cells,
  2871 					or the <a>cursor's</a> column position,
  2872 					plus the item's column span,
  2873 					overflow the number of columns in the implicit grid,
  2874 					as determined earlier in this algorithm.
  2875 				3. If a non-overlapping position was found in the previous step,
  2876 					set the item's row-start and column-start lines to the <a>cursor's</a> position.
  2877 					Otherwise,
  2878 					increment the <a>auto-placement cursor</a>’s row position
  2879 					(creating new rows in the <a>implicit grid</a> as necessary),
  2880 					reset its column position to the start-most column line in the <a>implicit grid</a>,
  2881 					and return to the previous step.
  2883 <!--
  2884    ███    ████████   ██████  ████████   ███████   ██████
  2885   ██ ██   ██     ██ ██    ██ ██     ██ ██     ██ ██    ██
  2886  ██   ██  ██     ██ ██       ██     ██ ██     ██ ██
  2887 ██     ██ ████████   ██████  ████████  ██     ██  ██████
  2888 █████████ ██     ██       ██ ██        ██     ██       ██
  2889 ██     ██ ██     ██ ██    ██ ██        ██     ██ ██    ██
  2890 ██     ██ ████████   ██████  ██         ███████   ██████
  2891 -->
  2893 <h2 id="abspos">
  2894 Absolute Positioning</h2>
  2896 <h3 id="abspos-items">
  2897 With a Grid Container as Containing Block</h3>
  2899 	If an absolutely positioned element's <a>containing block</a>
  2900 	is generated by a <a>grid container</a>,
  2901 	the containing block corresponds to the <a>grid area</a> determined by its <a>grid-placement properties</a>.
  2902 	The offset properties ('top'/'right'/'bottom'/'left')
  2903 	then indicate offsets inwards from the corresponding edges
  2904 	of this <a>containing block</a>, as normal.
  2906 	Note: While absolutely-positioning an element to a <a>grid container</a>
  2907 	does allow it to align to that container's <a>grid lines</a>,
  2908 	such elements do not take up space or otherwise participate in the layout of the grid.
  2910 	<div class='example'>
  2911 		<pre>
  2912 			.grid {
  2913 				grid: 10rem 10rem 10rem 10rem / 1fr 1fr 1fr 1fr;
  2914 				/* 4 columns of ''10rem'' each,
  2915 				   4 equal-height rows filling the <a>grid container</a> */
  2916 				justify-content: center;
  2917 				/* center the grid horizontally within the <a>grid container</a> */
  2918 				position: relative;
  2919 				/* Establish abspos <a>containing block</a> */
  2922 			.abspos {
  2923 				grid-row-start: 1;     /* 1st grid row line = top of grid container */
  2924 				grid-row-end: span 2;  /* 3rd grid row line */
  2925 				grid-column-start: 3;  /* 3rd grid col line */
  2926 				grid-column-end: auto; /* right padding edge */
  2927 				/* <a>Containing block</a> covers the top right quadrant of the <a>grid container</a> */
  2929 				position: absolute;
  2930 				top: 70px;
  2931 				bottom: 40px;
  2932 				left: 100px;
  2933 				right: 30px;
  2935 		</pre>
  2937 		<figure>
  2938 			<img src="images/abspos-grid.svg" width="702" height="402" alt=''>
  2939 		</figure>
  2941 		Note: Grids and the <a>grid-placement properties</a> are <a>flow-relative</a>,
  2942 		while abspos offsets are <a>physical</a>,
  2943 		so if the 'direction' or 'writing-mode' properties change,
  2944 		the grid will transform to match,
  2945 		but the offsets won't.
  2946 	</div>
  2948 	Instead of auto-placement, an ''auto'' value for a <a>grid-placement property</a>
  2949 	contributes a special line to the <a>placement</a>
  2950 	whose position is that of the corresponding padding edge of the <a>grid container</a>
  2951 	(the padding edge of the scrollable area, if the <a>grid container</a> overflows).
  2952 	These lines become the first and last lines (0th and -0th) of the <dfn>augmented grid</dfn>
  2953 	used for positioning absolutely-positioned items.
  2955 	Note: Thus, by default, the absolutely-positioned box's <a>containing block</a> will correspond
  2956 	to the padding edges of the <a>grid container</a>, as it does for <a>block containers</a>.
  2958 	Absolute positioning occurs after layout of the <a>grid</a>	and its in-flow contents
  2959 	and does not contribute to the sizing of any grid tracks
  2960 	or affect the size/configuration of the grid in any way.
  2961 	If a <a>grid-placement property</a> refers to a non-existent line
  2962 	either by explicitly specifying such a line or by spanning outside of the existing <a>implicit grid</a>,
  2963 	it is instead treated as specifying ''auto''
  2964 	(instead of creating new <a>implicit grid lines</a>).
  2966 	If the <a>placement</a> only contains a <a>grid span</a>,
  2967 	replace it with the two ''auto'' lines in that axis.
  2968 	(This happens when both <a>grid-placement properties</a> in an axis contributed a span originally,
  2969 	and [[#grid-placement-errors]] caused the second span to be ignored.)
  2972 <h3 id="static-position">
  2973 With a Grid Container as Parent</h3>
  2975 	The <a href="http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width">static position</a> [[!CSS21]]
  2976 	of an absolutely-positioned child of a <a>grid container</a>
  2977 	is determined as if it were the sole grid item
  2978 	in a <a>grid area</a>
  2979 	whose edges coincide with the padding edges of the <a>grid container</a>.
  2980 	However, if the <a>grid container</a> parent is also the generator of the absolutely positioned element's <a>containing block</a>,
  2981 	instead use the <a>grid area</a> determined in [[#abspos-items]].
  2983 	Note: Note that this position is affected by the values of 'justify-self' and 'align-self' on the child,
  2984 	and that, as in most other layout models,
  2985 	the absolutely-positioned child has no effect on the size of the containing block
  2986 	or layout of its contents.
  2988 <!--
  2989    ███    ██       ████  ██████   ██    ██ ██     ██ ████████ ██    ██ ████████
  2990   ██ ██   ██        ██  ██    ██  ███   ██ ███   ███ ██       ███   ██    ██
  2991  ██   ██  ██        ██  ██        ████  ██ ████ ████ ██       ████  ██    ██
  2992 ██     ██ ██        ██  ██   ████ ██ ██ ██ ██ ███ ██ ██████   ██ ██ ██    ██
  2993 █████████ ██        ██  ██    ██  ██  ████ ██     ██ ██       ██  ████    ██
  2994 ██     ██ ██        ██  ██    ██  ██   ███ ██     ██ ██       ██   ███    ██
  2995 ██     ██ ████████ ████  ██████   ██    ██ ██     ██ ████████ ██    ██    ██
  2996 -->
  2998 <h2 id='alignment'>
  2999 Alignment and Spacing</h2>
  3001 	After a <a>grid container</a>’s <a>grid tracks</a> have been sized,
  3002 	and the dimensions of all <a>grid items</a> are finalized,
  3003 	<a>grid items</a> can be aligned within their <a>grid areas</a>.
  3005 	The 'margin' properties can be used to align items in a manner similar to,
  3006 	but more powerful than,
  3007 	what margins can do in block layout.
  3008 	<a>Grid items</a> also respect the alignment properties from the Box Alignment spec,
  3009 	which allow easy keyword-based alignment of items in both the <a>row axis</a> and <a>column axis</a>.
  3011 	By default,
  3012 	<a>grid items</a> stretch to fill their <a>grid area</a>.
  3013 	However, if 'justify-self' or 'align-self' compute to a value other than ''justify-self/stretch''
  3014 	or margins are <a value for="margin">auto</a>,
  3015 	<a>grid items</a> will auto-size to fit their contents.
  3017 <!--
  3018  ██████   ████████  ████ ████████           ██████      ███    ████████
  3019 ██    ██  ██     ██  ██  ██     ██         ██    ██    ██ ██   ██     ██
  3020 ██        ██     ██  ██  ██     ██         ██         ██   ██  ██     ██
  3021 ██   ████ ████████   ██  ██     ██ ███████ ██   ████ ██     ██ ████████
  3022 ██    ██  ██   ██    ██  ██     ██         ██    ██  █████████ ██
  3023 ██    ██  ██    ██   ██  ██     ██         ██    ██  ██     ██ ██
  3024  ██████   ██     ██ ████ ████████           ██████   ██     ██ ██
  3025 -->
  3027 <h3 id='gutters'>
  3028 Gutters: the 'grid-column-gap', 'grid-row-gap', and 'grid-gap' properties</h3>
  3030 	<pre class='propdef'>
  3031 	Name: grid-row-gap, grid-column-gap
  3032 	Value: <<length>>
  3033 	Initial: 0
  3034 	Applies to: <a>grid containers</a>
  3035 	Inherited: no
  3036 	Percentages: n/a
  3037 	Media: visual
  3038 	Computed value: absolute <<length>>
  3039 	Animatable: as <<length>>
  3040 	</pre>
  3042 	These properties specify the <dfn lt=gutter>gutters</dfn> between
  3043 	<a>grid rows</a> and <a>grid columns</a>, respectively.
  3044 	The effect is as though the affected <a>grid lines</a> acquired width:
  3045 	the <a>grid track</a> between two <a>grid lines</a>
  3046 	is the space between the <a>gutters</a> that represent them.
  3047 	For the purpose of <a href="#algo-track-sizing">track sizing</a>,
  3048 	each <a>gutter</a> is essentially treated as an extra track of the specified length.
  3049 	Negative values are invalid.
  3051 	Note: Additional spacing may be added between tracks
  3052 	due to 'justify-content'/'align-content'.
  3053 	See [[#algo-overview]].
  3054 	This space effectively increases the size of the <a>gutters</a>.
  3056 	If a <a>grid</a> is <a>fragmented</a> between tracks,
  3057 	the <a>gutter</a> spacing between those tracks must be suppressed.
  3059 	<pre class='propdef'>
  3060 	Name: grid-gap
  3061 	Value: <<'grid-row-gap'>> <<'grid-column-gap'>>?
  3062 	Initial: see individual properties
  3063 	Applies to: see individual properties
  3064 	Inherited: see individual properties
  3065 	Percentages: see individual properties
  3066 	Media: see individual properties
  3067 	Computed value: see individual properties
  3068 	</pre>
  3070 	This property is a <a>shorthand</a> that sets 'grid-row-gap' and 'grid-column-gap' in one declaration.
  3071 	If <<'grid-column-gap'>> is omitted,
  3072 	it's set to the same value as <<'grid-row-gap'>>.
  3074 <h3 id='auto-margins'>
  3075 Aligning with <a value for="margin">auto</a> margins</h3>
  3077 	<em>This section is non-normative.
  3078 		The normative definition of how margins affect grid items is in <a section href="#layout-algorithm"></a>.</em>
  3080 	Auto margins on <a>grid items</a> have an effect very similar to auto margins in block flow:
  3082 	<ul>
  3083 		<li>
  3084 			During calculations of <a>grid track</a> sizes, auto margins are treated as ''0''.
  3086 		<li>
  3087 			Auto margins absorb positive free space
  3088 			prior to alignment via the alignment properties
  3089 			(defined in the next sections).
  3091 		<li>
  3092 			Overflowing elements ignore their auto margins and overflow in the <a>end</a> directions.
  3093 	</ul>
  3095 	Note: Note that, if free space is distributed to auto margins,
  3096 	the alignment properties will have no effect in that dimension
  3097 	because the margins will have stolen all the free space
  3098 	left over after sizing.
  3100 	<div class='example'>
  3101 		<p class='issue'>
  3102 			TODO: EXAMPLE HERE
  3103 	</div>
  3106 <h3 id='row-align'>
  3107 Row-axis Alignment: the 'justify-self' and 'justify-items' properties</h3>
  3109 	<a>Grid items</a> can be aligned in the inline dimension
  3110 	by using the 'justify-self' property on the <a>grid item</a>
  3111 	or 'justify-items' property on the <a>grid container</a>,
  3112 	as defined in [[!CSS3-ALIGN]].
  3114 	<div class='example'>
  3115 		For example,
  3116 		for an English document,
  3117 		the inline axis is horizontal,
  3118 		and so the 'justify-*' properties align the <a>grid items</a> horizontally.
  3120 		<p class='issue'>
  3121 			TODO: provide example
  3122 	</div>
  3125 <h3 id='column-align'>
  3126 Column-axis Alignment: the 'align-self' and 'align-items' properties</h3>
  3128 	<a>Grid items</a> can also be aligned in the block dimension
  3129 	(perpendicular to the inline dimension)
  3130 	by using the 'align-self' property on the <a>grid item</a>
  3131 	or 'align-items' property on the <a>grid container</a>,
  3132 	as defined in [[!CSS3-ALIGN]].
  3134 <h3 id='grid-align'>
  3135 Aligning the Grid: the 'justify-content' and 'align-content' properties</h3>
  3137 	If the <a>grid</a>’s outer edges do not correspond to the <a>grid container</a>’s content edges
  3138 	(for example, if no columns are flex-sized),
  3139 	the <a>grid tracks</a> are aligned within the content box according to the 'justify-content' and 'align-content' properties on the <a>grid container</a>.
  3141 	<div class='example'>
  3142 		For example, the following grid is centered vertically,
  3143 		and aligned to the right edge of its <a>grid container</a>:
  3145 		<pre>
  3146 			.grid {
  3147 				display: grid;
  3148 				grid: 12rem 12rem 12rem 12rem / 10rem 10rem 10rem 10rem;
  3149 				justify-content: end;
  3150 				align-content: center;
  3152 		</pre>
  3154 		<figure>
  3155 			<img src="images/align-justify-content.svg" width="352" height="252" alt=''>
  3156 		</figure>
  3157 	</div>
  3159 	If there are no <a>grid tracks</a>
  3160 	(the <a>explicit grid</a> is empty, and no tracks were created in the <a>implicit grid</a>),
  3161 	the sole <a>grid line</a> in each axis is aligned with the start edge of the <a>grid container</a>.
  3163 	Note that certain values of 'justify-content' and 'align-content'
  3164 	can cause the tracks to be spaced apart
  3165 	(''justify-content/space-around'', ''justify-content/space-between'', ''justify-content/space-evenly'')
  3166 	or to be resized (''&lt;content-distribution>/stretch'').
  3167 	If the <a>grid</a> is <a>fragmented</a> between tracks,
  3168 	any such additional spacing between those tracks must be suppressed.
  3170 	Issue: Add example of fixed size spanner getting extra space from content-distribution.
  3172 <h3 id='grid-baselines'>
  3173 Grid Baselines</h3>
  3175 	The baselines of a <a>grid container</a> are determined as follows:
  3177 	<ol>
  3178 		<li>
  3179 			If any of the <a>grid items</a> whose areas intersect the <a>grid container</a>’s first row/column
  3180 			<a href="#baseline-participation">participate in baseline alignment</a>,
  3181 			the grid container's baseline is the baseline of those <a>grid items</a>.
  3183 		<li>
  3184 			Otherwise, if the grid container has at least one <a>grid item</a> whose area intersects the first row/column,
  3185 			and the first such <a>grid item</a> (in <a>order-modified grid order</a>) has a baseline
  3186 			parallel to the relevant axis,
  3187 			the grid container's baseline is that baseline.
  3189 		<li>
  3190 			Otherwise, the grid container's baseline is <a href="http://www.w3.org/TR/css3-writing-modes/#inline-alignment">synthesized</a>
  3191 			from the first item's (in <a>order-modified grid order</a>) content box,
  3192 			or, failing that, from the grid container's content box.
  3193 	</ol>
  3195 	A <a>grid item</a> <dfn export id="baseline-participation">participates in baseline alignment</dfn> in a particular dimension
  3196 	if its value for 'align-self' or 'justify-self', as appropriate, is ''baseline''
  3197 	and its inline axis is parallel to that dimension.
  3199 	<dfn export lt="order-modified grid order">'order'-modified grid order</dfn> is the order in which
  3200 	<a>grid items</a> are encountered when traversing the grid's <a>grid cells</a>,
  3201 	in row-major order if calculating the inline-axis baseline,
  3202 	or in column-major order if calculating the block-axis baseline.
  3203 	If two items are encountered at the same time,
  3204 	they are taken in <a>order-modified document order</a>.
  3206 	When calculating the baseline according to the above rules,
  3207 	if the box contributing a baseline has an 'overflow' value that allows scrolling,
  3208 	the box must be treated as being in its initial scroll position
  3209 	for the purpose of determining its baseline.
  3211 	When <a href="http://www.w3.org/TR/CSS21/tables.html#height-layout">determining the baseline of a table cell</a>,
  3212 	a grid container provides a baseline just as a line box or table-row does. [[!CSS21]]
  3214 <!--
  3215  ██████  ████ ████████ ████ ██    ██  ██████
  3216 ██    ██  ██       ██   ██  ███   ██ ██    ██
  3217 ██        ██      ██    ██  ████  ██ ██
  3218  ██████   ██     ██     ██  ██ ██ ██ ██   ████
  3219       ██  ██    ██      ██  ██  ████ ██    ██
  3220 ██    ██  ██   ██       ██  ██   ███ ██    ██
  3221  ██████  ████ ████████ ████ ██    ██  ██████
  3222 -->
  3224 <h2 id='layout-algorithm'>
  3225 Grid Sizing</h2>
  3227 	This section defines the <dfn export>grid sizing algorithm</dfn>,
  3228 	which determines the size of all <a>grid tracks</a>
  3229 	and, by extension, the entire grid.
  3231 	Each track has specified <a lt="min track sizing function">minimum</a> and
  3232 	<a lt="max track sizing function">maximum</a> <a>sizing functions</a>
  3233 	(which may be the same).
  3234 	Each <a>sizing function</a> is either:
  3236 	<ul>
  3237 		<li>A <dfn>fixed sizing function</dfn> (<<length>> or resolveable <<percentage>>).
  3238 		<li>An <dfn>intrinsic sizing function</dfn> (''min-content'', ''max-content'', or ''auto'').
  3239 		<li>A <dfn>flexible sizing function</dfn> (<<flex>>).
  3240 	</ul>
  3242 	The <a>grid sizing algorithm</a> defines how to resolve these sizing constraints into used track sizes.
  3244 <h3 id="algo-overview">
  3245 Grid Sizing Algorithm</h3>
  3247 	<ol>
  3248 		<li>
  3249 			First, the <a>track sizing algorithm</a> is used to resolve the sizes of the <a>grid columns</a>.
  3251 			If calculating the layout of a <a>grid item</a> in this step
  3252 			depends on the <a>available space</a> in the <a>block axis</a>,
  3253 			assume the <a>available space</a> that it would have
  3254 			if any row with a <a>definite</a> <a>max track sizing function</a>
  3255 			had that size and all other rows were infinite.
  3257 		<li>
  3258 			Next, the <a>track sizing algorithm</a> resolves the sizes of the <a>grid rows</a>,
  3259 			using the <a>grid column</a> sizes calculated in the previous step.
  3261 		<li>
  3262 			Then, if the <a>min-content contribution</a> of any grid items have changed
  3263 			based on the row sizes calculated in step 2,
  3264 			steps 1 and 2 are repeated with the new <a>min-content contribution</a> (once only).
  3266 			<div class="note">
  3267 				This cycle is necessary for cases where the <a>inline size</a> of a <a>grid item</a>
  3268 				depends on the <a>block size</a> of its <a>grid area</a>.
  3269 				Examples include wrapped column <a>flex containers</a> (''flex-flow: column wrap''),
  3270 				<a>orthogonal flows</a> ('writing-mode'),
  3271 				and <a spec=css-multicol>multi-column elements</a>.
  3272 			</div>
  3274 			Issue: Is one cycle enough?
  3276 		<li>
  3277 			Finally, the <a>grid container</a> is sized
  3278 			using the resulting size of the <a>grid</a> as its content size,
  3279 			and the tracks are aligned within the <a>grid container</a>
  3280 			according to the 'align-content' and 'justify-content' properties.
  3281 			<span class="note">Note: This can introduce extra space within or between tracks.</span>
  3282 			When introducing space within tracks,
  3283 			only tracks with an ''grid-template-rows/auto'' <a>max track sizing function</a> accept space.
  3284 	</ol>
  3286 	Once the size of each <a>grid area</a> is thus established,
  3287 	the <a>grid items</a> are laid out into their respective containing blocks.
  3289 <h3 id='algo-terms'>
  3290 Track Sizing Terminology</h3>
  3292 	<dl noexport>
  3293 		<dt><dfn>min track sizing function</dfn>
  3294 		<dd>
  3295 			If the track was sized with a ''minmax()'' function,
  3296 			this is the first argument to that function.
  3297 			Otherwise, it's the track's sizing function.
  3299 		<dt><dfn>max track sizing function</dfn>
  3300 		<dd>
  3301 			If the track was sized with a ''minmax()'' function,
  3302 			this is the second argument to that function.
  3303 			Otherwise, it's the track's sizing function.
  3305 		<dt><dfn>available grid space</dfn>
  3306 		<dd>
  3307 			Independently in each dimension, the <a>available grid space</a> is:
  3309 			* If the <a>grid container's</a> size is definite, then use the size of the resulting content box.
  3310 			* If the <a>grid container</a> is being sized under a <a>min-content constraint</a> or <a>max-content constraint</a>  , then the <a>available grid space</a> is that constraint (and is indefinite).
  3312 			Note: ''auto'' sizes that indicate content-based sizing (e.g. the height of a block-level box in horizontal writing modes) are equivalent to ''max-content''.
  3314 			In all cases, clamp the <a>available grid space</a> by the <a>grid container's</a> min/max-width/height properties, if they are definite.
  3316 		<dt><dfn>free space</dfn>
  3317 		<dd>
  3318 			Equal to the <a>available grid space</a> minus the sum of the <a>base sizes</a> of all the grid tracks, floored at zero.
  3319 			If <a>available grid space</a> is <a>indefinite</a>,
  3320 			the <a>free space</a> is <a>indefinite</a> as well.
  3322 		<dt><dfn>span count</dfn>
  3323 		<dd>
  3324 			The number of <a>grid tracks</a> crossed by a <a>grid item</a> in the applicable dimension.
  3325 	</dl>
  3327 <h3 id="algo-track-sizing">
  3328 Track Sizing Algorithm</h3>
  3330 	The remainder of this section is the <dfn>track sizing algorithm</dfn>,
  3331 	which calculates from the <a lt="min track sizing function">min</a> and <a>max track sizing functions</a>
  3332 	the used track size.
  3333 	Each track has a <dfn>base size</dfn>,
  3334 	a <<length>> which grows throughout the algorithm
  3335 	and which will eventually be the track's final size,
  3336 	and a <dfn>growth limit</dfn>,
  3337 	a <<length>> which provides a desired maximum size for the <a>base size</a>.
  3338 	There are 4 steps:
  3340 	<ol>
  3341 		<li><a href="#algo-init">Initialize Track Sizes</a>
  3342 		<li><a href="#algo-content">Resolve Intrinsic Track Sizes</a>
  3343 		<li><a href="#algo-grow-tracks">Maximize Tracks</a>
  3344 		<li><a href="#algo-flex-tracks">Stretch Flexible Tracks</a>
  3345 	</ol>
  3347 <h3 id="algo-init">
  3348 Initialize Track Sizes</h3>
  3350 	<strong>Initialize each track's base size and growth limit.</strong>
  3351 	For each track,
  3352 	if the track's <a>min track sizing function</a> is:
  3354 	<dl class=switch>
  3355 		<dt>A <a>fixed sizing function</a>
  3356 		<dd>
  3357 			Resolve to an absolute length and use that size as the track’s initial <a>base size</a>.
  3359 			Note: <a>Indefinite</a> lengths cannot occur,
  3360 			as they're treated as ''auto''.
  3362 		<dt>An <a>intrinsic sizing function</a>
  3363 		<dt>A <a>flexible sizing function</a>
  3364 		<dd>
  3365 			Use an initial <a>base size</a> of zero.
  3366 	</dl>
  3368 	For each track,
  3369 	if the track's <a>max track sizing function</a> is:
  3371 	<dl class=switch>
  3372 		<dt>A <a>fixed sizing function</a>
  3373 		<dd>
  3374 			Resolve to an absolute length and use that size as the track’s initial <a>growth limit</a>.
  3376 		<dt>An <a>intrinsic sizing function</a>
  3377 		<dd>
  3378 			Use an initial <a>growth limit</a> of infinity.
  3380 		<dt>A <a>flexible sizing function</a>
  3381 		<dd>
  3382 			Use the track’s initial <a>base size</a> as its initial <a>growth limit</a>.
  3383 	</dl>
  3385 	In all cases, if the <a>growth limit</a> is less than the <a>base size</a>,
  3386 	increase the <a>growth limit</a> to match the <a>base size</a>.
  3388 	Note: <a>Gutters</a> are treated as fixed-size tracks for the purpose of the <a>track sizing algorithm</a>.
  3390 <h3 id="algo-content">
  3391 Resolve Intrinsic Track Sizes</h3>
  3393 	This step resolves intrinsic track <a>sizing functions</a> to absolute lengths.
  3394 	First it resolves those sizes based on items that are contained wholly within a single track.
  3395 	Then it gradually adds in the space requirements of items that span multiple tracks,
  3396 	evenly distributing the extra space across those tracks
  3397 	insofar as possible.
  3399 	When the <a>grid container</a> is being sized under a <a>min-content constraint</a>,
  3400 	a track with a flexible <a>min track sizing function</a>
  3401 	is treated as if its <a>min track sizing function</a> was ''min-content''
  3402 	for the purposes of this step.
  3403 	<span class='issue'>This seems correct, but should be checked because it wasn't in the original algorithm.</span>
  3405 	Note: There is no single way to satisfy these constraints
  3406 	when items span across multiple tracks.
  3407 	This algorithm embodies a number of heuristics
  3408 	which have been seen to deliver good results on real-world use-cases,
  3409 	such as the "game" examples earlier in this specification.
  3410 	This algorithm may be updated in the future
  3411 	to take into account more advanced heuristics as they are identified.
  3413 	<ol>
  3414 		<li>
  3415 			<strong>Size tracks to fit non-spanning items:</strong>
  3416 			For each track with an intrinsic <a>track sizing function</a>,
  3417 			consider the items in it with a span of 1:
  3418 			<ul>
  3419 				<li>
  3420 					<strong>For min-content minimums:</strong>
  3421 					If the track has a ''min-content'' <a>min track sizing function</a>,
  3422 					set its <a>base size</a>
  3423 					to the maximum of the items’ <a>min-content contributions</a>.
  3424 				<li>
  3425 					<strong>For max-content minimums:</strong>
  3426 					If the track has a ''max-content'' <a>min track sizing function</a>,
  3427 					set its <a>base size</a>
  3428 					to the maximum of the items’ <a>max-content contributions</a>.
  3429 				<li>
  3430 					<strong>For auto minimums:</strong>
  3431 					If the track has an ''auto'' <a>min track sizing function</a>
  3432 					and the <a>grid container</a> is being sized under a <a lt="min-content constraint">min/max-content constraint</a>,
  3433 					set the track's <a>base size</a>
  3434 					to the maximum of its items’ <a lt="min-content contribution">min/max-content contributions</a>,
  3435 					respectively.
  3437 					Otherwise,
  3438 					set its <a>base size</a>
  3439 					to the maximum of its items’ “min-size contributions”:
  3440 					the value specified by its respective 'min-width' or 'min-height' properties
  3441 					(whichever matches the relevant axis)
  3442 					if the specified size is ''width/auto'',
  3443 					or else the item’s <a>min-content contribution</a>.
  3444 					Note: For items with a specified minimum size of ''min-width/auto'' (the initial value),
  3445 					this is equivalent to a min-content minimum.
  3446 				<li>
  3447 					<strong>For min-content maximums:</strong>
  3448 					If the track has a ''min-content'' <a>max track sizing function</a>,
  3449 					set its <a>growth limit</a>
  3450 					to the maximum of the items’ <a>min-content contributions</a>.
  3451 				<li>
  3452 					<strong>For max-content and auto maximums:</strong>
  3453 					If the track has a ''max-content'' or ''auto'' <a>max track sizing function</a>,
  3454 					set its <a>growth limit</a>
  3455 					to the maximum of the items’ <a>max-content contributions</a>.
  3456 			</ul>
  3458 			In all cases, if a track’s <a>growth limit</a> is now less than its <a>base size</a>,
  3459 			increase the <a>growth limit</a> to match the <a>base size</a>.
  3461 		<li>
  3462 			<strong>Increase sizes to accommodate spanning items:</strong>
  3463 			Next, consider the items with a span of 2
  3464 			that do not span a track with a <a>flexible sizing function</a>:
  3465 			<!-- auto-min contribution <= min-content contribution <= max-content contribution -->
  3466 			<ol>
  3467 				<li>
  3468 					<strong>For intrinsic minimums:</strong>
  3469 					First increase the <a>base size</a> of tracks with
  3470 					a <a>min track sizing function</a> of ''min-content'', ''max-content'', or ''auto''
  3471 					by <a href="#extra-space">distributing extra space</a> as needed
  3472 					to accommodate the contributions dictated by these items’
  3473 					minimum size (as specified by 'min-width'/'min-height').
  3474 				<li>
  3475 					<strong>For content-based minimums:</strong>
  3476 					Next continue to increase the <a>base size</a> of tracks with
  3477 					a <a>min track sizing function</a> of ''min-content'' or ''max-content''
  3478 					by <a href="#extra-space">distributing extra space</a> as needed
  3479 					to account for these items' <a>min-content contributions</a>.
  3480 				<li>
  3481 					<strong>For max-content minimums:</strong>
  3482 					Third continue to increase the <a>base size</a> of tracks with
  3483 					a <a>min track sizing function</a> of ''max-content''
  3484 					by <a href="#extra-space">distributing extra space</a> as needed
  3485 					to account for these items' <a>max-content contributions</a>.
  3486 				<li>
  3487 					If at this point any track’s <a>growth limit</a> is now less than its <a>base size</a>,
  3488 					increase its <a>growth limit</a> to match its <a>base size</a>.
  3489 				<li>
  3490 					<strong>For intrinsic maximums:</strong>
  3491 					Next increase the <a>growth limit</a> of tracks with
  3492 					a <a>max track sizing function</a> of ''min-content'' or ''max-content'' (including ''auto'')
  3493 					by <a href="#extra-space">distributing extra space</a> as needed
  3494 					to account for these items' <a>min-content contributions</a>.
  3495 					Mark any tracks whose <a>growth limit</a> changed
  3496 					from infinite to finite in this step
  3497 					as <dfn>infinitely growable</dfn> for the next step.
  3499 					<details class=why>
  3500 						<summary>Why does the <a>infinitely growable</a> flag exist?</summary>
  3502 						<a href="http://lists.w3.org/Archives/Public/www-style/2014Mar/0500.html">Peter Salas explains</a>:
  3504 						<blockquote cite="http://lists.w3.org/Archives/Public/www-style/2014Mar/0500.html">
  3505 							Consider the following case:
  3507 							Two "auto" tracks (i.e. "minmax(min-content, max-content) minmax(min-content, max-content)").
  3508 							Item 1 is in track 1, and has min-content = max-content = 10.
  3509 							Item 2 spans tracks 1 and 2, and has min-content = 30, max-content = 100.
  3511 							After resolving min-content/max-content for the first item, we have this.
  3513 							track 1: used breadth = 10 max breadth = 10
  3515 							track 2: used breadth = 0 max breadth = infinity
  3517 							Then we resolve min-content/max-content for the second item.
  3519 							Phase 1 sets the used breadth of track 2 to 20 so that the two tracks' used breadths sum to 30.
  3520 							Phase 2 does nothing because there are no relevant tracks.
  3521 							Phase 3 sets the max breadth of track 2 to 20 so that the two tracks' max breadths sum to 30.
  3522 							In phase 4, we need to grow the sum of the max breadths by 70 to accommodate item 2.
  3523 							Two options are:
  3525 							1. Grow each track's max breadth equally,
  3526 								and end up with max breadths = [45, 55].
  3527 							2. Grow only the second track's max breadth,
  3528 								and end up with max breadths = [10, 90].
  3530 							By not considering the just-set max breadth as a constraint during space distribution
  3531 							(i.e. by treating it as infinity),
  3532 							we get the second result,
  3533 							which we considered a better result because the first track remains sized exactly to the first item.
  3534 						</blockquote>
  3535 					</details>
  3536 				<li>
  3537 					<strong>For max-content maximums:</strong>
  3538 					Lastly continue to increase the <a>growth limit</a> of tracks with
  3539 					a <a>max track sizing function</a> of ''max-content'' (including ''auto'')
  3540 					by <a href="#extra-space">distributing extra space</a> as needed
  3541 					to account for these items' <a>max-content contributions</a>.
  3542 			</ol>
  3544 			Repeat incrementally for items with greater spans until all items have been considered.
  3546 		<li>
  3547 			If any track still has an infinite <a>growth limit</a>
  3548 			(because, for example, it had no items placed in it),
  3549 			set its <a>growth limit</a> to its <a>base size</a>.
  3550 	</ol>
  3552 	<p id='extra-space'>
  3553 		To <dfn noexport>distribute extra space</dfn>
  3554 		by increasing the affected sizes of a set of tracks
  3555 		as required by a set of intrinsic size contributions,
  3557 	<ol>
  3558 		<li>
  3559 			Maintain separately for each affected <a>base size</a> or <a>growth limit</a>
  3560 			an amount of planned increase.
  3561 			(This prevents the size increases from becoming order-dependent.)
  3563 		<li>
  3564 			For each considered item,
  3565 			<ol>
  3566 				<li>
  3567 					<strong>Find the space to distribute:</strong>
  3568 					Subtract the corresponding size (<a>base size</a> or <a>growth limit</a>) of <em>every</em> spanned track
  3569 					from the item's size contribution to find the item's remaining size contribution.
  3570 					(For infinite <a>growth limits</a>, substitute the track's <a>base size</a>.)
  3571 					This is the space to distribute. Floor it at zero.
  3572 					<pre><var>extra-space</var> = max(0, <var>size-contribution</var> - ∑<var>track-sizes</var>)</pre>
  3574 				<li>
  3575 					<strong>Distribute space to base sizes up to growth limits:</strong>
  3576 					Distribute the space equally to the planned increase of each spanned track with an affected size,
  3577 					freezing tracks as their planned size reaches their <a>growth limits</a>
  3578 					(and continuing to grow the unfrozen tracks as needed).
  3580 					If a track was marked as <a>infinitely growable</a> for this phase,
  3581 					treat its <a>growth limit</a> as infinite for this calculation
  3582 					(and then unmark it).
  3584 					Note: If the affected size was a <a>growth limit</a>,
  3585 					this step has no effect.
  3587 				<li>
  3588 					<strong>Distribute space beyond growth limits:</strong>
  3589 					If space remains after all tracks are frozen,
  3590 					unfreeze and continue to distribute space to…
  3592 					<ul>
  3593 						<li>
  3594 							when handling ''min-content'' or ''auto'' <a>base sizes</a>:
  3595 							any affected track that happens to also have an intrinsic <a>max track sizing function</a>;
  3596 							if there are no such tracks, then all affected tracks.
  3597 						<li>
  3598 							when handling ''max-content'' <a>base sizes</a>:
  3599 							any affected track that happens to also have a ''max-content'' <a>max track sizing function</a>;
  3600 							if there are no such tracks, then all affected tracks.
  3601 						<li>when handling any intrinsic <a>growth limit</a>:
  3602 							all affected tracks.
  3603 					</ul>
  3604 				<li>
  3605 					<strong>Update the tracks' affected sizes</strong>
  3606 					by folding in the calculated increase
  3607 					so that the next round of space distribution will account for the increase.
  3608 					(If the affected size is infinite,
  3609 					set it to the track's <a>base size</a> plus the calculated increase.)
  3610 			</ol>
  3611 	</ol>
  3613 	Note: When this step is complete,
  3614 	all intrinsic <a>base sizes</a> and <a>growth limits</a>
  3615 	will have been resolved to absolute lengths.
  3618 <h3 id="algo-grow-tracks">
  3619 Maximize Tracks</h3>
  3621 	If the <a>free space</a> is positive, distribute it equally to all tracks,
  3622 	freezing tracks as they reach their <a>growth limits</a>
  3623 	(and continuing to grow the unfrozen tracks as needed).
  3625 	For the purpose of this step:
  3626 	if sizing the <a>grid container</a> under a <a>max-content constraint</a>,
  3627 	the <a>free space</a> is infinite;
  3628 	if sizing under a <a>min-content constraint</a>,
  3629 	the <a>free space</a> is zero.
  3631 	If this would cause the grid to be larger than the <a>grid container's</a> <a property lt=max-width>max-width/height</a>,
  3632 	then redo this step,
  3633 	treating the <a>available grid space</a> as equal to the <a>grid container's</a> content box size
  3634 	when it's sized to its <a property lt=max-width>max-width/height</a>.
  3636 <h3 id="algo-flex-tracks">
  3637 Stretch Flexible Tracks</h3>
  3639 	This step sizes flexible tracks
  3640 	using the largest value it can assign to an ''fr''
  3641 	without exceeding the <a>available space</a>.
  3643 	First, find the used <a>flex fraction</a>:
  3645 	<dl>
  3646 		<dt>If the <a>free space</a> is zero:
  3647 		<dd>
  3648 			The used <a>flex fraction</a> is zero.
  3650 		<dt>If the <a>free space</a> is a <a>definite</a> length:
  3651 		<dd>
  3652 			The used <a>flex fraction</a> is the result of
  3653 			<a href="#algo-find-fr-size">finding the size of an fr</a>
  3654 			using all of the <a>grid tracks</a>
  3655 			and a <a>space to fill</a> of the <a>available grid space</a>.
  3657 		<dt>If the <a>free space</a> is an <a>indefinite</a> length:
  3658 		<dd>
  3659 			The used <a>flex fraction</a> is the maximum of:
  3661 			<ul>
  3662 				<li>
  3663 					Each flexible track's <a>base size</a> divided by its <a>flex factor</a>.
  3665 				<li>The result of
  3666 					<a href="#algo-find-fr-size">finding the size of an fr</a>
  3667 					for each <a>grid item</a> that crosses a flexible track,
  3668 					using all the grid tracks that the item crosses
  3669 					and a <a>space to fill</a> of the item's <a>max-content contribution</a>.
  3670 			</ul>
  3672 			If using this <a>flex fraction</a> would cause the <a>grid</a> to be smaller than the <a>grid container's</a> <a property lt=min-width>min-width/height</a>
  3673 			(or larger than the <a>grid container's</a> <a property lt=max-width>max-width/height</a>),
  3674 			then redo this step,
  3675 			treating the <a>free space</a> as definite
  3676 			and the <a>available grid space</a> as equal to the <a>grid container's</a> content box size when it's sized to its <a property lt=min-width>min-width/height</a> (<a property lt=max-width>max-width/height</a>).
  3677 	</dl>
  3679 	For each flexible track,
  3680 	if the product of the used <a>flex fraction</a> and the track's <a>flex factor</a>
  3681 	is greater than the track's <a>base size</a>,
  3682 	set its <a>base size</a> to that product.
  3685 <h4 id="algo-find-fr-size">
  3686 Find the Size of an ''fr''</h4>
  3688 	This algorithm finds the largest size that an ''fr'' unit can be
  3689 	without exceeding the target size.
  3690 	It must be called with a set of <a>grid tracks</a>
  3691 	and some quantity of <dfn>space to fill</dfn>.
  3693 	<ol>
  3694 		<li>
  3695 			Let <dfn>leftover space</dfn> be the <a>space to fill</a>
  3696 			minus the <a>base sizes</a> of the non-flexible <a>grid tracks</a>.
  3698 		<li>
  3699 			Let <dfn>flex factor sum</dfn> be the sum of the <a>flex factors</a> of the flexible tracks.
  3700 			If this value is less than 1,
  3701 			set it to 1 instead.
  3703 		<li>
  3704 			Let the <dfn>hypothetical fr size</dfn>
  3705 			be the <a>leftover space</a>
  3706 			divided by the <a>flex factor sum</a>.
  3708 		<li>
  3709 			If the product of the <a>hypothetical fr size</a> and a flexible track's <a>flex factor</a>
  3710 			is less than the track's base size,
  3711 			restart this algorithm
  3712 			treating all such tracks as inflexible.
  3714 		<li>
  3715 			Return the <a>hypothetical fr size</a>.
  3716 	</ol>
  3718 <!--
  3719 ████████ ████████     ███     ██████   ██     ██ ████████ ██    ██ ████████ ████ ██    ██  ██████
  3720 ██       ██     ██   ██ ██   ██    ██  ███   ███ ██       ███   ██    ██     ██  ███   ██ ██    ██
  3721 ██       ██     ██  ██   ██  ██        ████ ████ ██       ████  ██    ██     ██  ████  ██ ██
  3722 ██████   ████████  ██     ██ ██   ████ ██ ███ ██ ██████   ██ ██ ██    ██     ██  ██ ██ ██ ██   ████
  3723 ██       ██   ██   █████████ ██    ██  ██     ██ ██       ██  ████    ██     ██  ██  ████ ██    ██
  3724 ██       ██    ██  ██     ██ ██    ██  ██     ██ ██       ██   ███    ██     ██  ██   ███ ██    ██
  3725 ██       ██     ██ ██     ██  ██████   ██     ██ ████████ ██    ██    ██    ████ ██    ██  ██████
  3726 -->
  3728 <h2 id='pagination'>
  3729 Fragmenting Grid Layout</h2>
  3732 	<p>
  3733 		<a>Grid containers</a> can break across pages
  3734 		between rows
  3735 		and inside items.
  3736 		The <a property lt="break-before">break-*</a> properties apply to grid containers
  3737 		as normal for the formatting context in which they participate.
  3738 		This section defines how they apply to grid items
  3739 		and the contents of grid items.
  3741 	<p>
  3742 		The following breaking rules refer to the fragmentation container as the “page”.
  3743 		The same rules apply to any other fragmentation containers.
  3744 		(Substitute “page” with the appropriate fragmentation container type as needed.)
  3745 		See the CSS3 Fragmentation Module [[!CSS3-BREAK]].
  3747 	<p>
  3748 		The exact layout of a fragmented grid container is not defined in this level of Grid Layout.
  3749 		However, breaks inside a grid container are subject to the following rules:
  3751 	<ul>
  3752 		<li>
  3753 			The 'break-before' and 'break-after' properties on <a>grid items</a>
  3754 			are propagated to their grid row.
  3755 			The 'break-before' property on the first row
  3756 			and the 'break-after' property on the last row
  3757 			are propagated to the grid container.
  3759 		<li>
  3760 			A forced break inside a grid item effectively increases the size of its contents;
  3761 			it does not trigger a forced break inside sibling items.
  3763 		<li>
  3764 			<a href="http://www.w3.org/TR/css3-break/#btw-blocks">Class A break opportunities</a> occur between rows,
  3765 			and <a href="http://www.w3.org/TR/css3-break/#end-block">Class C break opportunities</a> occur between the first/last row and the flex container's content edges.
  3766 			[[!CSS3-BREAK]]
  3768 		<li>
  3769 			When a grid container is continued after a break,
  3770 			the space available to its <a>grid items</a>
  3771 			(in the block flow direction of the fragmentation context)
  3772 			is reduced by the space consumed by grid container fragments on previous pages.
  3773 			The space consumed by a grid container fragment is
  3774 			the size of its content box on that page.
  3775 			If as a result of this adjustment the available space becomes negative,
  3776 			it is set to zero.
  3778 		<li>
  3779 			Aside from the rearrangement of items imposed by the previous point,
  3780 			UAs should attempt to minimize distortation of the grid container
  3781 			with respect to unfragmented flow.
  3782 	</ul>
  3785 <h3 id="fragmentation-alg">
  3786 Sample Fragmentation Algorithm</h3>
  3788 	<p class="issue">
  3789 		This is just a rough draft.
  3790 		This section needs to be severely cross-checked with the [[CSS3-FLEXBOX]] algorithm.
  3791 		Feedback overall is welcome; please reference the rules above instead as implementation guidance.
  3793 	<ol>
  3794 		<li>
  3795 			Layout the grid following the <a section href="#layout-algorithm"></a> by using the
  3796 			fragmentainer box width and assume unlimited height. During this step all 'grid-row'
  3797 			''auto'' and ''fr'' values must be resolved.
  3799 		<li>
  3800 			Layout the grid container using the values resolved in the previous step.
  3802 		<li>
  3803 			If a grid area dimensions change due to fragmentation (do not include items that
  3804 			span rows in this decision), increase the grid row as necessary for rows that either:
  3805 			<ul>
  3806 				<li>
  3807 					have a content min track sizing function.
  3809 				<li>
  3810 					are in a grid that does not have an explicit height and the grid row is flexible.
  3811 			</ul>
  3813 		<li>
  3814 			If the grid height is ''auto'', the height of the grid should be the sum of the final
  3815 			row sizes.
  3817 		<li>
  3818 			If a grid area overflows the grid container due to margins being collapsed during
  3819 			fragmentation, extend the grid container to contain this grid area (this step is
  3820 			necessary in order to avoid circular layout dependencies due to fragmentation).
  3821 	</ol>
  3823 	<p class="note">
  3824 		If the grid’s height is specified, steps three and four may cause the grid rows to
  3825 		overflow the grid.
  3826 	</p>
  3828 <h2 class="no-num" id="acks">
  3829 Acknowledgements</h2>
  3831 	This specification is made possible by input from
  3832 	Erik Anderson,
  3833 	Rossen Atanassov,
  3834 	Manuel Rego Casasnovas,
  3835 	Arron Eicholz,
  3836 	Javier Fernandez,
  3837 	Sylvain Galineau,
  3838 	Markus Mielke,
  3839 	Daniel Holbert,
  3840 	John Jansen,
  3841 	Chris Jones,
  3842 	Kathy Kam,
  3843 	Veljko Miljanic,
  3844 	Mats Palmgren,
  3845 	François Remy,
  3846 	Sergio Villar Senin,
  3847 	Christian Stockwell,
  3848 	Eugene Veselov,
  3849 	and the CSS Working Group members,
  3850 	with special thanks to
  3851 	Rossen Atanassov, Alex Mogilevsky, Phil Cupp, and Peter Salas of Microsoft for creating the initial proposal.
  3852 	Thanks also to Eliot Graff for editorial input.
  3854 <h2 class="no-num" id="changes">
  3855 Changes</h2>
  3857 	The following significant changes were made since the
  3858 	<a href=http://www.w3.org/TR/2015/WD-css-grid-1-20150806/>6 August 2015 Working Draft</a>.
  3860 	* Renamed <css>row-gap</css>/<css>column-gap</css> to 'grid-row-gap'/'grid-column-gap'
  3861 		to avoid having multicol and grid share 'column-gap'.
  3862 		This also preserves <css>grid-</css> as a prefix across these properties and their shorthand.
  3863 	* Split ''auto'' into ''auto-fill'' and ''auto-fit'' keywords for ''repeat()'' notation,
  3864 		adjusted grammar to guarantee a definite number of repetitions,
  3865 		and allowed minimum sizes to increase the number of repetitions past one to fulfill the minimum.
  3866 	* Reduced <<auto-repeat>> syntax to accept only a single track size, for simplicity.
  3867 	* Added information on the speech and navigation impact of reordering with grid placement or 'order'
  3868 		vs. reordering the underlying source.
  3870 	A partial <a href="https://drafts.csswg.org/css-grid-1/issues-wd-20150805">Disposition of Comments</a> is available.
  3872 	See also <a href="http://www.w3.org/TR/2015/WD-css-grid-1-20150806/#changes">previous changes</a>.
  3874 Privacy and Security Considerations {#priv-sec}
  3875 ===============================================
  3877 	Grid introduces no new privacy leaks,
  3878 	or security considerations beyond "implement it correctly".

mercurial