w3c / w3c/csswg-drafts

[css-shadow-parts] Specifying named slot in styling its slotted content

Open
#8,577 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

css-shadow-parts-1
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

When discussing #7922, I raised a concern that the current implementation of ::slotted (which matches selectors based on their light DOM relationships, regardless of slot assignments) could be compounded by adding combinator support inside that pseudo.

This codepen demonstrates the confusion of styling :first-child/:last-child when using named slots b/c the selector is evaluated based on the :first-child in the light DOM but not the :first-child as assigned to a named slot.

I propose we create a new approach to styling slotted content that allows authors to identify 'default' or named slot. i.e.,

::resolved-slot('one', *:first-child) {

^ Not in love with that naming but we can bikeshed later.

Alternatively, @LeaVerou mentioned a possible alternative syntax entirely to indicate a shift from the web component's Shadow DOM to the light DOM. Perhaps:

@slotted {
  p:first-child { ... }
  div + div { ... }
}

with a named slot:

@slotted (name="one"){
  p:first-child { ... }
  div + div { ... }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with issue #7922 and the linked CodePen demonstration to understand the mismatch between light-DOM relationships and named-slot assignments. Compare the proposed ::resolved-slot() and @slotted syntaxes, then review the CSS Shadow Parts context. Done requires agreement on a syntax and its selector behavior before implementation can be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.