Title: CSS Rhythmic Sizing Shortname: css-rhythm Level: 1 Group: CSSWG Status: ED Work Status: exploring Editor: Koji Ishii, Google, kojiishi@gmail.com, w3cid 45369 Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400 ED: https://drafts.csswg.org/css-rhythm/ TR: https://www.w3.org/TR/css-rhythm-1/ Abstract: This module contains CSS features for aligning content size to multiple of unit size.
spec:css21; type:property; text:max-height spec:css21; type:property; text:max-width spec:css21; type:property; text:min-width spec:css-writing-modes-4; type:dfn; text:end spec:css-writing-modes-4; type:dfn; text:start spec:css-break-3; type:dfn; text:fragmentIntroduction {#intro} ===================== This specification provides features to control sizes of CSS objects according to the rules desired by use cases. Controlling sizes of CSS objects to be multiple of a unit is desired in many cases. This level of the specification focuses on following cases. * Adjust heights of block-level boxes to multiples of the specified length. * Adjust heights of line boxes to multiples of the specified length. By stacking blocks at multiples, authors can align content across columns, pages, scroll-snapped bocks or multiple blocks placed absolutely to maintain vertical rhythm. Also by controlling heights of line boxes, lines of text in different fonts can create consistent visuals to help readability. East Asian Casual Vertical Rhythms {#eastasia} ---------------------------------------------- In East Asia, a casual variant of vertical rhythm is widely used. Vertical rhythm is typically used in professional typography. While it improves readability, its spacing constraints require careful and well-thought design of spaces. The East Asian casual variant was originally a product of technical constraints of traditional word processors in '80s. But when the technical constraints were lifted in more modern technologies, with the help of square-like visual of ideographic characters, East Asian authors preferred to keep parts of the characteristics. In this variant of vertical rhythm, the requirement is loosened for the ease of use for non-professional authors. Text is still on the rhythm, so that the majority of ideographic characters are mostly on grid, but when author specifies borders, margins, or some other objects that may break the rhythm, the rhythm is shifted rather than forced. The strict vertical rhythm often surprises non-professional authors by forced jumps in such cases, while this variant combines rhythm on text and the ease of use for non-professional authors. This variant was very widely accepted in East Asia since the middle of '90s, such that most major word processors used in East Asia provided similar features by default. In East Asian publishing typography, the vertical rhythm is one of important properties, but its priority compared to other properties varies by types of documents. In single column documents, the priority is weaker than that of multi-column documents. Text should be on the vertical rhythm, but it is often preferred for borders, margins, or other properties to win over the rhythm. In such cases, the rhythm is shifted, similar to the casual variant. In this specification, when the 'line-height-step' property is used without combination of the 'block-step' property or the 'line-grid' property, it produces the similar effect as the East Asian casual vertical rhythm. It may also serve good for East Asian publishing typography, depends on the desired strength of the vertical rhythm. For other cases of vertical rhythm, it is expected that the 'block-step' property or the 'line-grid' property are used, or that the 'line-height-step' property is used together with them. Adjusting Block-level Box Heights {#block-height} ================================= The most common typographic rhythm problems are block-level intrusions: when continuous paragraph-level text is interrupted by differently-sized content such as illustrations and headings, then the line-to-line rhythm can be thrown off. The block step properties allow such elements to be fitted to the rhythmic interval by constraining their height to a multiple of a specified step size. This allows content before and after the interruption to maintain a continuous rhythm.
Name: block-step-size Value: none | <This property defines the step unit for a block-level box’s block size. When the step unit is set to a positive <> Initial: none Applies to: block-level boxes Inherited: no Animatable: ??? Percentages: N/A Media: visual Computed Value: keyword or absolute length
Name: block-step-insert Value: margin | padding Initial: margin Applies to: block-level boxes Inherited: no Animatable: no Percentages: N/A Media: visual Computed Value: as specifiedThis property specifies whether extra spacing derived from applying 'block-step-size' is inserted inside (like 'padding') or outside (like 'margin') the box’s border. Values have the following meanings:
Name: block-step-align Value: auto | center | start | end Initial: auto Applies to: block-level boxes Inherited: no Animatable: no Percentages: N/A Media: visual Computed Value: as specifiedThis property specifies whether extra spacing derived from applying 'block-step-size' is inserted before, inserted after, or split between both sides of the box. Values have the following meanings:
Name: block-step-round Value: up | down | nearest Initial: up Applies to: block-level boxes Inherited: no Animatable: no Percentages: N/A Media: visual Computed Value: as specifiedThis property specifies whether adjustments due to 'block-step-size' insert positive or negative space. Values have the following meanings:
Name: block-step Value: <'block-step-size'> || <'block-step-insert'> || <'block-step-align'> || <'block-step-round'> Initial: See individual properties Applies to: block-level boxes Inherited: no Animatable: See individual properties Percentages: N/A Media: visual Computed Value: See individual propertiesThis shorthand property allows for setting 'block-step-size', 'block-step-insert', 'block-step-align', and 'block-step-round' in one declaration. Omitted values are set to the property’s initial value. Advisement: Authors are advised to use this shorthand rather than the longhands unless there is a specific need for its individual longhands to cascade independently. Adjusting Line Box Heights: the 'line-height-step' property {#line-height-step} ===============================================================================
Name: line-height-step Value: <This property defines the step unit for line box heights. A step unit is the length of the vertical rhythm, usually the distance from one baseline to the next baseline of the body text. Body text should fit into one step unit, and taller lines such as headings should have heights of two or more step units. Vertical rhythm is created by making heights of all lines an integer multiple of the step unit. When the step unit is set to a positive <> Initial: 0 Applies to: block containers Inherited: yes Animatable: no Percentages: N/A Media: visual Computed Value: the absolute length
Rounding up the computed line box height.
:root {
font-size: 12pt;
--my-grid: 18pt;
line-height-step: var(--my-grid);
}
h1 {
font-size: 20pt;
margin-top: calc(2 * var(--my-grid));
}
p {
margin: 0;
}
The line box in <h1> does not fit into one step unit
and thus occupies two,
but it is still centered within the two step unit.
$gu: 18px;
@function gu($n) {
@return $n * $gu;
}
h1 {
font-size: 20pt;
margin: gu(1.2) auto gu(1.8);
}