[TIL] CSS :empty isn’t applicable on form fields

Today I learned that the CSS :empty selector is implemented to look for child content (think of innerText/innerHTML).
This means it reports empty for filled form elements which are self-closing elements.

Findings

I’ve created a Codepen with various tests that show the possibilities:

See the Pen CSS :empty pseudo-selector does not work well for form fields by Anselm Hannemann (@anselmh) on CodePen.

Update 20. Feb 2023

Browser vendors agreed to implement :user-invalid and :user-valid selectors into browsers this year as part of the Web Interoperability goals.

Sources: