Skip to content

[css-highlight-api] Inline styles for Highlight should apply on top of styles provided by ::highlight #4588

Closed
@sanketj

Description

@sanketj

This section (https://drafts.csswg.org/css-highlight-api-1/#c-and-h) of the highlight API spec mentions that "the User Agent must use the styles provided in the style attribute of the corresponding highlight when no applicable property has been specified via ::highlight()". This seems to imply that if a ::highlight has been specified, then the ::highlight styles should "win" over those coming from the .style attribute. What was initially proposed in the highlight API explainer (https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/highlight/explainer.md#application-of-css-properties) was that "the Highlight object's 'inline' style (i.e. properties set directly on the .style member) will be applied on top of the cascaded values for the given highlight identifier", which is the reverse of what we currently have spec'ed.

Not sure if this was a deliberate change but I think it is important that styles set via the .style attribute apply on top of ::highlight styles. This is a useful convenience for authors to be able to override the highlight styles from script. I can see it being especially useful when combined with highlight events (https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/highlight/events-explainer.md). For example, if the author wants to change the background color of a highlight when it is clicked, it is convenient to attach a click event listener to the highlight and then set the .style attribute in the callback.

cc: @frivoal @BoCupp-Microsoft @gked

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions