Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

WebKit 5 min read How-to mediumAdept

Try out CSS Nesting today

CSS Nesting, using the community-chosen Option 3 syntax, shipped on by default in Safari Technology Preview 162 and is behind a flag in Chrome Dev. It works much like Sass nesting, but in this version a nested selector must begin with a symbol: a bare element selector like `article` is silently ignored, which you avoid by prefixing `&` or wrapping it in `:is()`. The `&` also places the parent selector explicitly, as in `.component &` or `&:hover` without a descendant space. A later note says Safari Technology Preview 179+ dropped the symbol requirement.

Assumes: CSS selectorsSass nesting

Related posts

  • CSS Nesting and the Cascade

    WebKit mediumAdept

    CSS Nesting now supports relaxed parsing, so nested selectors no longer need to start with a symbol: `h1 { }` inside `article { }` just works. Firefox 117 and Safari Technology Preview 179 ship it, and Chrome's update is in progress. The `&` still marks where the parent selector goes, as in `article &`. An open question remains about declarations that follow a nested `@supports` block. The current spec, matching Sass, Less and other preprocessors, hoists them so the earlier rule wins, while a developer survey favored preserving source order (62% vs 38%).

  • Help choose the syntax for CSS Nesting

    WebKit mediumAdept

    The CSS Working Group is choosing between three candidate syntaxes for native CSS nesting, since Sass-style nesting is impossible: browser parsers would read a nested selector like `element:pseudo` as a `property: value` declaration. Option 3 lets nested rules sit directly in the declaration block but forbids them from starting with a letter, so element selectors need `&` or an `:is()` wrapper. Option 4 adds an optional second block after the declarations that holds only nested rules. Option 5 introduces a dedicated `@nest` at-rule. Side-by-side examples cover basics, nested nesting, media queries and cascade layers, and developers are asked to vote in a survey.

  • WebKit Features in Safari 16.5

    WebKit easyNovice

    Safari 16.5 is mainly a polish and bug-fix release that adds CSS Nesting, the :user-valid and :user-invalid pseudo-classes, Apple Pay support for pre-orders and deferred payments, and disabling of the WebCodecs API in Lockdown Mode. Nesting still requires nested element selectors to start with a symbol such as &, a limitation the CSS Working Group hopes to remove. The new form pseudo-classes wait for user interaction before flagging input as invalid, which removes the need for JavaScript workarounds, and they pair well with :has(). Dozens of fixes cover CSS margin-trim, scroll snapping, media playback, WASM SIMD and Web Inspector.

  • Using :has() as a CSS Parent Selector and much more

    WebKit mediumAdept

    The CSS `:has()` pseudo-class, long requested as a "parent selector", lets developers style an element based on its descendants, its following siblings, or the state of elements anywhere in the DOM. WebKit shipped it in Safari 15.4 using new `:has`-specific caching and filtering optimizations. Chrome 105 ships Igalia's implementation, and Firefox is in progress. Hands-on examples cover styling figures and grid cards by their content, the child and sibling combinators inside `:has()`, form-state styling such as `:focus-visible` and `:invalid` labels, and JavaScript-free theme toggles. Some pseudo-classes, including media states and certain form invalidation cases, don't yet update inside `:has()`, so cross-browser testing is recommended.

  • Release Notes for Safari Technology Preview 243

    WebKit mediumAdept

    Safari Technology Preview 243 ships WebKit changes 310600@main through 312007@main for macOS Tahoe and Sequoia. The bulk of the release is CSS layout and selector fixes, covering flexbox, grid, aspect-ratio, anchor positioning, `:has()` invalidation and CJK line breaking. It also adds `contain: style` for quote counters, the `insert` keyword for `text-autospace` and the `shadowrootslotassignment` attribute. Other changes include accessibility fixes for VoiceOver, an O(n²) fix for parsing large `<select>` lists, an ES module loader rewrite for top-level await correctness, and several regular expression fixes.

The quest for software engineering knowledge.

Look:
Layout: