Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS ::selection Inheritance Model #914

Closed
schenney-chromium opened this issue Nov 3, 2023 · 1 comment
Closed

CSS ::selection Inheritance Model #914

schenney-chromium opened this issue Nov 3, 2023 · 1 comment
Assignees
Labels
Resolution: satisfied The TAG is satisfied with this design

Comments

@schenney-chromium
Copy link

こんにちは TAG-さん!

I'm requesting a TAG review of changes to the CSS cascade model for the ::selection pseudo class, also known as CSS Highlight Inheritance because it applies to all highlight pseudos (of which ::selection is the only one that has been around long enough to have back compatibility concerns).

With CSS Highlight Inheritance, the CSS Highlight pseudo classes, such as ::selection and ::highlight, inherit their properties through the pseudo highlight chain, rather than the element chain. The result is a more intuitive model for inheritance of properties in highlights. Specifically, "When any supported property is not given a value by the cascade ... its specified value is determined by inheritance from the corresponding highlight pseudo-element of its originating element’s parent element."

Further details:

  • [ Yes ] I have reviewed the TAG's Web Platform Design Principles
  • Relevant time constraints or deadlines: WebKit are implementing and chromium would like to ship
  • The group where the work on this specification is currently being done: CSS
  • Major unresolved issues with or opposition to this specification: None.
  • This work is being funded by: Bloomberg

You should also know that...

We are requesting TAG review because this is a potentially site breaking change despite being a fix for a problem with the spec. We believe the impact on existing sites is limited based on several months of experimental testing in Chrome.

The spec defining this feature does change the behavior of ::selection (not ::highlight) for all browsers. But evidence suggests that the mitigation that sites used to work around the old behavior still work with the new behavior, so breakage is very limited. There was a single source of significant breakage when the feature was first turned on and the spec and code have been changed to maintain the former behavior (related to custom properties on root applying to ::selection). We have had zero other reported bugs from enabling the feature experimentally.

Some history ... The spec was changed in response to an issue where Firefox wanted to un-prefix -moz-selection but was not obeying the old spec. As I understand it, the selection style was checking for ::selection on the selected element, using it if found, otherwise using the root selection styling. All browsers were doing this.

Sites were designed to work around this through the judicious use of ::selection on various elements. That is, put ::selection on anything you wanted a specified selection on, and if the inheritance was wrong, add a more specific ::selection selector. Hence the heavy use of custom properties to keep all these ::selection declarations in sync. You can see this, for example, on GitHub where they define ::selection for an element, element > span, and element > span > span, and again for light and dark mode. Sass even has an operator with a comment on it saying they would remove it if the spec is fixed.

This change does not break sites that have taken the approach above. Specific selectors for ::selection will resolve to the same properties as they do now. The improvement is that "element > span::selection" and "element > span > span::selection" can now be removed in favor of just "element::selection".

We'd prefer the TAG provide feedback as (please delete all but the desired option):

💬 leave review feedback as a comment in this issue and @-notify [schenney-chromium]

@plinss plinss added this to the 2023-11-20-week milestone Nov 16, 2023
@plinss plinss removed this from the 2024-01-23-f2f-London milestone Mar 11, 2024
@torgo torgo added this to the 2024-03-18-week milestone Mar 17, 2024
@plinss plinss removed this from the 2024-03-18-week milestone Mar 25, 2024
@torgo torgo added this to the 2024-04-22-week:d milestone Apr 21, 2024
@LeaVerou
Copy link
Member

Hi there, this looks great to us, it is way better than the behavior before this change. Happy to see it move forward!

Thank you for flying TAG!

@LeaVerou LeaVerou added Resolution: satisfied The TAG is satisfied with this design and removed Progress: in progress labels Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: satisfied The TAG is satisfied with this design
Projects
None yet
Development

No branches or pull requests

4 participants