> provides an explicit fallback alignment.
Details per Layout Mode {#distribution-details}
-----------------------------------------------
### Block Containers ### {#distribution-block}
Alignment Container
|
The block container’s content box.
|
Alignment Subject(s)
|
The entire contents of the block, as a unit.
|
'align-content' Axis
|
The block axis.
If a <> is specified
the fallback alignment is used instead.
'justify-content' Axis
|
Does not apply to and has no effect on block containers.
|
''justify-content/normal'' Behavior
|
All values other than ''justify-content/normal'' force the block container to establish a new formatting context.
For table cells, the behavior of the ''justify-content/normal'' depends on the computed value of 'vertical-align':
''vertical-align/top'' makes it behave as ''start'',
''vertical-align/middle'' makes it behave as ''center'',
''vertical-align/bottom'' makes it behave as ''end'',
and all other values make it behave as ''baseline''.
''justify-content/normal'' otherwise behaves as ''start''.
| |
### Multicol Containers ### {#distribution-multicol}
### Flex Containers ### {#distribution-flex}
See [[!CSS-FLEXBOX-1]] for details.
### Grid Containers ### {#distribution-grid}
See [[!CSS-GRID-1]] for details.
Baseline Content-Alignment
The content of boxes participating in row-like layout contexts (shared alignment contexts)
can be baseline-aligned to each other.
This effectively increases the padding on the box
to align the alignment baseline of its contents
with that of other baseline-aligned boxes in its group.
The set of boxes that participate in baseline content-alignment
depends on the layout model:
- Table Cells:
-
A table cell participates in first (last) baseline content-alignment
in either its row or column (whichever matches its inline axis)
if its computed 'align-content' is ''baseline'' (''last-baseline'').
- Flex Items:
-
A flex item participates in first (last) baseline content-alignment
in its flex line if
its computed 'align-content' is ''baseline'' (''last-baseline''),
its inline axis is parallel to the main axis,
and its computed 'align-self' is ''align-self/stretch'' or ''self-start'' (''self-end'').
For this purpose,
the ''start'', ''end'', ''flex-start'', and ''flex-end'' values of 'align-self'
are treated as either ''self-start'' or ''self-end'',
whichever they end up equivalent to.
- Grid Items:
-
A grid item participates in first (last) baseline content-alignment
in either its row or column (whichever matches its inline axis)
if its computed 'align-content' is ''baseline'' (''last-baseline''),
and its computed 'align-self' or 'justify-self' (whichever affects its block axis)
is ''align-self/stretch'' or ''self-start'' (''self-end'').
For this purpose,
the ''start'', ''end'', ''flex-start'', and ''flex-end'' values of 'align-self'
are treated as either ''self-start'' or ''self-end'',
whichever they end up equivalent to.
If a box spans multiple shared alignment contexts,
it participates in first (last) baseline content-alignment
within its start-most (end-most) shared alignment context along that axis.
When a box participates in first (last) baseline content-alignment
it aligns its contents as follows:
its alignment subject (i.e. content)
is aligned to the start (end) edge of its alignment container (i.e. itself)
and the minimum necessary extra space is added between its start (end) content edge and its alignment subject’s edge
to align its alignment baseline in that axis with those of its baseline-sharing group.
See [[#align-by-baseline]].
This increases the intrinsic size of the box.
Note: In other words, a box participating in baseline content-alignment
acts like its 'padding' was increased
so that its alignment baseline lines up with the alignment baselines of its participating siblings.
The box itself is aligned as usual for its 'align-self'/'justify-self' value.
The content distribution properties also affect the initial scroll position,
setting it to display the appropriate portion of the scrollable area.
In other words,
the scrollable overflow region is aligned relative to the viewport
as specified by the content distribution property.
For example,
if a scrollable flex container is set to ''justify-content: flex-end''
(or ''justify-content: flex-start'' with ''flex-flow: row-reverse''),
it will be initially displayed scrolled all the way to the main-end edge of the scrollable area,
and its content will overflow its main-start edge.
Issue: This needs to be integrated with overflow-anchor, when the property exists,
so that you get the same behavior whether an elements *starts out* overflowing,
or is filled element-by-element.
Self-Alignment: Aligning the Box within its Parent
The 'justify-self' and 'align-self' properties control alignment of the box within its containing block.
Inline/Main-Axis Alignment: the 'justify-self' property
Name: justify-self
Value: auto | normal | stretch | <> | [ <>? && <> ]
Initial: auto
Applies to: block-level boxes, absolutely-positioned boxes, and grid items
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value, except for ''justify-self/auto'' (see prose)
Animatable: no
Justifies the box within its containing block along the inline/row/main axis:
the box's outer edges are aligned within its alignment container
as described by its alignment value.
The auto keyword computes to
the computed value of 'justify-items' on the parent
(minus any ''legacy'' keywords),
or ''justify-self/normal'' if the box has no parent.
The normal keyword
represents the “default” alignment for the layout mode.
Its behavior depends on the layout mode, as described below.
When the box’s computed 'width'/'height' (as appropriate to the axis) is ''width/auto''
and neither of its margins (in the appropriate axis) are ''margin/auto'',
the stretch keyword
sets the box’s used size to the length necessary to make its outer size
as close to filling the alignment container as possible
while still respecting the constraints imposed by 'min-height'/'min-width'/'max-height'/'max-width'.
Unless otherwise specified, this value falls back to ''flex-start''.
Issue: Should ''justify-self/stretch'' allow a fallback alignment,
like it does on 'align-content' and 'justify-content'?
Note: The ''justify-self/stretch'' keyword can cause elements to shrink,
to fit their container.
All other values are as defined in [[#alignment-values]], above.
Note: ''margin/auto'' margins,
because they effectively adjust the size of the margin area,
take precedence over 'justify-self'.
### Block-Level Boxes ### {#justify-block}
'justify-self' Axis
|
The block’s containing block’s inline axis.
|
Alignment Container
|
The block's containing block,
except that for block-level elements that establish a block formatting context
and are placed next to a float,
the alignment container is reduced by the space taken up by the float.
Issue: This is the legacy behavior of HTML align .
Do we want to still do this,
or should we do the centering behavior of margins,
which center while ignoring floats,
then shift if necessary to avoid overlapping?
|
Alignment Subject
|
The block's margin box.
|
''justify-self/normal'' Behavior
|
Behaves as ''justify-self/start''.
|
Other Details
|
In terms of CSS2.1 block-level formatting [[!CSS21]],
the rules for “over-constrained” computations in section 10.3.3
are ignored in favor of alignment as specified here
and the used value of the offset properties are not adjusted to correct for the over-constraint.
This property does not apply to floats.
|
The effect of these rules is that an auto-sized block-level table,
for example, can be aligned while still having side margins.
If the table's max-content size is narrower than its containing block,
then it is shrink-wrapped to that size and aligned as specified.
If the table's max-content size is wider, then it fills its containing block,
and the margins provide appropriate spacing from the containing block edges.
### Absolutely-Positioned Boxes ### {#justify-abspos}
'justify-self' Axis
|
The block’s containing block’s inline axis.
|
Alignment Container
|
The box's containing block,
as modified by the offset properties ('top'/'right'/'bottom'/'left').
|
Alignment Subject
|
The box's margin box.
|
''justify-self/normal'' Behavior
|
For consistency with CSS 2.1,
the ''justify-self/normal'' keyword behaves as ''start'' on replaced absolutely-positioned boxes,
and behaves as ''justify-self/stretch'' on all other absolutely-positioned boxes.
If the box has non-''top/auto'' offsets in this axis,
and either 'margin' in this axis is ''margin/auto'',
an ''width/auto'' 'width' ('height', for vertical writing modes) is treated as ''fill-available''
and ''margin/auto'' margins are treated as zero.
(Otherwise, when 'justify-content' is not ''justify-content/normal'',
''width: auto'' (''height: auto'') is treated as ''width/fit-content''
and ''margin/auto'' margins are used for alignment
as in in-flow block-level layout.)
|
Other Details
|
In terms of CSS2.1 formatting [[!CSS21]],
the rules for “over-constrained” computations in section 10.3.7
are ignored in favor of alignment as specified here,
and the used value of the offset properties are not adjusted to correct for the over-constraint.
Values other than ''justify-self/stretch'' cause non-replaced absolutely-positioned boxes
to use fit-content sizing for calculating ''width/auto'' inline sizes.
Note that ''justify-self/stretch'' does cause replaced absolutely-positioned elements to fill their containing block
just as non-replaced ones do.
If either offset property in this dimension is ''top/auto'',
'justify-self' has no effect.
|
### Static Position of Absolutely-Positioned Boxes ### {#justify-abspos-static}
'justify-self' Axis
|
The same axis that 'justify-self' corresponds to for in-flow children of the element's parent
|
Alignment Container
|
The element's static-position rectangle,
as defined by its parent's layout mode.
|
Alignment Subject
|
The element's margin box after laying out the element,
treated as fixed-size for the purpose of alignment.
|
''justify-self/normal'' Behavior
|
Behaves as (the fallback for) ''justify-self/stretch'' (because it is treated as fixed-size).
|
### Table Cells ### {#justify-cell}
This property does not apply to table cells,
because their position and size is fully constrained by table layout.
### Flex Items ### {#justify-flex}
This property does not apply to flex items,
because there is more than one item in the main axis.
See 'flex' for stretching and 'justify-content' for main-axis alignment. [[!CSS-FLEXBOX-1]]
### Grid Items ### {#justify-grid}
Block/Cross-Axis Alignment: the 'align-self' property
Name: align-self
Value: auto | normal | stretch | <> | [ <>? && <> ]
Initial: auto
Applies to: flex items, grid items, and absolutely-positioned boxes
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value, except for ''align-self/auto'' (see prose)
Animatable: no
Aligns the box within its containing block along the block/column/cross axis:
the box's outer edges are aligned within its alignment container
as described by its alignment value.
The auto keyword computes to
the computed value of 'align-items' on the parent
or ''align-self/normal'' if the box has no parent.
The normal keyword
represents the “default” alignment for the layout mode.
The ''align-self/stretch'' keyword is as defined in [[#justify-self-property]].
All other values are as defined in [[#alignment-values]], above.
Note: ''margin/auto'' margins,
because they effectively adjust the size of the margin area,
take precedence over 'justify-self'.
### Block-Level Boxes ### {#align-block}
The 'align-self' property does not apply to block-level boxes
(including floats),
because there is more than one item in the block axis.
### Absolutely-Positioned Boxes ### {#align-abspos}
'align-self' Axis
|
The block’s containing block’s block axis.
|
Alignment Container
|
The box's containing block.
|
Alignment Subject
|
The box’s margin box.
|
''align-self/normal'' Behavior
|
For consistency with CSS 2.1,
the ''align-self/normal'' keyword behaves as ''start'' on replaced absolutely-positioned boxes,
and behaves as ''align-self/stretch'' on all other absolutely-positioned boxes.
If the box has non-''top/auto'' offsets in this axis,
and either 'margin' in this axis is ''margin/auto'',
an ''width/auto'' 'height' ('width', for vertical writing modes)
is treated as ''fill-available''
and ''margin/auto'' margins are treated as zero.
(Otherwise, when 'align-content' is not ''align-content/normal'',
''height: auto'' (''width: auto'') is treated as ''height/fit-content''
and ''margin/auto'' margins are used for alignment
as in in-flow block-level layout.)
|
Other Details
|
In terms of CSS2.1 formatting [[!CSS21]],
the rules for "over-constrained" computations in section 10.6.4
are ignored in favor of alignment as specified here
and the used value of the offset properties are not adjusted to correct for the over-constraint.
Values other than ''align-self/stretch'' cause non-replaced absolutely-positioned boxes
to use shrink-to-fit sizing for calculating ''height/auto'' block sizes.
Note that ''justify-self/stretch'' does cause replaced absolutely-positioned elements to fill their containing block
just as non-replaced ones do.
If either offset property in this dimension is ''top/auto'',
'align-self' has no effect.
|
### Static Position of Absolutely-Positioned Boxes ### {#align-abspos-static}
'align-self' Axis
|
The same axis that 'align-self' corresponds to for in-flow children of the element's parent
|
Alignment Container
|
The element's static-position rectangle,
as defined by its parent's layout mode.
|
Alignment Subject
|
The element's margin box after laying out the element,
treated as fixed-size for the purpose of alignment.
|
''align-self/normal'' Behavior
|
Behaves as (the fallback for) ''align-self/stretch'' (because it is treated as fixed-size).
|
### Table Cells ### {#align-cell}
This property does not apply to table cells,
because their position and size is fully constrained by table layout.
### Flex Items ### {#align-flex}
See [[!CSS-FLEXBOX-1]] for details.
### Grid Items ### {#align-grid}
Baseline Self-Alignment
Boxes participating in row-like layout contexts (shared alignment contexts)
can be baseline-aligned to each other.
This effectively increases the margins on the box
to align its alignment baseline
with other baseline-aligned boxes in its group.
The set of boxes that participate in baseline self-alignment
depends on the layout model:
- Flex Items:
-
A flex item participates in first (last) baseline self-alignment in its flex line
if its inline axis is parallel to the main axis
and its computed 'align-self' is ''baseline'' (''last-baseline'').
See [[!CSS-FLEXBOX-1]] for details.
- Grid Items:
-
A grid item participates in first (last) baseline self-alignment
in either its row or column (whichever matches its inline axis)
if its 'justify-self' or 'align-self' property (whichever affects its block axis)
computes to ''baseline'' (''last-baseline'').
If a box spans multiple shared alignment contexts,
it participates in first (last) baseline self-alignment
within its start-most (end-most) shared alignment context along that axis.
When a box participates in first (last) baseline self-alignment,
it is aligned as follows:
the minimum necessary extra space is added between its start (end) edge and the alignment container edge
to match its alignment baseline in that axis up to that of its baseline-sharing group.
See [[#align-by-baseline]].
This may increase the intrinsic size contribution of the alignment subject.
Note: In other words, a box participating in baseline self-alignment
acts like its 'margin' was increased
so that its alignment baseline lines up with the alignment baselines of its participating siblings.
The box's contents are aligned as usual for its 'align-content'/'justify-content' value.
Default Alignment
The 'align-items' and 'justify-items' properties set the default 'align-self' and 'justify-self' behavior of the items contained by the element.
Inline/Main-Axis Alignment: the 'justify-items' property
Name: justify-items
Value: auto | normal | stretch | <> | [ <>? && <> ] | [ legacy && [ ''/left'' | ''/right'' | ''/center'' ] ]
Initial: auto
Applies to: block containers and grid containers
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value, except for ''justify-items/auto'' (see prose)
Animatable: no
This property specifies the default 'justify-self' for all of the boxes
(including anonymous boxes)
participating in this box's formatting context.
Values have the following meanings:
- auto
-
If the inherited value of ''justify-items'' includes the ''legacy'' keyword,
''justify-items/auto'' computes to the inherited value.
Otherwise, ''justify-items/auto'' computes to ''justify-items/normal''.
- legacy
-
This keyword causes the value to effectively inherit into descendants.
It can only be combined with the ''/center'', ''left'', and ''right'' positions.
When ''justify-self:auto'' retrieves the value of 'justify-items',
only the alignment keyword, not the ''legacy'' keyword, is passed to it.
It exists to implement the legacy alignment behavior of HTML's
<center>
element and align
attribute.
Other values have no special handling and are merely passed to 'justify-self'.
Issue: The ''justify-items/auto'' keyword exists solely to implement the ''legacy'' inheritance property.
We could just rename it to ''legacy'',
since it computes away to ''justify-items/normal'' unless you're using ''legacy'' anyway.
Issue: The ''legacy'' keyword acts weird,
to make it behave like an inherited value
even though this property is not inherited.
We don't mix inheritance and non-inheritance anywhere else,
because it's a bad code smell.
Should we remove ''legacy'' and make a separate inheriting property for it?
Or just drop the behavior entirely and let it remain special HTML magic?
Block/Cross-Axis Alignment: the 'align-items' property
Name: align-items
Value: normal | stretch | <> | [ <>? && <> ]
Initial: normal
Applies to: block-level elements
Inherited: no
Percentages: n/a
Media: visual
Computed value: specified value
Animatable: no
This property specifies the default 'align-self' for all of the boxes
(including anonymous boxes)
participating in this box's formatting context.
Values have the following meanings:
Values have no special handling and are merely passed to 'align-self'.
Baseline Alignment Details
Determining the Baselines of a Box
The first baseline set
(and last baseline set) of a box
for a given axis
are a set of baselines (alphabetic, central, etc.)
nominally associated with the first (last) line of text within the box.
The alignment baseline is one of these,
usually the dominant baseline of the alignment container.
(See 'alignment-baseline'.)
Note that boxes might not have baselines in a particular axis.
The first and last baseline sets of a box
are determined differently based on the layout model, as follows:
- block containers
-
The first (last) inline-axis baselines of a block container
are generated from the dominant first (last) baseline of the first (last) in-flow line box in the block container,
or are taken from the first (last) in-flow block-level child in the block container that contributes a set of first (last) baselines,
whichever comes first (last).
If there is no such line box or child,
then the block container has no baselines.
For the purposes of finding the baselines,
in-flow boxes with a scrolling mechanisms (see the 'overflow' property)
must be considered as if scrolled to their origin (final) position.
A block container has no block-axis baselines.
- tables
-
The first (last) inline-axis baselines of a table box are
the first (last) baselines of its first (last) row.
When finding the baselines of an inline-block,
any baselines contributed by table boxes must be skipped.
(This quirk is a legacy behavior from [[CSS21]].)
The first (last) block-axis baselines of a table box are the first (last) baselines of its first (last) column.
- table rows
-
If any cells in the row participate in ''baseline'' (''last-baseline'') alignment along the row axis,
the first (last) inline-axis baselines of the row
are generated from their shared alignment baseline
and the row's first available font,
after alignment has been performed.
Otherwise, the first (last) inline-axis baselines of the row
are synthesized from the lowest and highest content edges of the cells in the row.
[[!CSS21]]
A table row has no block-axis baselines.
- table columns
-
If any cells in the column participate in ''baseline'' (''last-baseline'') alignment
along the column axis (by having a writing mode perpendicular to that of the table),
the first (last) block-axis baselines of the column
are generated from their shared alignment baseline
and the column's first available font,
after alignment has been performed.
Otherwise, the first (last) inline-axis baselines of the row
are synthesized from the extreme content edges of the cells in the row.
[[!CSS21]]
A table column has no inline-axis baselines.
- flex containers
-
See Flex Baselines in [[!CSS-FLEXBOX-1]].
- grid containers
-
See Grid Baselines in [[!CSS-GRID-1]].
To generate baselines for a box from a single baseline,
use the baseline table from the font settings and first available font of that box,
and align that baseline set to the given single baseline.
To synthesize baselines from a rectangle (or two parallel lines),
synthesize the alphabetic baseline from the lower line,
and the central baseline by averaging the positions of the two edges or lines.
Note: The forthcoming Inline Layout Module will define synthesis rules for baselines other than alphabetic and central.
Maybe these things are wrong?
CSS 2.1 is really weird about baseline alignment.
Baseline Alignment Terminology
A baseline-sharing group
is composed of boxes that participate in baseline alignment together.
This is possible only if they
Boxes share an alignment context along a particular axis when they are:
- table cells in the same row, along the table's row (inline) axis
- table cells in the same column, along the table's column (block) axis
- grid items in the same row, along the grid's row (inline) axis
- grid items in the same column, along the grid's colum (block) axis
- flex items in the same flex line, along the flex container's main axis
Boxes in a baseline-sharing group are aligned to each other
using their alignment baseline.
This is the dominant baseline associated with
the box that generates their shared alignment context
on the first (last, for ''last-baseline'' alignment) formatted line.
For example, in horizontal writing modes,
specifying ''align-content: baseline'' on table cells in the same row
will align the alphabetic baselines of their first formatted lines.
Aligning Boxes by Baseline
Given a set of boxes and their baselines that all belong to a single baseline-sharing group,
the boxes are baseline-aligned as follows:
First, generate the alignment context's baseline table
from its first available font
and overlay also the mirror of this baseline table by aligning their central baselines.
These are the baseline grids to which the boxes will align.
Next, align all boxes by their specified alignment baseline
to the alignment context's baseline table
or its mirror, whichever matches its line orientation.
Unless otherwise specified (e.g. via the 'alignment-baseline' property),
the alignment baseline is the dominant baseline of the alignment context.
Position this aligned subtree within the alignment container
as specified by the relevant keyword (''baseline'' or ''last-baseline'').
Changes
Changes since the previous Working Draft include:
* Switched initial values to normal instead of auto.
* Renamed true to ''unsafe'' and made it the default in all layout modes.
* Fixed handling of ''justify-self: stretch'' (and 'align-self') to allow shrinking, as defined in Flexbox.
* Made justify/align-content:auto compute to their respective behaviors for flex and grid containers,
and fixed other computation / “behaves as” situations.
* Various bugfixes and editorial improvements.
Privacy and Security Considerations
As a simple layout spec,
this introduces no new privacy or security considerations.
Acknowledgments
Special thanks goes to Javier Fernandez, Markus Mielke, Alex Mogilevsky,
and the participants in the CSSWG's March 2008 F2F alignment discussions.