FFFF csswg-drafts/css-align-3/Overview.bs at 7afea74ede5f909e0ce7f0308ff4dfa8d7c1f618 · tursunova/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
2561 lines (2197 loc) · 109 KB

File metadata and controls

2561 lines (2197 loc) · 109 KB
<pre class='metadata'>
Title: CSS Box Alignment Module Level 3
Shortname: css-align
Level: 3
Group: csswg
Status: ED
Work Status: Refining
ED: https://drafts.csswg.org/css-align/
TR: https://www.w3.org/TR/css-align-3/
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/, w3cid 42199
Abstract: This module contains the features of <a href="https://www.w3.org/TR/CSS/">CSS</a> relating to the alignment of boxes within their containers in the various CSS box layout models: block layout, table layout, flex layout, and grid layout. (The alignment of text and inline-level content is defined in [[CSS-TEXT-3]] and [[CSS-INLINE-3]].)
Ignored Terms: table cell, stretch, static position, static-position containing block, static positions
At Risk: ''[ first | last ]? baseline''
At Risk: the <<overflow-position>> keywords
At Risk: the scrollable-area safety trigger into ''safe'' mode when no <<overflow-position>> is specified
At Risk: the ''legacy'' keyword for 'justify-items'
At Risk: the effect of the <a>box alignment properties</a> on absolutely-positioned boxes with ''left/auto'' offsets
</pre>
<pre class=link-defaults>
spec:css2; type:property;
text:vertical-align
text:max-width
text:max-height
text:min-width
text:min-height
spec:css-cascade-3; type:value; text:initial
spec:css-display-3; type:property; text:display
spec:css-flexbox-1; type:dfn;
text:flex line
text:static-position rectangle
spec:css-fonts-3; type:dfn; text:first available font
spec:css-grid-1; type:dfn;
text:collapsed gutter
spec:css-inline-3; type:property;
text:dominant-baseline
text:alignment-baseline
spec:css-multicol-1; type:dfn;
text:multi-column container
text:column box
spec:css-overflow-3; type:dfn; text:scroll container
spec:css-position-3; type:property; text:left
spec:css-writing-modes-3; type:dfn;
text:dominant baseline
text:start
text:end
spec:selectors-3; type:dfn; text:first formatted line
spec:css2; type:dfn; text:line box
</pre>
<style>
.issue th:first-child { text-align: left !important; }
[rowspan] > img { float: right; }
[rowspan] { vertical-align: middle; }
table small { display: block; }
table.align-details { width: 100%; }
.align-details th {
font: inherit;
font-style: italic;
white-space: nowrap; width: 1em;
vertical-align: baseline; }
.align-details td { vertical-align: baseline; }
</style>
<h2 id="intro">
Introduction</h2>
CSS Levels 1 and 2 allowed for the alignment of text via 'text-align'
and the alignment of blocks by balancing ''margin/auto'' margins.
However, except in table cells,
vertical alignment was not possible.
As CSS adds further capabilities,
the ability to align boxes in various dimensions becomes more critical.
This module attempts to create a cohesive and common box alignment model to share among all of CSS.
Note: The alignment of text and inline-level content is defined in [[CSS-TEXT-3]] and [[CSS-INLINE-3]].
Note: This specification is not intended to change any of the behavior
defined in <a href="https://www.w3.org/TR/CSS2/">CSS2.1</a>
when the properties defined here are set to their initial values.
If implementors or anyone else notices a discrepancy,
please report this to the CSSWG as an error.
<em>This section (above) is not normative.</em>
<h3 id="placement">
Module Interactions</h3>
This module adds some new alignment capabilities
to the block layout model described in [[!CSS2]] <a href="https://www.w3.org/TR/CSS2/visuren.html">chapters 9</a>
and <a href="https://www.w3.org/TR/CSS2/visudet.html">10</a>,
<a href="#justify-block">redefines how overconstrained block-level box margins are resolved</a>,
and defines the interaction of these new alignment properties
with the alignment of table cell content using 'vertical-align',
as defined in [[!CSS2]] <a href="https://www.w3.org/TR/CSS2/tables.html#height-layout">chapter 17</a>.
The interaction of these properties with
Grid Layout [[!CSS-GRID-1]]
and Flexible Box Layout [[!CSS-FLEXBOX-1]]
is defined in their respective modules.
The property definitions here supersede those in [[!CSS-FLEXBOX-1]]
(which have a smaller, earlier subset of permissible values).
No properties in this module apply to the <code>::first-line</code>
or <code>::first-letter</code> pseudo-elements.
<h3 id="values">
Value Definitions</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values &amp; Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> as their property value.
For readability they have not been repeated explicitly.
<h3 id="partial">
Partial Implementations</h3>
Since it is expected that support for the features in this module
will be deployed in stages corresponding to the various layout models affected,
it is hereby clarified that
the <a href="https://www.w3.org/TR/CSS/#partial">rules for partial implementations</a>
that require treating as invalid any unsupported feature
apply to any alignment keyword
which is not supported across all layout modules to which it applies
for layout models in which the implementation supports the property in general.
For example,
if an implementation supports 'align-self' in [[CSS-GRID-1]] and [[CSS-FLEXBOX-1]],
then it must treat ''align-content/start'' as invalid
unless it is supported in both grid and flex containers.
However if that same implementation does not support 'align-self' for block-level elements at all,
then a lack of implementation of ''align-self: start''
does not trigger this requirement to treat it as invalid.
<h2 id="overview">
Overview of Alignment Properties</h2>
The <dfn export>box alignment properties</dfn> in CSS are a set of 6 properties
that control alignment of boxes within other boxes.
They can be described along two axises:
<ul>
<li>which dimension they apply to ([=main axis|main=]/[=inline axis|inline=] vs. [=cross axis|cross=]/[=block axis|block=]), and
<li>whether they control the position of the box within its parent, or the box's content within itself.
</ul>
Note: This specification uses the terms “justify” and “align” to distinguish
between alignment in the main/inline and cross/block dimensions, respectively.
The choice is somewhat arbitrary, but having the two terms allows for
a consistent naming scheme that works across all of CSS's layout models
(including [[css-flexbox-1#box-model]])
The following table summarizes the <a>box alignment properties</a>
and the display types they can apply to.
<table class=data>
<colgroup span=1></colgroup>
<colgroup span=2></colgroup>
<colgroup span=1></colgroup>
<thead>
<tr>
<th>Common
<th>Axis
<th>Aligns
<th>Applies to
<tbody>
<tr>
<th>'justify-content'
<td>main/inline
<td rowspan=2>
<img src="images/content-example.svg" width=106 height=106 alt="">
content within element
<small>(effectively adjusts padding)</small>
<td rowspan=2>[=block containers=], <a>flex containers</a>, and <a>grid containers</a>
<tr>
<th>'align-content'
<td>cross/block
<tbody>
<tr>
<th>'justify-self'
<td>inline
<td rowspan=2>
<img src="images/self-example.svg" width=106 height=106 alt="">
element within parent
<small>(effectively adjusts margins)</small>
<td>block-level boxes, absolutely-positioned boxes, and <a>grid items</a>
<tr>
<th>'align-self'
<td>cross/block
<td>absolutely-positioned boxes, <a>flex items</a>, and <a>grid items</a>
<tbody>
<tr>
<th>'justify-items'
<td>inline
<td rowspan=2>
<img src="images/items-example.svg" width=106 height=106 alt="">
items inside box
<small>(controls child items&rsquo; ''align/justify-self: auto'')</small>
<td>[=block containers=] and <a>grid containers</a>
<tr>
<th>'align-items'
<td>cross/block
<td><a>flex containers</a> and <a>grid containers</a>
</table>
Note: The '*-items' properties don't affect the element itself.
When set on a container,
they specify the interpretation of any ''*-self: auto'' used on children of the container element.
<h2 id='terms'>
Alignment Terminology</h2>
Since this module defines alignment properties for all layout modes in CSS,
some abstract terminology is introduced:
<dl>
<dt><dfn export>alignment subject</dfn>
<dd>
The <a>alignment subject</a> is the thing or things being aligned by the property.
For 'justify-self' and 'align-self',
the <a>alignment subject</a> is the margin box of the box the property is set on,
and assumes the <a>writing mode</a> of that box.
For 'justify-content' and 'align-content',
the <a>alignment subject</a> is defined by the layout mode
and refers to some aspect of its contents;
it also assumes the <a>writing mode</a> of the box the property is set on.
<dt><dfn export>alignment container</dfn>
<dd>
The <a>alignment container</a> is the rectangle that the <a>alignment subject</a> is aligned within.
This is defined by the layout mode,
but is usually the <a>alignment subject</a>’s containing block,
and assumes the [=writing mode=] of the box establishing the containing block.
<dt><dfn export>fallback alignment</dfn>
<dd>
Some alignments can only be fulfilled in certain situations
or are limited in how much space they can consume;
for example, ''space-between'' can only operate when there is more than one <a>alignment subject</a>,
and baseline alignment, once fulfilled, might not be enough to absorb all the excess space.
In these cases a fallback alignment takes effect
(as defined below)
to fully consume the excess space.
</dl>
<h2 id='alignment-values'>
Alignment Keywords</h2>
All of the alignment properties use a common set of keyword values,
which are defined in this section.
Keywords fall into three categories:
<dl>
<dt><a href="#positional-values">positional alignment</a>
<dd>These keywords define alignment as an absolute position within the <a>alignment container</a>.
<dt><a href="#baseline-values">baseline alignment</a>
<dd>These keywords define alignment as a relationship
among the baselines of multiple [=alignment subjects=] within an <a>alignment context</a>.
<dt><a href="#distribution-values">distributed alignment</a>
<dd>These keywords define alignment as a distribution of space among <a>alignment subjects</a>.
</dl>
<h3 id='positional-values'>
Positional Alignment: the ''center'', ''start'', ''end'', ''self-start'', ''self-end'', ''flex-start'', ''flex-end'', ''left'', and ''right'' keywords</h3>
The <dfn>positional alignment</dfn> keywords specify a position for an <a>alignment subject</a>
with respect to its <a>alignment container</a>.
Values have the following meanings:
<dl dfn-type="value">
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">center</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd>Centers the <a>alignment subject</a> within its <a>alignment container</a>.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">start</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s start edge in the appropriate axis.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">end</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the <a>alignment container</a>’s end edge in the appropriate axis.
<dt><dfn for="<self-position>, justify-self, align-self">self-start</dfn> <small>([[#self-alignment|self]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>alignment subject</a>’s start side in the appropriate axis.
<dt><dfn for="<self-position>, justify-self, align-self">self-end</dfn> <small>([[#self-alignment|self]])</small>
<dd>Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>alignment subject</a>’s end side in the appropriate axis.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">flex-start</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd><strong>Only used in flex layout.</strong> [[!CSS-FLEXBOX-1]]
Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>flex container</a>’s main-start or cross-start side, as appropriate.
When used outside of a <a>flex formatting context</a>, this value behaves as ''start''.
That is, on boxes that are not <a>flex items</a>
(or pretending to be <a>flex items</a>,
such as when determining the static position of an absolutely-positioned box
that is a child of a <a>flex container</a>),
this value behaves as ''start'' when used in the <a>self-alignment properties</a>,
and on boxes that are not <a>flex containers</a>,
this value behaves as ''start'' when used in the <a>content-distribution properties</a>.
<dt><dfn for="<self-position>, <content-position>, justify-self, align-self, justify-content, align-content">flex-end</dfn> <small>([[#self-alignment|self]], [[#content-distribution|content]])</small>
<dd><strong>Only used in flex layout.</strong>
Aligns the <a>alignment subject</a> to be flush with the edge of the <a>alignment container</a>
corresponding to the <a>flex container</a>’s main-end or cross-end side, as appropriate.
When used outside of a <a>flex formatting context</a>, this value behaves as ''end''.
That is, on boxes that are not <a>flex items</a>
(or pretending to be <a>flex items</a>,
such as when determining the static position of an absolutely-positioned box
that is a child of a <a>flex container</a>),
this value behaves as ''end'' when used in the <a>self-alignment properties</a>,
and on boxes that are not <a>flex containers</a>,
this value behaves as ''end'' when used in the <a>content-distribution properties</a>.
<dt><dfn for="justify-content, justify-self, justify-items">left</dfn> <small>(only 'justify-*')</small>
<dd>Aligns the <a>alignment subject</a> to be flush with
the <a>alignment container</a>’s <a href="https://www.w3.org/TR/css3-writing-modes/#line-left">line-left</a>
or <a>physical left</a> edge,
whichever is in the appropriate axis.
If the property's axis is not parallel with either left↔right axis,
this value behaves as ''start''.
<span class=note>Currently, the only case where the property's axis
is not parallel with either left↔right axis
is in a column flexbox.</span>
<dt><dfn for="justify-content, justify-self, justify-items">right</dfn> <small>(only 'justify-*')</small>
<dd>Aligns the <a>alignment subject</a> to be flush with
the <a>alignment container</a>’s <a href="https://www.w3.org/TR/css3-writing-modes/#line-right">line-right</a>
or <a>physical right</a> edge,
whichever is in the appropriate axis.
If the property's axis is not parallel with either left↔right axis,
this value behaves as ''start''.
<span class=note>Currently, the only case where the property's axis
is not parallel with either left↔right axis
is in a column flexbox.</span>
</dl>
Two grammar terms are used to denote certain subsets of these values:
<dl>
<dt><<self-position>>
<dd>
This set is used by 'justify-self' and 'align-self'
to align the box within its <a>alignment container</a>,
and also by 'justify-items' and 'align-items'
(to specify default values for 'justify-self' and 'align-self').
<pre class='prod'>
<dfn>&lt;self-position></dfn> = center | start | end | self-start | self-end |
flex-start | flex-end
</pre>
<dt><<content-position>>
<dd>
This set is used by 'justify-content' and 'align-content'
to align the box's contents within itself.
<pre class='prod'>
<dfn>&lt;content-position></dfn> = center | start | end | flex-start | flex-end
</pre>
</dl>
Note: ''left'' and ''right'' are excluded from <<self-position>> and <<content-position>>,
despite being valid [=positional alignment=] values for 'justify-content'/'justify-self'/'justify-items',
because they are not allowed in the 'align-*' properties.
They are instead explicitly included in the 'justify-*' properties’ grammars.
<aside class=example>
The ''<self-position>/start'' and ''<self-position>/end'' keywords
are <a>flow-relative</a>:
they use the <a>writing mode</a> to determine which side to align to.
<figure>
<img src="images/start-inline-tb.svg"
width="199" height="125"
style="background: white; padding: 8px;"
title="inline-axis 'start' alignment in various writing systems"
alt="Inline-axis 'start' alignment:
Horizontal Latin and Chinese are left-aligned,
while Arabic and Hebrew are right-aligned.">
<img src="images/end-inline-tb.svg"
width="199" height="125"
style="background: white; padding: 8px;"
title="inline-axis 'end' alignment in various writing systems"
alt="Inline-axis 'end' alignment:
Horizontal Latin and Chinese are right-aligned,
while Arabic and Hebrew are left-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>inline axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'justify-*')
</figcaption>
</figure>
The ''<self-position>/left'' and ''<self-position>/right'' keywords
are absolute (not <a>flow-relative</a>).
<figure>
<img src="images/left-inline-tb.svg"
width="175" height="125"
style="background: white; padding: 8px;"
title="'left' alignment in various writing systems"
alt="Inline-axis 'left' alignment:
Horizontal text is left-aligned, regardless of writing system.">
<img src="images/right-inline-tb.svg"
width="176" height="125"
style="background: white; padding: 8px;"
title="'right' alignment in various writing systems"
alt="Inline-axis 'right' alignment:
Horizontal text is right-aligned, regardless of writing system.">
<figcaption>
''<self-position>/left'' vs ''<self-position>/right''
</figcaption>
</figure>
The ''<self-position>/start'' and ''<self-position>/end'' keywords
have meaning in both the <a lt="inline axis">inline</a> and <a lt="block axis">block</a> axes:
''<self-position>/start'' always orients to the start of the text
(top left for left-to-right/top-to-bottom languages like English)
while ''<self-position>/end'' always orients to the end of the text.
<figure>
<img src="images/start-block-tb.svg"
width="183" height="125"
style="background: white; padding: 8px; padding-bottom: calc(8px + 23px);"
title="block-axis 'start' alignment in various writing systems"
alt="Block-axis 'start' alignment:
Horizontal text is top-aligned in the vertical axis.">
<img src="images/end-block-tb.svg"
width="183" height="125"
style="background: white; padding: 8px; padding-top: calc(8px + 23px);"
title="block-axis 'end' alignment in various writing systems"
alt="Block-axis 'bottom' alignment:
Horizontal text is bottom-aligned in the vertical axis.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>block axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'align-*')
</figcaption>
</figure>
The ''<self-position>/start'' and ''<self-position>/end'' keywords
use the <a>writing mode</a> of the <a>alignment container</a>,
to help keep things consistent.
But if alignment using the <a>alignment subject</a>’s <a>writing mode</a> is needed,
the ''<self-position>/self-start'' and ''<self-position>/self-end'' keywords can be used.
<figure>
<img src="images/self-v-context-start-tb.svg"
width="204" height="193"
style="background: white; padding: 8px;"
title="inline-axis 'start' alignment with LTR context"
alt="Inline-axis 'start' alignment in an LTR container:
Alignment uses the context’s start direction, so
the (RTL) Arabic and Hebrew items
are left-aligned alongside the (LTR) Latin and Chinese.">
<img src="images/self-v-context-self-start-tb.svg"
width="229" height="193"
style="background: white; padding: 8px;"
title="inline-axis 'self-start' alignment with LTR context"
alt="Inline-axis 'self-start' alignment in an LTR container:
Horizontal Latin and Chinese items are right-aligned,
while Arabic and Hebrew items are left-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/self-start'' on the individual items
</figcaption>
</figure>
</aside>
<aside class=example>
The behavior of the alignment keywords is analogous in <a>vertical writing modes</a>:
''<self-position>/start'' and ''<self-position>/end''
are relative to the start/end of the text in the relevant axis.
The ''<self-position>/left'' and ''<self-position>/right'' keywords
are interpreted as <a>line-left</a> and <a>line-right</a>,
relative to the “left” and “right” sides of LTR/RTL text.
<figure>
<img src="images/start-inline-rl.svg"
width="125" height="200"
style="background: white; padding: 8px;"
title="inline-axis 'start' alignment in various writing systems"
alt="Inline-axis 'start' alignment in vertical-rl writing:
Vertical Latin and Chinese are top-aligned,
while Arabic and Hebrew are bottom-aligned.">
<img src="images/end-inline-rl.svg"
width="125" height="200"
style="background: white; padding: 8px;"
title="inline-axis 'end' alignment in various writing systems"
alt="Inline-axis 'end' alignment in vertical-rl writing:
Vertical Latin and Chinese are top-aligned,
while Arabic and Hebrew are bottom-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>inline axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'justify-*')
</figcaption>
</figure>
<figure>
<img src="images/left-inline-rl.svg"
width="126" height="174"
style="background: white; padding: 8px; padding-bottom: calc(8px + 23px);"
title="'left' alignment in various writing systems"
alt="Inline-axis 'left' alignment in vertical-rl writing:
Vertical text is top-aligned, regardless of writing system.">
<img src="images/right-inline-rl.svg"
width="125" height="180"
style="background: white; padding: 8px; padding-top: calc(5px + 23px); padding-bottom: 5px;"
title="'right' alignment in various writing systems"
alt="Inline-axis 'right' alignment in vertical-rl writing:
Vertical text is bottom-aligned, regardless of writing system.">
<figcaption>
''<self-position>/left'' vs ''<self-position>/right''
</figcaption>
</figure>
<figure>
<img src="images/start-block-rl.svg"
width="123" height="183"
style="background: white; padding: 8px;"
title="block-axis 'start' alignment in various writing systems"
alt="Block-axis 'start' alignment in vertical-rl writing:
Vertical text is top-aligned in the vertical axis.">
<img src="images/end-block-rl.svg"
width="125" height="183"
style="background: white; padding: 8px;"
title="block-axis 'end' alignment in various writing systems"
alt="Block-axis 'bottom' alignment in vertical-rl writing:
Vertical text is bottom-aligned in the vertical axis.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/end'' in the <a>block axis</a>
(<a href="#flexbox-exception">typically<sup>†</sup></a> 'align-*')
</figcaption>
</figure>
<figure>
<img src="images/self-v-context-start-rl.svg"
width="162" height="210"
style="background: white; padding: 8px; padding-bottom: calc(8px + 30px);"
title="inline-axis 'start' alignment with LTR context"
alt="Inline-axis 'start' alignment in a vertical-rl LTR container:
Alignment uses the context’s start direction, so
the (RTL) Arabic and Hebrew items
are top-aligned alongside the (LTR) Latin and Chinese.">
<img src="images/self-v-context-self-start-rl.svg"
width="162" height="240"
style="background: white; padding: 8px;"
title="inline-axis 'self-start' alignment with LTR context"
alt="Inline-axis 'self-start' alignment in a vertical-rl LTR container:
Horizontal Latin and Chinese items are top-aligned,
while Arabic and Hebrew items are bottom-aligned.">
<figcaption>
''<self-position>/start'' vs ''<self-position>/self-start'' on the individual items
</figcaption>
</figure>
</aside>
<div class=note id=flexbox-exception>
For most layout models (block, table, grid, etc),
the 'justify-*' properties always align things in the <a>inline axis</a>,
while the 'align-*' properties always align things in the <a>block axis</a>.
Flexbox, on the other hand, has 'justify-*' align things in the <a>main axis</a>
and 'align-*' align things in the <a>cross axis</a>.
This depends on the value of 'flex-direction':
when 'flex-direction' is ''flex-direction/row'' or ''flex-direction/row-reverse'',
it matches the other layout modes
(<a>inline axis</a> with 'justify-*', <a>block axis</a> with 'align-*');
when 'flex-direction' is ''flex-direction/column'' or ''flex-direction/column-reverse'',
it has the opposite correspondence.
</div>
<p class='issue'>
Make it easier to understand the dual-axis nature of "start" and "end" wrt orthogonal flows.
<h3 id='baseline-values'>
Baseline Alignment: the ''baseline'' keyword and ''first''/''last'' modifiers</h3>
See [[css-writing-modes-3#intro-baselines]].
<dfn export>Baseline alignment</dfn> is a form of positional alignment
that aligns multiple <a>alignment subjects</a>
within a <a>shared alignment context</a>
(such as cells within a row)
by matching up their <a>alignment baselines</a>.
If the position of the <a>alignment subjects</a> within a <a>baseline-sharing group</a>
is not fully constrained by <a>baseline alignment</a>
(i.e., they could be shifted within their respective <a>alignment containers</a>
while maintaining baseline-alignment),
they are [=fallback alignment|fallback-aligned=] insofar as possible while preserving their <a>baseline alignment</a>.
The baseline alignment keywords are represented with the <<baseline-position>> grammar term:
<pre class='prod'>
<dfn>&lt;baseline-position></dfn> = [ first | last ]? && baseline
</pre>
The ''first'' and ''last'' values give a box a <dfn export>baseline alignment preference</dfn>:
either “first” or “last”, respectively,
defaulting to “first”.
Values have the following meanings:
<dl dfn-type=value dfn-for="justify-self, justify-items, align-content, align-self, align-items, <baseline-position>">
<dt><dfn>baseline</dfn>
<dd>
Computes to ''first baseline'', defined below.
<dt><dfn lt="first baseline | first">first baseline</dfn>
<dd>
Specifies participation in <dfn dfn for export>first-baseline alignment</dfn>:
aligns the <a>alignment baseline</a> of the box's <a>first baseline set</a>
with the corresponding baseline
of its [=baseline-sharing group=].
See [[#align-by-baseline]] for more details.
The <a>fallback alignment</a> for ''first baseline'' is
''safe self-start'' (for [=self-alignment=])
or ''safe start'' (for [=content-distribution=]).
<dt><dfn lt="last baseline | last">last baseline</dfn>
<dd>
Specifies participation in <dfn dfn for export>last-baseline alignment</dfn>:
aligns the <a>alignment baseline</a> of the box's <a>last baseline set</a>
with the corresponding baseline
of its [=baseline-sharing group=].̣
See [[#align-by-baseline]] for more details.
The <a>fallback alignment</a> for ''last baseline'' is
''safe self-end'' (for [=self-alignment=])
or ''safe end'' (for [=content-distribution=]).
</dl>
When specified for 'align-content',
these values trigger <a>baseline content-alignment</a>,
shifting the content of the box within its content box,
and may also affect the sizing of the box itself.
See [[#baseline-align-content]].
When specified for 'align-self'/'justify-self',
these values trigger <a>baseline self-alignment</a>,
shifting the entire box within its container,
which may affect the sizing of its container.
See [[#baseline-align-self]].
When [=baseline self-alignment=] is specified on a box,
[=content distribution=] is performed first,
then the resulting box and its contents
are [=baseline self-alignment|self-aligned=]
However, if the box also has [=baseline content-alignment=] in the same axis
or if its [=content-distribution property=] in the same axis is ''align-content/normal'',
its [=used value|used=] [=content-distribution property=] in that axis
is ''align-content/start'' or ''safe end''
for a [=baseline alignment preference=] of its [=baseline self-alignment=]
of “first” or “last”, respectively.
<p class='issue'>Add example images here.
If a box does not belong to a <a>shared alignment context</a>,
then the <a>fallback alignment</a> is used.
For example, ''align-content: baseline'' on a block box
falls back to ''align-content/start'' alignment.
The [=fallback alignment=] is also used to align the [=baseline-sharing group=]
within its [=alignment container=].
Note: Because they are equivalent, and ''baseline'' is shorter,
the CSSOM serializes ''first baseline'' as ''baseline''.
See [[cssom-1#serializing-css-values]].
Note: For the somewhat-related 'vertical-align' property,
due to inconsistent design decisions in CSS2.1,
''baseline'' is not equivalent to ''first baseline''
as an inline-level box’s <a>baseline alignment preference</a> depends on 'display'.
(E.g., ''inline-block'' uses its last baseline by default,
while ''inline-table'' uses its first baseline by default.)
<h3 id='distribution-values'>
Distributed Alignment: the ''<content-distribution>/stretch'', ''space-between'', ''space-around'', and ''space-evenly'' keywords</h3>
The <dfn export>distributed alignment</dfn> values are used by 'justify-content' and 'align-content'
to disperse a container’s extra space among its <a>alignment subjects</a>.
<figure>
<img src="images/distribute.svg" alt="space-between | space-around | space-evenly | stretch" width="504" height="218">
<figcaption>The <a>distributed alignment</a> values</figcaption>
</figure>
When space cannot be distributed in this way,
these values behave as their <a>fallback alignment</a>.
Each distribution value has an associated default <a>fallback alignment</a>.
(A future level of this module may allow the <a>fallback alignment</a> to be specified explicitly.)
<dl dfn-type="value" dfn-for="align-content, justify-content, <content-distribution>">
<dt><dfn>space-between</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>.
The first <a>alignment subject</a> is placed flush with the start edge of the <a>alignment container</a>,
the last <a>alignment subject</a> is placed flush with the end edge of the <a>alignment container</a>,
and the remaining <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a> is the same.
<figure>
<img src="images/space-between.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split in two and distributed: one half between the first two and one half between the last two items.">
</figure>
The default [=fallback alignment=] for this value is ''flex-start''.
<span class='note'>(For layout modes other than flex layout, ''flex-start'' is identical to ''start''.)</span>
<dt><dfn>space-around</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>,
with a half-size space on either end.
The <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a> is the same,
and the spacing before the first and after the last <a>alignment subject</a> is half the size of the other spacing.
<figure>
<img src="images/space-around.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split into sixths and distributed: one sixth at the start, one at the end, and two sixths (one third) each between the first two and between the last two items.">
</figure>
The default [=fallback alignment=] for this value is ''safe center''.
<dt><dfn>space-evenly</dfn>
<dd>
The <a>alignment subjects</a> are evenly distributed in the <a>alignment container</a>,
with a full-size space on either end.
The <a>alignment subjects</a> are distributed so that the spacing between any two adjacent <a>alignment subjects</a>,
before the first <a>alignment subject</a>,
and after the last <a>alignment subject</a>
is the same.
<figure>
<img src="images/space-evenly.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split into fourths and distributed: to the start, to the end, to between the first two, and to between the last two items.">
</figure>
The default [=fallback alignment=] for this value is ''safe center''.
<dt><dfn>stretch</dfn>
<dd>
If the combined size of the <a>alignment subjects</a> is less than the size of the <a>alignment container</a>,
any <css>auto</css>-sized <a>alignment subjects</a> have their size increased equally (not proportionally),
while still respecting the constraints imposed by 'max-height'/'max-width'
(or equivalent functionality),
so that the combined size exactly fills the <a>alignment container</a>.
<figure>
<img src="images/space-stretch.svg"
width="504" height="56"
alt="For example, given three items, all excess space is split into thirds and distributed: one third to each item.">
</figure>
The default [=fallback alignment=] for this value is ''flex-start''.
<span class='note'>(For layout modes other than flex layout, ''flex-start'' is identical to ''start''.)</span>
</dl>
These values are represented with the <<content-distribution>> grammar term:
<pre class='prod'><dfn>&lt;content-distribution></dfn> = space-between | space-around | space-evenly | stretch</pre>
<h3 id='overflow-values'>
Overflow Alignment: the ''safe'' and ''unsafe'' keywords and scroll safety limits</h3>
When the <a>alignment subject</a> is larger than the <a>alignment container</a>,
it will overflow.
Some alignment modes, if honored in this situation,
may cause data loss:
for example, if the contents of a sidebar are centered,
when they overflow they may send part of their boxes past the viewport's start edge,
which can't be scrolled to.
<div class='example'>
The figure below illustrates the difference in “safe” versus “unsafe” centering,
using a column flexbox as an example:
<figure>
<style>
.cross-auto-figure > div {
margin: 0 auto;
width: 70px;
background: #888;
padding: 0 .5em;
border-radius: 1em;
border: 1px solid transparent;
}
.cross-auto-figure > div > div {
border-spacing: 0;
display: table;
background: #ddd;
color: black;
text-align: center;
margin: .5em auto;
padding: .5em;
border-radius: .5em;
}
</style>
<div style="display:table; margin: 0 auto 1em;">
<div style="display:table-cell; padding-right: 50px;" class='cross-auto-figure'>
<div>
<div>About</div>
<div style="white-space: nowrap; margin-left: -31px;">Authoritarianism</div>
<div>Blog</div>
</div>
</div>
<div style="display:table-cell; padding-left: 50px;" class='cross-auto-figure'>
<div>
<div>About</div>
<div style="white-space: nowrap;">Authoritarianism</div>
<div>Blog</div>
</div>
</div>
</div>
<figcaption>
The items in the figure on the left are all strictly centered,
even if the one that is too long to fit overflows on both sides,
while those in the figure on the right are centered unless they overflow,
in which case all the overflow goes off the end edge.
If the container was placed
against the left edge of the page,
the “safe” behavior would be more desirable,
as the long item would be fully readable,
rather than clipped by the left edge of the screen.
In other circumstances,
the “unsafe” centering behavior might be better,
as it correctly centers all the items.
</figcaption>
</figure>
</div>
To control this situation,
an <dfn export>overflow alignment</dfn> mode can be explicitly specified.
“Unsafe” alignment honors the specified alignment mode in overflow situations, even if it causes data loss,
while “safe” alignment changes the alignment mode in overflow situations in an attempt to avoid data loss.
The default behavior is to contain the alignment subject within the scrollable area,
though at the time of writing this safety feature is not yet implemented.
<pre class='prod'><dfn>&lt;overflow-position></dfn> = unsafe | safe</pre>
<dl dfn-type="value" dfn-for="<overflow-position>">
<dt><dfn>safe</dfn>
<dd>
If the size of the <a>alignment subject</a> overflows the <a>alignment container</a>,
the <a>alignment subject</a> is instead aligned as if the alignment mode were ''start''.
<dt><dfn>unsafe</dfn>
<dd>
Regardless of the relative sizes of the <a>alignment subject</a> and <a>alignment container</a>,
the given alignment value is honored.
<dt>(no value specified)
<dd>
If the <a>overflow alignment</a> isn't explicitly specified,
the default <a>overflow alignment</a> is a blend of “safe” and “unsafe”
in that an overflowing <a>alignment subject</a> is allowed to overflow its <a>alignment container</a>,
but if this would cause it to also overflow
the <a>scrollable overflow area</a> of its nearest ancestor <a>scroll container</a>
(thus extending into the “unscrollable” region),
then its overflow in that direction is limited
by biasing any remaining overflow to the opposite side.
Issue: It may not be Web-compatible to implement the “smart” default behavior
(though we hope so, and believe it to be likely),
so UAs should pass any feedback on this point to the WG.
UAs that have not implemented the “smart” default behavior
must behave as ''unsafe''.
</dl>
<!--
██████ ███████ ██ ██ ████████ ████████ ██ ██ ████████
██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ███ ██ ██
██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ██ ██
█████████ ███████ ██ ██ ██ ██ ██ ██ ██ ██████ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ██
██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ███ ██
██████ ███████ ██ ██ ██ ████████ ██ ██ ██
-->
<h2 id='content-distribution'>
Content Distribution: Aligning a Box’s Contents Within Itself</h2>
<dfn export id="content-distribute" lt="content distribution | content-distribution">Content distribution</dfn> controls alignment of the box's content within its content box.
It is specified by the <dfn export>content-distribution properties</dfn> 'align-content' and 'justify-content'
(and their 'place-content' shorthand).
<div class="figure">
<img alt="Diagram showing that the alignment of the content within the element is affected." src="images/content-example.svg" width=212 height=212>
</div>
<h3 id='align-justify-content'>
The 'justify-content' and 'align-content' Properties</h3>
<pre class="propdef">
Name: align-content
Value: normal | <<baseline-position>> | <<content-distribution>> | <<overflow-position>>? <<content-position>>
Initial: normal
Applies to: block containers, multicol containers, flex containers, and grid containers
Inherited: no
Percentages: n/a
Computed value: specified keyword(s)
Animation type: discrete
</pre>
<pre class="propdef">
Name: justify-content
Value: normal | <<content-distribution>> | <<overflow-position>>? [ <<content-position>> | left | right ]
Initial: normal
Applies to: multicol containers, flex containers, and grid containers
Inherited: no
Percentages: n/a
Computed value: specified keyword(s)
Animation type: discrete
</pre>
Aligns the contents of the box as a whole (as the <a>alignment subject</a>)
within the box itself (as the <a>alignment container</a>):
along the inline/row/main axis of the box (for 'justify-content')
or the block/column/cross axis of the box (for 'align-content').
Values other than <dfn value for="justify-content, align-content">normal</dfn> are defined in [[#alignment-values]], above.
For all layout modes,
the <a>alignment subject</a> and <a>alignment container</a>
both assume the <a>writing mode</a> of the box the '*-content' property is set on.
### Block Containers (Including Table Cells)### {#distribution-block}
<table class="data align-details">
<tr>
<th><a>Alignment Container</a>
<td>
The <a>block container</a>’s content box.
<tr>
<th><a lt="alignment subject">Alignment Subject(s)</a>
<td>
The entire contents of the block, as a unit.
<tr>
<th>'align-content' Axis
<td>
The <a>block axis</a>.
If a <<content-distribution>> is specified
its <a>fallback alignment</a> is used instead.
<tr>
<th>'justify-content' Axis
<td>
Does not apply to and has no effect on <a>block containers</a>.
<tr>
<th>''align-content/normal'' Behavior
<td>
All values other than ''align-content/normal'' force the block container to [=establish an independent formatting context=].
For table cells, the behavior of ''align-content: normal'' depends on the computed value of 'vertical-align':
''vertical-align/top'' makes it behave as ''start'' and
''vertical-align/bottom'' makes it behave as ''end'';
otherwise ''vertical-align/middle'' makes it behave as ''center'',
and all other values make it behave as ''baseline''.
[[!CSS2]]
''align-content/normal'' otherwise behaves as ''start''.
</table>
### Multicol Containers ### {#distribution-multicol}
<table class="data align-details">
<tr>
<th><a>Alignment Container</a>
<td>
The <a>multi-column container</a>’s content box.
<tr>
<th><a lt="alignment subject">Alignment Subject(s)</a>
<td>
The column boxes,
with any spacing inserted between column boxes
added to the relevant column gaps.
<tr>
<th>'align-content' Axis
<td>
The <a>block axis</a>,
treating the column boxes
(and any column-spanning elements),
as a singular unit.
If a <<content-distribution>> is specified
its <a>fallback alignment</a> is used instead.
<tr>
<th>'justify-content' Axis
<td>
The <a>inline axis</a>.
<tr>
<th>''justify-content/normal'' Behavior