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

[selectors-4] :empty pseudo-selector (spec updated) #594

Closed
brandonmcconnell opened this issue Oct 25, 2023 · 3 comments
Closed

[selectors-4] :empty pseudo-selector (spec updated) #594

brandonmcconnell opened this issue Oct 25, 2023 · 3 comments

Comments

@brandonmcconnell
Copy link

This is a copy from last year's Interop 2023 proposal for this same feature: #180

Description

:empty pseudo-selector (spec updated to also match elements with only whitespace)

Quoting the spec:

The :empty pseudo-class represents an element that has no children except, optionally, document white space characters. In terms of the document tree, only element nodes and content nodes (such as [DOM] text nodes, and entity references) whose data has a non-zero length must be considered as affecting emptiness; comments, processing instructions, and other nodes must not affect whether an element is considered empty or not.

Example: p:empty is a valid representation of the <p> elements in the following HTML fragment:

<p></p>
<p>
<p> </p>
<p></p>

Example: div:empty is not a valid representation of the <div> elements in the following fragment:

<div>text</div>
<div><p></p></div>
<div>&nbsp;</div>
<div><p>bla</p></div>
<div>this is not <p>:empty</p></div>

Rationale

The :empty pseudo-class is already widely supported among most modern browsers, but the spec has since changed to include matching for elements that contain only whitespace and no non-whitespace nodes or text nodes.

Quoting the amendment to this change from the spec:

Note: In Level 2 and Level 3 of Selectors, :empty did not match elements that contained only white space. This was changed so that that—given white space is largely collapsible in HTML and is therefore used for source code formatting, and especially because elements with omitted end tags are likely to absorb such white space into their DOM text contents—elements which authors perceive of as empty can be selected by this selector, as they expect.

In modern web development, we have bundlers that remove all non-whitespace characters from elements, so this is not normally an issue for a good number of us, but that limits the use of features like this to those of us running non-standard tools and further gate-keeps those without them, namely JAMstack devs who may have to ensure none of their elements are ever empty, so they can target in CSS them as expected.

It's the main reason for why we tend to see HTML like this in the wild, to ensure all elements contain no unexpected whitespace:

<div
    >Some content<span
        >some more content</span
    ></div
>

Related discussions:

Specification

https://w3c.github.io/csswg-drafts/selectors-4/#the-empty-pseudo

Tests

@foolip
Copy link
Member

foolip commented Nov 2, 2023

Hi @brandonmcconnell, unfortunately it's too late to propose focus areas for Interop 2024, the proposal window closed on Oct 7. We're now in the middle of evaluating the 100+ proposals we got and can't take on additional work. Closing this, but that's not a reflection of the strength of :empty as a proposal, just our need to keep our planning deadlines.

@brandonmcconnell
Copy link
Author

@foolip That's understandable. Moving forward, I think it would be highly advantageous and convenient to automatically repropose features that were not accepted into the previous year's interop.

This feature was already evaluated and essentially now has to skip a year.

@foolip
Copy link
Member

foolip commented Dec 6, 2023

@brandonmcconnell thanks for the feedback! I've filed #611 and linked your comment there so it's not forgotten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants