Skip to content

Ability to style default summary in <details> #8770

Open

Description

@jakearchibald
<details>
  Hello!
</details>

Unless I'm missing something, there doesn't seem to be a way to style the auto-generated <summary> for <details>.

Should we add something like this:

details::default-summary {
  /* … */
}

That also means the styling of the <summary> can move entirely into the UA sheet:

details > summary:first-of-type,
details::default-summary {
  /* … */
}

Activity

  1. added
    topic: rendering
    topic: selectors
    on Jan 27, 2023
  2. bkardell commented on Feb 9, 2023

    @bkardell
    Contributor

    Just out of curiosity, why limit that to the 'default summary' instead of making it apply to the 'active summary' (ie, whatever the part internally playing the summary role is). I don't have a good name for that, so I'll just use ::summary-part to illustrate what I mean..

    The UA sheet would just be:

    details::summary-part {
      /* … */
    }
    

    And so would most actual stylesheets, I expect.

    If that makes any sense, it needs a better name.

  3. jakearchibald commented on Feb 9, 2023

    @jakearchibald
    ContributorAuthor

    I couldn't think of any other case where a pseudo-element selector selected something that wasn't a pseudo-element, or shadow DOM.

  4. bkardell commented on Feb 9, 2023

    @bkardell
    Contributor

    I guess I was suggesting that maybe it isn't the <summary> you want to style after all but kind of the (inspecting the chrome shadow dom anyway) details-summary slot, and we'd expose... basically that (handwavingly)

  5. jakearchibald commented on Feb 10, 2023

    @jakearchibald
    ContributorAuthor

    Yeah, that could work. I see the appeal of having a single selector for it. Not sure what to name it, but I'm sure there's a name out there.

  6. zcorpan commented on Feb 13, 2023

    @zcorpan
    Member

    This seems reasonable to me. You should probably file an issue for the CSS WG as well. cc @whatwg/css

  7. added
    addition/proposal
    on Feb 13, 2023
  8. jakearchibald commented on Feb 13, 2023

    @jakearchibald
    ContributorAuthor

    We may as well, at the same time, expose the details content. It'd be nice to allow CSS to override the open/close state.

  9. scottaohara commented on Feb 13, 2023

    @scottaohara
    Contributor

    That seems like it could create misalignments with how the details summary could expose the content as in the collapsed state, but it would actually be shown. And vice versa.

    Likely could be done, but just needs to be on the checklist of things to do if allowing that

  10. nt1m commented on Feb 13, 2023

    @nt1m
    Member

    We may as well, at the same time, expose the details content. It'd be nice to allow CSS to override the open/close state.

    #8884

  11. jakearchibald commented on Feb 14, 2023

    @jakearchibald
    ContributorAuthor

    @scottaohara fwiw, <dialog> already has these misalignments. You can display a closed dialog.

  12. scottaohara commented on Feb 14, 2023

    @scottaohara
    Contributor

    @jakearchibald true, but there is no native HTML element that triggers a dialog that would expose an expanded/collapsed state. So not a 1:1 comparison with details/summary where if you make the contents of the details visible by CSS then the state communicated when someone interacts with the summary element would also need to change based on this modification.

  13. dbaron commented on May 4, 2023

    @dbaron
    Member

    Given that all major engines (Chromium, Gecko, WebKit) implement details in terms of shadow DOM, it's also possible we could do this by moving towards (a) standardizing that shadow DOM (or the necessary aspects of it) and (b) exposing parts that could be styled using ::part() (as selectmenu does).

    (Also see an explainer I'm working on about improving stylability of details.)

  14. annevk commented on May 5, 2023

    @annevk
    Member

    I'm not sure there's agreement that. In particular I find it rather inconsistent with existing elements to use userland shadow tree APIs. The internal shadow tree is defined already (in the Rendering section) and defining built-in pseudo-elements for it as suggested upthread seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposaltopic: renderingtopic: selectors

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions