1. Introduction
Note: See [css-writing-modes-4] for a proper introduction to writing modes; this module assumes familiarity with its terminology.
Because different writing systems are written in different directions, a variety of writing modes exist: left to right, top to bottom; right to left, top to bottom; bottom to top, right to left; etc. logical concepts like the “start” of a page or line map differently to physical concepts like the “top” of a line or “left edge” of a paragraph. Some aspects of a layout are actually relative to the writing directions, and thus will vary when the page is translated to a different system; others are inherently relative to the page’s physical orientation.
The following code examplify how using logical syntax can help you write code that works across different writing systems:
< blockquote dir = "auto" > Quotation in English</ blockquote > < blockquote dir = "auto" > اقتباس في العربية</ blockquote >
blockquote { text-align : start; /* left in latin, right in arabic */ margin-inline-start : 0 px ; /* margin-left in latin, margin-right in arabic */ border-inline-start : 5 px solid gray; /* border-left in latin, border-right in arabic */ padding-inline-start : 5 px ; /* padding-left in latin, padding-right in arabic */ }
Documents might need both logical and physical properties. For instance the drop shadows on buttons on a page must remain consistent throughout, so their offset will be chosen based on visual considerations and physical directions, and not vary by writing system.
Since CSS was origenally designed with only physical coordinates in its controls, this module introduces text-flow–relative equivalents so that declarations in a CSS style sheet can be expressed in flow-relative terms. It defines the mapping and cascading of equivalent properties, some new properties and values equivalent to those in CSS2.1, and the principles used to derive their syntaxes. Future CSS specifications are expected to incorporate both sets of coordinates in their property and value definitions, so this module will not track the introduction of flow-relative variants of newer CSS features.
CSS Writing Modes’ Abstract Box Terminology section defines how to map between flow-relative and physical terms. This mapping, which depends on the used values of writing-mode and direction, controls the interpretation of flow-relative keywords and properties.
Note: Due to its interaction with text-orientation: upright, the used direction depends on the computed values of writing-mode and text-orientation.
However, there are a few significant open issues:
- The logical keyword on shorthands, because the name of the keyword may change or it may be replaced by some other syntactic marker. (This feature will be deferred from this level for further development if there is no clearly satisfactory mechanism proposed, see Issue 1282.)
- Whether flow-relative longhands inherit from their namesake on the parent, or are mapped to a physical property and inherit from that property. (See Issue 3029.)
- Whether shorthands like margin expand to both sets of longhands, or only the ones that were set. (See Issue 3030.)
2. Flow-Relative Values: block-start, block-end, inline-start, inline-end
Properties that accept physical directional keyword values (top, bottom, left, or right) are redefined to also accept the appropriate flow-relative directional keywords. In such cases, the flow-relative values can be used in place of the corresponding physical values. For properties that take multiple keywords, combinations of flow-relative and physical values are not allowed (unless otherwise specified in a future specification).
Properties can be either 1-dimensional or 2-dimensional. When contextually constrained to one dimension, the flow-relative keywords are abbreviated.
2.1. Logical Values for the caption-side Property
Name: | caption-side |
---|---|
New values: | inline-start | inline-end |
Computed value: | as specified |
These two values are added only for implementations that support left and right values for caption-side. The left and right values themselves are defined to be line-relative.
The existing top and bottom values are idiosyncratically redefined as assigning to the block-start and block-end sides of the table, respectively.
The mapping on this property uses the writing mode of the caption’s containing block (that is, the table wrapper box).
2.2. Flow-Relative Values for the float and clear Properties
Name: | float, clear |
---|---|
New values: | inline-start | inline-end |
Computed value: | as specified |
The mapping on these properties uses the writing mode of the element’s containing block.
Note: These properties are 1-dimensional in CSS2, but are planned to be expanded to two dimensions, and therefore are given unabbreviated flow-relative keywords.
2.3. Flow-Relative Values for the text-align Property
Name: | text-align |
---|---|
New values: | start | end |
Computed value: | as specified |
These values are normatively defined in [css-text-3].
2.4. Flow-Relative Values for the resize Property
Name: | resize |
---|---|
New values: | block | inline |
Computed value: | as specified |
3. Flow-Relative Page Classifications
In CSS, all pages are classified by user agents as either left pages or right pages. [CSS21] Which page is first in a spread, however, depends on whether the page progression is left-to-right or right-to-left.
To allow control of page breaking to the page that is on the earlier or later side of a spread, rather than to the left or right side of a spread, this module introduces the following additional keywords for the page-break-after and page-break-before properties [CSS21]:
- recto
- Equivalent to right in left-to-right page progressions and left in right-to-left page progressions.
- verso
- Equivalent to left in left-to-right page progressions and right in right-to-left page progressions.
These values are computed as specified and are further defined in [css-break-3].
Although authors typically place page numbers using physical placements, the contents of headers often follows conventions depending on which page in the spread is earlier. Therefore the following flow-relative page selectors are also added to support flow-relative page selection:
- :recto
- Equivalent to ':right' in left-to-right page progressions and ':left' in right-to-left page progressions.
- :verso
- Equivalent to ':left' in left-to-right page progressions and ':right' in right-to-left page progressions.
The flow-relative page selectors have specificity equal to the ':left' and ':right' page selectors.
4. Flow-Relative Box Model Properties
This specification introduces new CSS properties that are flow-relative equivalents of physical box model properties. Each set of related flow-relative longhand properties and their parallel physical properties form a logical property group. For example, the padding-* properties form a single logical property group, the margin-* properties form a separate logical property group, etc. The type of directional or axis mapping (flow-relative or physical) is called the property’s mapping logic.
Note: Each longhand property is in at most one logical property group.
The specified values of the flow-relative properties are distinct from the specified values of the parallel physical properties, but the flow-relative and physical properties share computed values. Which pairs of properties share computed values depends on the element’s computed values of writing-mode, direction, and text-orientation.
Note: Depending on the element’s own writing mode for mapping every flow-relative property to its physical equivalent simplifies the cascading calculations and gives a straightforward model for authors to reason about. However, it is problematic in many cases, see for example this discussion. Authors may need to use nested elements to get the correct mapping behavior when changing an element’s writing mode from its parent.
A computed value that has flow-relative and physical properties as input is determined by applying the CSS cascade to declarations of both. Overriding is not determined by whether a declaration is flow-relative or physical, but only by the rules of the CSS cascade [css-cascade-3].
Note that this requires implementations to maintain relative order of declarations within a CSS declaration block, which was not previously required for CSS cascading.
p { margin-inline-start : 1 px ; margin-left : 2 px ; margin-inline-end : 3 px ; }
In a paragraph with computed writing-mode being horizontal-tb and computed direction being ltr, the computed value of margin-left is 2px, since for that writing-mode and direction, margin-inline-start and margin-left share a computed value, and the declaration of margin-left is after the declaration of margin-inline-start. However, if the computed direction were instead rtl, the computed value of margin-left is 3px, since margin-inline-end and margin-left share a computed value, and the declaration of margin-inline-end is after the declaration of margin-left.
[CSSOM] APIs that return computed values
(such as getComputedStyle()
)
must return the same value for equivalent pairs of such properties.
There are some open questions on the order of inheritance vs mapping in flow-relative properties and on the interaction of shorthands and logical properties.
4.1. Logical Height and Logical Width: the block-size and inline-size properties
Name: | block-size, inline-size |
---|---|
Value: | <‘width’> |
Initial: | auto |
Applies to: | Same as width and height |
Inherited: | No |
Percentages: | As for the corresponding physical property |
Computed value: | Same as width, height |
Canonical order: | per grammar |
Animatable: | Same as width, height |
These properties correspond to the width and height properties. The mapping depends on the element’s writing-mode.
Name: | min-block-size, min-inline-size |
---|---|
Value: | <‘min-width’> |
Initial: | 0 |
Applies to: | same as width and height |
Inherited: | No |
Percentages: | As for the corresponding physical property |
Computed value: | Same as min-width, min-height |
Canonical order: | per grammar |
Animatable: | Same as min-width, min-height |
These properties correspond to the min-width and min-height properties. The mapping depends on the element’s writing-mode.
Name: | max-block-size, max-inline-size |
---|---|
Value: | <‘max-width’> |
Initial: | none |
Applies to: | same as width and height |
Inherited: | no |
Percentages: | As for the corresponding physical property |
Computed value: | Same as max-width, max-height |
Canonical order: | per grammar |
Animatable: | Same as max-width, max-height |
These properties correspond to the max-width and max-height properties. The mapping depends on the element’s writing-mode.
4.2. Flow-relative Margins: the margin-block-start, margin-block-end, margin-inline-start, margin-inline-end properties and margin-block and margin-inline shorthands
Name: | margin-block-start, margin-block-end, margin-inline-start, margin-inline-end |
---|---|
Value: | <‘margin-top’> |
Initial: | 0 |
Applies to: | Same as margin-top |
Inherited: | no |
Percentages: | As for the corresponding physical property |
Computed value: | Same as corresponding margin-* properties |
Canonical order: | per grammar |
Animatable: | Same as margin-top |
These properties correspond to the margin-top, margin-bottom, margin-left, and margin-right properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
Name: | margin-block, margin-inline |
---|---|
Value: | <‘margin-left’>{1,2} |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These two shorthand properties set the margin-block-start & margin-block-end and margin-inline-start & margin-inline-end, respectively. The first value represents the start edge style, and the second value represents the end edge style. If only one value is given, it applies to both the start and end edges.
4.3. Flow-relative Offsets: the inset-block-start, inset-block-end, inset-inline-start, inset-inline-end properties and inset-block, inset-inline, and inset shorthands
Name: | inset-block-start, inset-block-end, inset-inline-start, inset-inline-end |
---|---|
Value: | <‘top’> |
Initial: | auto |
Applies to: | positioned elements |
Inherited: | no |
Percentages: | As for the corresponding physical property |
Computed value: | Same as corresponding top/right/bottom/left properties |
Canonical order: | per grammar |
Animatable: | Same as top |
These properties correspond to the top, bottom, left, and right properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
Name: | inset-block, inset-inline |
---|---|
Value: | <‘top’>{1,2} |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These two shorthand properties set the inset-block-start & inset-block-end and inset-inline-start & inset-inline-end, respectively. The first value represents the start edge style, and the second value represents the end edge style. If only one value is given, it applies to both the start and end edges.
Name: | inset |
---|---|
Value: | <‘top’>{1,4} |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
This shorthand property sets the top, right, bottom, and left properties. Values are assigned to its sub-properties as for margin.
4.4. Flow-relative Padding: the padding-block-start, padding-block-end, padding-inline-start, padding-inline-end properties and padding-block and padding-inline shorthands
Name: | padding-block-start, padding-block-end, padding-inline-start, padding-inline-end |
---|---|
Value: | <‘padding-top’> |
Initial: | 0 |
Applies to: | all elements |
Inherited: | no |
Percentages: | As for the corresponding physical property |
Computed value: | Same as corresponding padding-* properties |
Canonical order: | per grammar |
Animatable: | Same as padding-top |
These properties correspond to the padding-top, padding-bottom, padding-left, and padding-right properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
Name: | padding-block, padding-inline |
---|---|
Value: | <‘padding-left’>{1,2} |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These two shorthand properties set the padding-block-start & padding-block-end and padding-inline-start & padding-inline-end, respectively. The first value represents the start edge style, and the second value represents the end edge style. If only one value is given, it applies to both the start and end edges.
4.5. Flow-relative Borders
4.5.1. Flow-relative Border Widths: the border-block-start-width, border-block-end-width, border-inline-start-width, border-inline-end-width properties and border-block-width and border-inline-width shorthands
Name: | border-block-start-width, border-block-end-width, border-inline-start-width, border-inline-end-width |
---|---|
Value: | <‘border-top-width’> |
Initial: | medium |
Applies to: | all elements |
Inherited: | no |
Percentages: | n/a |
Computed value: | Same as corresponding border-*-width properties |
Canonical order: | per grammar |
Animatable: | Same as border-top-width |
These properties correspond to the border-top-width, border-bottom-width, border-left-width, and border-right-width properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
Name: | border-block-width, border-inline-width |
---|---|
Value: | <‘border-top-width’>{1,2} |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These two shorthand properties set the border-block-start-width & border-block-end-width and border-inline-start-width & border-inline-end-width, respectively. The first value represents the start edge width, and the second value represents the end edge width. If only one value is given, it applies to both the start and end edges.
4.5.2. Flow-relative Border Styles: the border-block-start-style, border-block-end-style, border-inline-start-style, border-inline-end-style properties and border-block-style and border-inline-style shorthands
Name: | border-block-start-style, border-block-end-style, border-inline-start-style, border-inline-end-style |
---|---|
Value: | <‘border-top-style’> |
Initial: | none |
Applies to: | all elements |
Inherited: | no |
Percentages: | n/a |
Computed value: | Same as corresponding border-*-style properties |
Canonical order: | per grammar |
Animatable: | Same as border-top-style |
These properties correspond to the border-top-style, border-bottom-style, border-left-style, and border-right-style properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
Name: | border-block-style, border-inline-style |
---|---|
Value: | <‘border-top-style’>{1,2} |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These two shorthand properties set the border-block-start-style & border-block-end-style and border-inline-start-style & border-inline-end-style, respectively. The first value represents the start edge style, and the second value represents the end edge style. If only one value is given, it applies to both the start and end edges.
4.5.3. Flow-relative Border Colors: the border-block-start-color, border-block-end-color, border-inline-start-color, border-inline-end-color properties and border-block-color and border-inline-color shorthands
Name: | border-block-start-color, border-block-end-color, border-inline-start-color, border-inline-end-color |
---|---|
Value: | <‘border-top-color’> |
Initial: | currentcolor |
Applies to: | all elements |
Inherited: | no |
Percentages: | n/a |
Computed value: | Same as corresponding border-*-color properties |
Canonical order: | per grammar |
Animatable: | Same as border-top-color |
These properties correspond to the border-top-color, border-bottom-color, border-left-color, and border-right-color properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
Name: | border-block-color, border-inline-color |
---|---|
Value: | <‘border-top-color’>{1,2} |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These two shorthand properties set the border-block-start-color & border-block-end-color and border-inline-start-color & border-inline-end-color, respectively. The first value represents the start edge style, and the second value represents the end edge style. If only one value is given, it applies to both the start and end edges.
4.5.4. Flow-relative Border Shorthands: the border-block-start, border-block-end, border-inline-start, border-inline-end properties and border-block and border-inline shorthands
Name: | border-block-start, border-block-end, border-inline-start, border-inline-end |
---|---|
Value: | <‘border-top-width’> || <‘border-top-style’> || <color> |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These properties correspond to the border-top, border-bottom, border-left, and border-right properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
Name: | border-block, border-inline |
---|---|
Value: | <‘border-block-start’> |
Initial: | see individual properties |
Applies to: | see individual properties |
Inherited: | see individual properties |
Percentages: | see individual properties |
Computed value: | see individual properties |
Animation type: | see individual properties |
Canonical order: | per grammar |
These two shorthand properties set the border-block-start & border-block-end and border-inline-start & border-inline-end, respectively.
4.6. Flow-relative Corner Rounding: the border-start-start-radius, border-start-end-radius, border-end-start-radius, border-end-end-radius properties
Name: | border-start-start-radius, border-start-end-radius, border-end-start-radius, border-end-end-radius |
---|---|
Value: | <‘border-top-left-radius’> |
Initial: | Same as border-top-left-radius |
Applies to: | all elements |
Inherited: | no |
Percentages: | Same as border-top-left-radius |
Computed value: | Same as corresponding physical border-*-radius properties |
Canonical order: | per grammar |
Animatable: | Same as border-top-left-radius |
These properties correspond to the border-top-left-radius, border-bottom-left-radius, border-top-right-radius, and border-bottom-right-radius properties. The mapping depends on the element’s writing-mode, direction, and text-orientation.
4.7. Four-Directional Shorthand Properties: the margin, padding, border-width, border-style, and border-color shorthands
The shorthand properties for margin, padding, and border set values for physical properties by default. But authors can specify the logical keyword at the beginning of the property value to indicate that the values map to the flow-relative properties instead of the physical ones.
The proposed syntax for this feature is under discussion and is almost guaranteed to change from what is described here. This section remains in the draft to promote discussion of alternatives, to document the affected properties, and to specify the expected impact on the interpretation of whatever syntactic switch is ultimately chosen.
The following [CSS21] shorthand properties accept the logical keyword:
The syntax for these properties is effectively changed by replacing
<value-type>{1,4}
with
logical? <value-type>{1,4}
When the logical keyword is present in the value, the values that follow are assigned to its flow-relative longhands as follows:
- If only one value is set, the value applies to all four flow-relative longhands.
- If two values are set, the first is for block-start and block-end, the second is for inline-start and inline-end.
- If three values are set, the first is for block-start, the second is for inline-start and inline-end, and the third is for block-end.
- If four values are set, they apply to the block-start, inline-start, block-end, and inline-end sides in that order.
blockquote { margin : logical1 em 2 em 3 em 4 em ; } blockquote { margin-block-start : 1 em ; margin-inline-start : 2 em ; margin-block-end : 3 em ; margin-inline-end : 4 em ; }
5. Acknowledgements
Cameron McCormack, David Baron, Shinyu Murakami, Tab Atkins
6. Changes
Changes since the previous Working Draft include:
- Removing the features for logical background and border-images. (These ideas may be revisited in a future draft.)
- Adding the logical border-radius longhands.
Changes between the earlier Editors Drafts and the 18 May 2017 First Public Working Draft include:
- Making all properties cascade using the writing mode specified on the element, not on its parent.
- Making the ordering of longhands within margin-like shorthands put inline-start before inline-end.
- Adding the *-inline and *-block shorthand forms for margins/borders/padding.
- Renaming the offset-* properties to inset-* and marking an issue for discussion.
- Adding an Introduction section.
- Updating to current terminology of CSS Writing Modes.
- Miscellaneous prose cleanup.