Skip to content

Support Native CSS Nesting #8587

@jrmoynihan

Description

@jrmoynihan

Describe the problem

Native CSS Nesting without a pre-processor is stable since Chromium 112 (March 2023), and is in technical preview of Safari 16.5.

However, this syntax is not supported by Svelte's processor in <style> tags. Especially in instances like using Svelte in third-party web containers where you might not have control over the availability of additional pre-processors, this makes writing the style rules far simpler/easier than using complex selectors or a multitude of classes, allowing more rapid and readable prototyping.

Surprisingly, there's no open or closed issue covering this topic.

Sources:
https://caniuse.com/css-nesting
https://web.dev/web-platform-04-2023/
https://developer.chrome.com/articles/css-nesting/
https://webkit.org/blog/13813/try-css-nesting-today-in-safari-technology-preview/

Describe the proposed solution

Treat nested selectors as valid syntax. Given this html:

<p>
  We really <span>should</span> support this
  <strong class="red">because it's part of the web platform...</strong>
</p>

All of these syntaxes should work without error:

<style>
  /* p strong */
  p {
    strong {
      line-height: 1.2;
    }
  }
  /* strong.red */
  strong {
    &.red {
       color: red;
    }
  }
  /* p > span */
  p {
    > span {
      color: orange;
    }
  }
</style>

Alternatives considered

Using a pre-processor is the alternative, but it adds unnecessary bloat to the DX.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions