TocTable of Contents
Css baseline 2022
Overview of 2022 baseline css features
3D transforms
CSS 3D transforms extend the 2D transform system into the third dimension, allowing elements to be rotated, translated, and scaled along the z-axis. The parent element must establish a 3D rendering context using transform-style: preserve-3d for children to occupy genuine 3D space relative to each other.
| |
The key 3D transform functions are rotateX(), rotateY(), rotateZ(), rotate3d(), translateZ(), translate3d(), scaleZ(), scale3d(), and perspective(). translateZ() moves an element toward or away from the viewer — positive values bring it closer, negative values push it further away.
perspective on a parent element sets the vanishing point depth for all 3D-transformed children. A lower value produces a more dramatic perspective effect; a higher value is subtler. perspective-origin controls the position of the vanishing point, defaulting to the centre of the element.
backface-visibility: hidden prevents the back face of a transformed element from showing through when it is rotated more than 90 degrees away from the viewer — essential for card-flip effects.
Cascade Layers
Cascade layers give you explicit control over the order in which groups of styles are evaluated in the cascade, independently of specificity. Declared with the @layer at-rule, each layer sits in a defined position in the cascade stack, and styles in a higher layer always win over styles in a lower layer — regardless of selector specificity.
| |
Declaring the layer order upfront with @layer base, components, utilities; establishes the stack before any rules are added, making the intended priority explicit. Styles in utilities will always override those in components, which will always override base — regardless of which selectors are used inside each layer.
Styles declared outside any layer sit above all layers in the cascade, which means unlayered styles take highest priority. This is important when integrating third-party stylesheets: wrapping them in a layer pushes them below your own unlayered styles, preventing specificity conflicts.
| |
Layers can also be nested:
| |
Nested layers are referenced with dot notation: components.forms. This allows large codebases to organise styles hierarchically without losing control over cascade order.
Cascade layers are a fundamental tool for managing style architecture at scale, reducing the specificity arms race that commonly arises in large projects and making it practical to integrate external styles without !important overrides.
contain
The contain property allows you to indicate that an element and its subtree are independent from the rest of the document, enabling the browser to limit the scope of layout, style, and paint recalculations to that subtree. This can significantly improve rendering performance in complex pages.
| |
The individual containment types can be combined or applied through shorthand keywords:
layout containment isolates the element from the outside layout — changes inside cannot affect elements outside, and vice versa. style containment limits the scope of CSS counters and quotes. paint containment ensures the element’s contents do not visually overflow its box. size containment means the element’s size does not depend on its children.
strict enables all four types simultaneously. content enables layout, style, and paint — the most commonly useful combination, without size containment which requires an explicit size to be set.
| |
Containment is also the foundation that container queries build on — container-type: inline-size implicitly applies layout and style containment to enable querying. content-visibility: auto uses containment internally to skip rendering off-screen elements.
font-synthesis
The font-synthesis property controls whether the browser is allowed to synthesise bold, italic, small-caps, and subscript/superscript font faces when the requested variant is not available in the font family. Synthesis produces an approximation by algorithmically transforming the regular face — thickening strokes for bold, slanting characters for italic — which is generally considered lower quality than a true designed variant.
| |
The font-synthesis shorthand accepts a space-separated list of the synthesis types to permit: weight (bold), style (italic/oblique), small-caps, and position (sub/super). Setting font-synthesis: none disables all synthesis; listing specific keywords enables only those.
Disabling synthesis is particularly important when a font family includes only a regular face — if bold is applied without synthesis, the text simply renders at normal weight rather than a fake-bold approximation. This is often preferable for display typefaces where the synthesised result is visually poor.
Individual longhands — font-synthesis-weight, font-synthesis-style, font-synthesis-small-caps, and font-synthesis-position — each accept auto (allow synthesis) or none (disallow it).
Layout containment
Layout containment, established with contain: layout, isolates the layout of an element’s subtree from the rest of the page. The browser can skip recalculating layout for the contained subtree when changes occur outside it, and vice versa — changes inside cannot trigger layout recalculations outside the boundary.
| |
Layout containment establishes several formatting context boundaries automatically: the element becomes a block formatting context (similar to overflow: hidden), a new stacking context, and a new absolute positioning containing block. This means:
- Floats inside the element cannot affect content outside it
- Margins do not collapse across the containment boundary
- Absolutely positioned children are contained within the element rather than escaping to a positioned ancestor
| |
Layout containment is particularly valuable for components that are rendered many times on a page — such as cards, list items, or table rows. When one card’s content changes, the browser only needs to recalculate layout within that card’s containment boundary, rather than the entire page.
It is one of the containment types included in both contain: content and contain: strict.
Paint containment
Paint containment, established with contain: paint, ensures that an element’s descendants do not paint outside its border box. The browser can skip painting the subtree entirely when it is off-screen, and can optimise repaints so that only the contained element’s area is repainted when its content changes.
| |
Paint containment has a similar visual effect to overflow: hidden — content that would overflow the element’s box is clipped — but it also provides the performance benefit of containing the paint area. When a card’s content changes, the browser only repaints the pixels within that card’s box rather than potentially invalidating a larger region of the page.
Like layout containment, paint containment establishes a new stacking context and block formatting context, and acts as an absolute positioning containing block for descendants.
| |
Paint containment is included in contain: content and contain: strict. It is particularly effective for elements containing animations or frequently changing content, as it limits how much of the page the browser needs to repaint. Combined with layout containment, it forms the content shorthand — the most commonly useful containment combination.
resolution media query
The resolution media feature queries the pixel density of the output device, allowing different styles or assets to be served to standard and high-resolution displays. It accepts values in dppx (dots per pixel), dpi (dots per inch), or dpcm (dots per centimetre).
| |
1dppx corresponds to a standard display where one CSS pixel equals one physical pixel. 2dppx matches retina and HiDPI screens where two physical pixels render each CSS pixel, producing sharper images. The dpi unit can also be used — 96dpi is equivalent to 1dppx and 192dpi to 2dppx.
The modern range syntax makes the queries readable: (resolution >= 2dppx) is cleaner than the older (min-resolution: 2dppx). Both forms are supported.
For most modern use cases, serving vector SVG assets eliminates the need for resolution queries entirely — SVGs scale perfectly at any pixel density. Resolution queries remain relevant for raster images (PNG, JPEG, WebP) where separate files at different resolutions are needed for optimal sharpness.
Size containment
Size containment, established with contain: size, means that the element’s size is not influenced by its children. The browser can calculate the element’s size without looking at its content, which allows layout calculations to be skipped for the subtree when sizing the element.
| |
Without an explicit size set, size containment causes the element to collapse to zero in both dimensions — because if the element’s size cannot depend on its children, and no size is specified, there is nothing to size it to. This makes size containment almost always require an explicit width and height (or block-size and inline-size) to be useful.
Size containment can be applied to just one axis with contain: inline-size (the inline axis only) or contain: block-size (the block axis only), giving finer control:
| |
Size containment is included in contain: strict but not contain: content, as it requires an explicit size which is not always desirable. It is the containment type implicitly applied by container-type: inline-size when setting up container queries, which is its most common real-world application.
Style containment
Style containment, established with contain: style, limits the scope of CSS properties that can affect elements outside a containment boundary. Specifically, it scopes CSS counters and quotes properties so that counter values and quote nesting levels do not bleed out of the contained subtree into the rest of the document.
| |
Without style containment, CSS counters on one component can accidentally affect counter values in sibling components if they share the same counter name. Style containment prevents this by treating each contained element as a new scope for counter inheritance and the open-quote/close-quote nesting level.
Style containment does not affect most CSS properties — it does not isolate layout, painting, or size. It is narrowly focused on the two areas (counters and quotes) where CSS can have unintentional global side effects from within a component.
In practice, style containment is most often applied as part of contain: content or contain: strict rather than on its own, since the broader containment types that include it also bring more significant performance benefits.
text-align-last
The text-align-last property controls the alignment of the last line of a block of text, or of a line that ends with a forced line break. It is particularly useful when text-align: justify is set, since justification does not apply to the last line by default — that line is left-aligned and can appear awkwardly short in some layouts.
| |
The accepted values are the same as text-align: auto, left, right, center, start, end, and justify. The default auto applies the same alignment as text-align to the last line, which for justified text means the last line inherits the fallback alignment (typically left).
text-align-last applies to each line that immediately precedes a forced break — including lines before <br> elements — not just the very last line of the whole block. In practice it is most commonly used in combination with text-align: justify for typographic control over fully-justified text blocks.
text-combine-upright
The text-combine-upright property compresses a sequence of characters into the space of a single character, rotating them upright within a vertical text run. This is used for the typographic feature known as “tate-chuu-yoko” in Japanese — the insertion of horizontal numerals or abbreviations within vertical text so they read naturally without breaking the vertical flow.
| |
| |
Without text-combine-upright, numbers in vertical Japanese text would either be rotated sideways or stack vertically one digit at a time. With it, short sequences of characters (typically two to four digits) are fitted into a single em square, reading horizontally while the surrounding text flows vertically.
The all value compresses all characters in the element. The digits value (with an optional integer for the maximum number of digits) compresses only numeric digit sequences of up to that many digits — for example, text-combine-upright: digits 2 compresses sequences of one or two digits.
This property has no visual effect in horizontal writing modes — it only applies when the element is in a vertical text context established by writing-mode.
HWB
hwb() expresses colors as a hue angle plus amounts of white and black mixed in. Many designers find it more intuitive than HSL for creating tints and shades.
| |
200— hue angle (same as in HSL, 0–360)20%— whiteness (how much white is mixed in)10%— blackness (how much black is mixed in)
Creating tints and shades:
| |
HSL uses saturation and lightness, which interact in less obvious ways. HWB’s whiteness and blackness are independent additive values that feel more like mixing paint.
With Alpha:
| |
::backdrop
The ::backdrop pseudo-element is a box the size of the viewport, which is rendered immediately beneath any element being presented in the top layer,
like a dialog or popover.
Popover heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
| |
Grid Animation
This allows the animation of rows and columns in a grid layout.
Use grid-template-rows to animate from 0 to auto and in combination with a details summary it is possible to show and hide content without javascript.
Click to see...
| |
Focus visible
The :focus-visible pseudo-class in CSS applies styles to an element when it is focused, but only if the user needs to see a focus indicator, such as when using a keyboard.
| |
Overflow Clip
overflow: clip clips overflowing content at the element’s edge but, unlike overflow: hidden, it does not create a new block formatting context or a scroll container.
| |
This matters because overflow: hidden can trap position: sticky children, while overflow: clip does not.
You can clip only horizontally or only vertically:
| |
This is impossible with hidden — setting one axis to hidden forces the other to auto.
Use Cases
- Clipping decorative background elements that bleed out
- Preventing horizontal scroll without breaking sticky headers
- Isolating overflow in card components cleanly
Prefers-contrast media query
prefers-contrast: takes the a11y contrast user settings in account. Various operating systems support such preferences.
| |
Dynamic-range Media Query
The dynamic-range media feature lets your CSS detect whether the user’s screen supports standard or high dynamic range, enabling you to tailor colors and contrast for HDR displays.
| |
HDR users get a wide-gamut display-p3 color; standard users get a regular sRGB color.
standard— a typical display with standard dynamic rangehigh— a display with HDR and wide color gamut (OLED or HDR monitors)
| |
- Richer hero images and color palettes on HDR screens
- Enhanced gradients that exceed sRGB gamut
- Logo colors that pop on capable displays
Appearance
Appearance is mostly used to remove vendor styling from form controls, like:
| |
CSS Motion Path
CSS Motion Path — primarily the offset-path property — allows you to move elements along a defined geometric path using CSS animations. No JavaScript required.
| |
The element travels from 0% to 100% along the SVG path curve.
Path Types
path()— SVG path data stringray()— a straight line at a given anglecircle(),ellipse(),polygon()— CSS shape functions
Auto Rotation
| |
offset-rotate: auto makes the element face its direction of travel automatically.
Individual transform properties
The translate, rotate, and scale CSS properties apply single transformations independently, as opposed to applying multiple transformations with the transform CSS property.
What does that mean?
In supporting browsers you can use translate, scale and rotate without transform: they’re their own properties now.
| |
Viewport Unit Variants
These units are relative to the smallest, largest, and current (dynamic) viewport size.
dvh is dynamic viewport height
dvw is dynamic viewport width
svh is smallest viewport height
svw is smallest viewport width
lvh is largest viewport height
lvw is largest viewport width
A good use case for dvh is fullscreen sheets on mobile for menu’s or shopping carts
| |