Repository navigation
Description
At the F2F, there was some discussion about how to expose the <slot> in the <details> element's shadow DOM that wraps the details' content.
There are two main options: a new pseudo-element (provisionally called ::details-content), or a shadow part (provisionally called ::part(content)).
Arguments for ::details-content:
- Consistent with the collection of existing pseudo-elements exposed on various "special" elements, like
input::file-selector-button
Arguments for ::part(content)
- Clearer about what other things are allowed, like
::part(content):hoverworks by default - Integrates nicely with other shadow-parts functionality, like the ability to export it as one of the parts of a wrapping component. ¹
During the meeting, we seemed to recall that this topic had been previously brought up, and both WebKit engineers and the HTML spec editors disliked it. Our recollection of their reasoning was:
- consistency with existing pseudo-elements on special elements (aka the "arguments for" I already listed)
- part names are author-controlled, and the language shouldn't impinge on it
I think that (1) is reasonable, tho that's historical precedent from before ::part() even existed. It might be reasonable to change that. For example, we could make all those element-specific pseudo-elements also exposed as ::part(), as that would give you the "export this as one of the wrapping component's parts" ability that I allude to above.
But I will push back on (2) very strongly. It is important to not impinge on author-controlled namespaces; you don't want to accidentally clash with existing author-defined names, and it's not great to have certain special names be illegal for authors to use.
But neither of those apply here. The owner of a given element's ::part() namespace is the owner of that component's shadow DOM. I designed this very carefully to make sure that's 100% true - the owner of a component's shadow can choose to import the names from a sub-component for themselves, but it's always an extremely explicit choice. You'll never get surprised by names showing up in your namespace you don't expect.
So, here, the UA is the owner of the details shadow. If it wants to expose a part name, nothing any author can do will ever interact negatively with that.
¹: That is, if you have a custom component <my-widget> that contains a <details> element in its shadow, you could use <details exportparts=content>, and then my-widget::part(content) works, targeting the details-content box. This is impossible to do with a pseudo-element, at least right now.
Tho we could attack this from the other direction - rather than turn all existing element-specific pseudo-elements into ::part()s so they can be used in exportparts, we could just allow pseudo-elements to be used in exportparts, like <details exportparts="::details-content : content">.
/cc @emilio
Activity
nt1m commentedon Feb 17, 2024
I think the only reason
::part(name)has been designed as it is to avoid author names impeding with future built-ins. The syntax could have been::--namefwiw. In fact, WebKit internally names some existing pseudo-elements like::placeholderor::file-selector-buttonas "user-agent parts".If the syntax for
::part(name)was instead::--name, this issue to me is conceptually equivalent to asking to use::--details-contentinstead of::details-content... I don't think it really makes a lot of sense.nt1m commentedon Feb 17, 2024
I like that built-in pseudo-elements have a distinct syntax from non-built-in ones do, it makes it easy to distinguish what the browser provides by default from what the browser doesn't.
emilio commentedon Feb 17, 2024
Citation needed?:::part() and the part attribute allows multiple identifiers, not sure how that could be achieved with a syntax like that. Part is strictly more powerful than regular pseudo elements.
Sure, but for each we need to define what pseudo classes if any are valid to the right of the pseudo. Also what properties apply to it. All these are answered for for part.
I don't see part as a built in pseudo element, it can expose multiple elements and elements can have multiple parts, it's a more powerful feature. The fact that WebKit uses that mechanism to implement some pseudos is kind of an implementation detail.
emilio commentedon Feb 17, 2024
I think that'd be super weird, to target something sometimes as part and sometimes as pseudo-element. Also we probably don't want to do this for all pseudo elements, it's unclear what exposing a first-line should do, for example? I think that's not great alternative, and if we go for a pseudo element we should just tell people to export the whole details element for such use case (which might not be what they want, necessarily, but would allow you to do ::part(details)::details-content the same way you can do ::part(input)::placeholder nowadays.
dbaron commentedon Feb 21, 2024
Previous discussions on this topic:
<details>: Ability to style default summary in <details> whatwg/html#8770, particularly Ability to style default summary in <details> whatwg/html#8770 (comment) and the one following it<select>: [select] Don't reuse slot="" and ::part(); behavior="" is also strange openui/open-ui#702 (long)Note that a big chunk of the Open UI discussion was the week after the Cupertino F2F discussion, and the combination of those two made me give up on trying to push for
::part()at the time, even though I would have preferred it.rniwa commentedon Mar 8, 2024
I don't think we should be using
::partsyntax fordetails. The whole point of::partsyntax was to namespace shadow DOM / custom elements so that they won't conflict with builtin pseudo elements.I'm immensely annoyed that this topic is getting re-litigated again.
dbaron commentedon Mar 8, 2024
There are many things we could say about what an individual participant in a discussion thought the motivations for something were at the time. For example, I could point out the post I over wrote 21 years ago describing one of the core motivations for wanting XBL (early in a decade-long standards journey that eventually led to web components) as being able to describe builtin controls and allow them to be styled. But I don't think either of those opinions represent clearly documented consensus, and even if they did, new evidence can lead reopening of issues where there was previous consensus.
annevk commentedon Mar 8, 2024
I consider
::details-contentthe only viable option.Rationale:
::part()is a web developer namespace. This would be akin to standardizingdata-*attributes. While it is true we are not taking away names web developers can use, it is still utterly confusing.::placeholder,::marker,::file-selector-button,::thumb/::slider-thumb, etc.::part()is very much tied to open/closed shadow trees. For built-in elements the way they work should remain up to implementations, even if we decide to define their subtree in terms of internal shadow trees (not open/closed) in the specification. Using::part()however deviates from that as that's specific syntax tied to open/closed shadow trees. I'm very much opposed to start exposing implementation details.Loirooriol commentedon Mar 8, 2024
It's a namespace for the creator of the shadow, which can be the author or the UA. It's different to
data-*attributes or CSS custom properties, where the author and the UA share a single namespace.But the spec mandates a shadow tree, and this is already exposed to authors. E.g. if they use
details::before, it appears before the summary, not at the beginning of the details content.kbrilla commentedon Mar 8, 2024
I think discussion
:part()vs:custom-pseudowas held many times in recent year always in favor of custom pseudo.emilio commentedon Mar 8, 2024
I'm not sure I agree, it is confusing the first time because it's new, but long term it's IMO less confusing, specially for developers already familiar with parts.
Sure, though same thing, that's a one-time issue. That's also fixable (e.g., you can expose
::file-selector-buttonas an alias of::part(selector-button)and so on, conceptually).I'm not sure I get this argument. We already define
<details>in terms of a shadow tree. Can a user agent implement using something else? Lot of effort, but sure. But you could also make::partwork in that (hypothetical) set-up.An aside / another topic worth looking into, is that there's another difference between
::part()and pseudos that I think might be worth discussing, which is which element do they inherit from.Pseudo-elements always inherit from its originating element, while
::part()uses the usual flat tree rules. For::details-contentin particular it might not be an issue, because those would end up being the same (the<details>element), but for newer form controls or things likeswitch, where you may want to define e.g. the thumb as a child of the track, it can cause confusing behavior:Alternatively, we might want to have a weird "part-like pseudo-element" that behaves like this... But that's a new CSS concept.
I think that if we're going to define new controls in terms of shadow trees, using
::part()would be the right thing to use to expose the inner elements. It's more powerful, way less special.The big drawback that I see with
::part()is feature-detection / not being able to use@supports selector(::details-content)or so.tabatkins commentedon Mar 8, 2024
@nt1m
No, that was one reason. The other reason was to allow the class-like semantics, where an element can be exposed and/or targeted via multiple part names. (As the co-author of the spec, I can speak definitively on this.)
@rniwa
It was to namespace, yes, but the conclusion you're subsequently drawing from that (that the UA should never be allowed to use ::part()) is incorrect. The ::part() namespace of a component is owned by the owner of the component's shadow DOM. Arbitrary authors cannot interfere with a given component's names (unlike many other namespaces we explicitly carved out for authors, like custom properties). So, since the
detailsshadow is owned by the UA, the ::part() namespace for it is owned by the UA as well. It is 100% safe for the UA to expose parts.This isn't particularly appropriate to express in this venue.
@annevk
I sympathize with "confusing", but this is still a meaningfully distinct situation from
data-*attributes, or most other author namespaces we've carved out.This is the big argument against ::part(), I think.
I'm not sure what "open/closed" has relevance here, but yes, it does expose the fact that the element has a shadow tree (or at least masquerades as having one). This is already supported in the spec in any case - authors aren't allowed to install a shadow tree of their own on
details.@emilio
Well right now the choice is "target it as a pseudo-element" (if you have access to the originating element) or "you can't target it at all, sucks to be you" ^_^. I think allowing the second situation to become "target as a part" is an improvement; it allows people to, say, wrap a
detailsin theirimage-spoilercomponent and still expose the contents bit. Or have a form component that wraps an<input type=file>and exposes its::file-chooser-buttonor whatever.Right, it would need to be tree-abiding pseudos only. Non-tree-abiding are virtually always an exception.
Yeah, it's possible, but awkward. ^_^ It forces the author to expose the fact that something is implemented as a
details, rather than hand-rolled. This isn't strictly necessary to avoid, but we do try to avoid exposing such implementation details when we can.dbaron commentedon Mar 13, 2024
I think there is a plan to discuss this at the WHATNOT meeting tomorrow; see whatwg/html#10200 . (This meeting is exactly 24 hours after the CSS call.)
emilio commentedon Mar 14, 2024
Ok, so things that I want discussed after chatting with @smaug---- (putting here for reference and so I don't forget):
::pseudois more consistent with existing built-ins). But that might be a one-time thing.::pseudohas different inheritance behavior than::part(), which is relevant if we want people to rely on the tree shape).::part()is more flexible than::pseudo, specially combined with existing shadow trees).::pseudos like placeholder have specific restrictions). My understanding is that we don't want this in the future, but it's hard (not impossible I guess) to bolt this into parts.3 remaining items
tabatkins commentedon Mar 14, 2024
Raised the "part-like pseudo-element" issue in #10083
astearns commentedon Mar 15, 2024
Slightly more detail in meeting notes here: whatwg/html#10200 (comment)
Specify the rendering of <details> in more detail.
LeaVerou commentedon May 8, 2024
Every use case I’ve seen where multiple part names are used, only one is actually a true part name, and the others are states which are better addressed as custom pseudo-classes.
yisibl commentedon May 18, 2024
I'm rather curious as to why there is no
<details-content>element in HTML, and if it existed, wouldn't there no longer be a need for the::details-contentpseudo-element?As a CSS author, API consistency is important, so I support
::details-content.Add ::details-content pseudo-element.
Add ::details-content pseudo-element.
Add ::details-content pseudo-element. (#10379)
yisibl commentedon Jun 20, 2024
@dbaron From my testing, Chrome(128.0.6544.0) doesn't currently support
::details-content:hoverand::details-content::before, do you have plans to implement them before shipping?dbaron commentedon Jun 20, 2024
Yes.
Specify the rendering of <details> in more detail
WickyNilliams commentedon Sep 13, 2024
@LeaVerou an example where I have used multiple parts - I have a calendar component with lots of
<button>s (next month, previous month, plus every day is a button). Each of these has abuttonpart. This allows consumers to apply broad styles to all buttons. But also each button has more specific parts likenext,previous,day. Allowing users to style individual instances (next/previous) or categories of buttons (days). So there are two parts on each, they are always present, and neither are state related.Specify the rendering of <details> in more detail
bramus commentedon Aug 14, 2025
I believe we can close this one as
::details-contentis available in all major engines (behind a flag in Firefox) by now.