Skip to content

[selectors] :visible pseudo-class for targeting only visible elements #5827

@castastrophe

Description

@castastrophe

https://www.w3.org/TR/selectors-4/

Proposal to add a :visible pseudo-class to the selectors specification. This would allow authors to target only elements in the DOM that do not have display: none or visibility: hidden applied. Would be helpful if it also excluded style and script tags that do not render visible user content. This would add a lot of value for systems builders as often they do not have full control of the markup they are styling.

Example use-cases

  • li:visible: Target all visible list items.
  • *:first-child:visible: Target the first visible element (this is extremely useful for situations where a script or style tag might appear first in the DOM but is not visible to the user).
  • div:not(:visible): A way to toggle visibility (though some JS or interaction would likely be involved to trigger the change).

Apologies if this has already been discussed, I did a search of the issue queue and did not see anything comparable. I look forward to discussion on this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions