TocTable of Contents
Css baseline 2021
Overview of 2021 baseline css features
All the features are Widely available because they all passed 36 months since being newly available.
fit-content
The fit-content keyword (and fit-content() function) sizes an element to fit its content, up to the available space in the container. It behaves like max-content — growing to wrap content without breaking — but is capped at the available width, after which it wraps like a normal block.
| |
In grid layout, fit-content() as a track sizing function accepts a clamp argument — the maximum size the track will grow to, even if the content is larger:
| |
This creates columns that size to their content up to the given maximum, then stop growing — the remaining space goes to the 1fr column.
As a width or height value, fit-content is equivalent to min(max-content, max(min-content, available)) — it takes as much space as the content needs, but never more than the available space, and never less than the minimum content size. This makes it useful for buttons, badges, tooltips, and any element that should hug its content without overflowing.
text-indent: each-line
The each-line keyword for text-indent applies the indentation not just to the first line, but to every line that follows a forced line break — giving you more control over indented text blocks.
By default, text-indent only affects the very first line of a block:
| |
Now every line that begins after a <br> or a forced break is also indented. Lines that wrap naturally (soft wraps) are not affected.
Both keywords can be used together — hanging reverses the indent direction (outdent the first line) while each-line applies it after forced breaks too.
Use cases:
- Poetry formatting where each verse line should be indented
- Legal or script formatting with explicit line breaks
- Custom typographic layouts
Ik ben de blauwbilgorgel,
Mijn vader was een porgel,
Mijn moeder was een porulan,
Daar komen vreemde kind'ren van.
Raban! Raban! Raban!
Ik ben een blauwbilgorgel
Ik lust alleen maar korgel,
Behalve als de nachtuil krijst,
Dan eet ik riep en rimmelrijst.
Rabijst! Rabijst! Rabijst!
Ik ben een blauwbilgorgel,
Als ik niet wok of worgel,
Dan lig ik languit in de zon
En knoester met mijn knezidon.
Rabon! Rabon! Rabon!
Ik ben een blauwbilgorgel
Eens sterf ik aan de schorgel,
En schrompel als een kriks ineen
En word een blauwe kiezelsteen.
Ga heen! Ga heen! Ga heen!
text-indent: hanging
The hanging keyword inverts the direction of text-indent — instead of indenting the first line, it indents every line except the first. This is also known as a hanging indent or outdent.
| |
Hanging indents are the standard format for bibliography entries:
A negative value combined with hanging creates a classic bibliography style where the first line starts at the left edge and subsequent lines are indented.
| |
Use cases:
- Bibliography and works-cited lists
- Dictionary or glossary entries
- Definition lists in custom typographic styles
:where()
:where() takes a selector list as its argument, and matches any element that can be selected by one of the selectors in that list, without increasing specificity.
| |
:where() works exactly like :is() — it matches elements that satisfy any selector in its list — but it always contributes zero specificity. This makes it perfect for default and base styles.
| |
With :where(), any user override with a simple h2 selector will win.
Like :is()
, :where() uses forgiving parsing — invalid selectors are silently ignored.
:not()
:not() matches every element that does not match the selector inside it. Since CSS Selectors Level 4, it accepts a full selector list, making exclusions much more expressive.
| |
:not() itself adds no specificity — but its argument does. :not(.active) adds class-level specificity (0,1,0).
:user-valid and :user-invalid
:user-valid and :user-invalid
Quotes
quotes The default value of quotes is auto. The browser provides language specific quotation marks when the <q> element is used.
| |
This is an English quote.
Dit is een Nederlandse quote.
This is a custom quote.
Tab size
tab-size defines the width of the tab character (\t) when it appears in rendered text. It only affects white-space: pre or white-space: pre-wrap contexts, like <pre> and <code> elements.
| |
The browser default is 8 spaces. Setting it to 2 or 4 better matches common code style guides.
Instead of a number (in space characters), you can use a length:
| |
Without tab-size, actual tab characters render as huge 8-space gaps. Setting tab-size: 4 makes code look as intended.
:is()
:is() accepts a list of selectors and matches any element that matches at least one of them. It is primarily a readability and maintenance tool.
| |
| |
Much cleaner with identical results.:is() takes the specificity of its most specific argument. So :is(#id, p) has ID-level specificity even when matching a <p>.
`:is()` uses forgiving parsing — an invalid selector in the list is ignored rather than invalidating the entire rule.
Flexbox Gap
The very useful gap from grid layout gap column-gap row-gap is now also available for flex containers as gap.
| |
File Selector Button
::file-selector-button selects the button part of a <input type="file>
| |
Font Family System
font-family: system-ui uses the operating system default font for text.
Just as this website does.
Logical Properties
Logical properties replace physical directions (top, left, right, bottom) with flow-relative equivalents (block-start, inline-end, etc.), making layouts that automatically adapt to different writing modes and text directions.
| Physical | Logical |
|---|---|
width / height | inline-size / block-size |
margin-top | margin-block-start |
padding-left | padding-inline-start |
border-right | border-inline-end |
top / left | inset-block-start / inset-inline-start |
Shorthand
| |
Aspect Ratio
aspect-ratio sets the aspect ratio of the element. When using width and height aspect-ratio is overruled.
| |
Counter style
Some examples
| |