w3c / w3c/csswg-drafts

[selectors-4] :valid-within / :invalid-within pseudo-classes

Open
#3,072 12 comments 21 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

selectors-5
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

Selectors Level 4

This is a request to add pseudo-class selectors (:valid-within & :invalid-within) that would apply to any element that contains an element which matches the conditions used for the :valid or :invalid pseudo-classes.

The use cases would be very similar to those of the :focus-within pseudo-class. The most obvious case would be if one wanted to style a containing parent element of an input with a different background color, such as in the attached example.

I know that it is already possible to style siblings that follow the input via input:invalid <+/~> <selector> (as long as one can control their source order), however the proposed pseudo-class would have a wider range of uses and not require specific source ordering.

These selectors were mentioned briefly as a comment in #457, pertaining to :target-within. I could not find other discussions of the same.

invalid-within

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Selectors Level 4 section linked in the issue, then read the related discussion in #457. Compare the proposed :valid-within and :invalid-within behavior with :focus-within and the existing :valid/:invalid pseudo-classes, using the attached example as context. Done means the working group has resolved the behavior and specification direction.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.