[webkit-dev] Request for position: CSS highlight inheritance (css-pseudo #highlight-cascade)

Delan Azabani dazabani at igalia.com
Thu Jul 1 01:22:14 PDT 2021


I’m seeking WebKit’s position on the “Cascading and Per-Element
Highlight Styles” section of css-pseudo-4 [0].

Most impls (with the sole exception of Presto) have historically not
propagated highlight styles through the element tree. This has meant
that only the global ::selection selector (*::selection) worked
intuitively, and made it awkward to style the highlights on some
subset of elements.

Authors had to repeat each selector with a “*” descendant, and ensure
that “overriding” rules win the cascade. For example, to highlight
content under p.foo in yellow, but content under <em> anywhere in the
document in cyan, one might:

    p.foo::selection,
    p.foo *::selection {
        background-color: yellow;
    }
    em:not(#specificity)::selection,
    em:not(#specificity) *::selection {
        background-color: cyan;
    }

The spec gives highlights an inheritance-based processing model, where
all properties (inherited or otherwise) default to the value on the
parent’s highlight. Note that the spec’s processing model is no longer
cascade-based, as of w3c/csswg-drafts#2474 [1].

We believe the compat risk is minimal, because the new model won’t
break existing content with global ::selection rules, nor will it
break rules that use the cascade to build an ersatz “propagation” like
the example above. As far as we can tell, only content that relies on
descendants of a highlight-styled element being reset to initial
styles should be affected.

[0] https://drafts.csswg.org/css-pseudo-4/#highlight-cascade
[1] https://github.com/w3c/csswg-drafts/issues/2474

Cheers,
Delan Azabani
Igalia // web platform


More information about the webkit-dev mailing list