Skip to content

:blank pseudo-selector support (re form fields) #179

Closed

Description

@brandonmcconnell

Description

:blank is a pseudo-selector that allows CSS to target a form field when it is blank/unpopulated.

Quoting the spec:

The :blank pseudo-class applies to user-input elements whose input value is empty (consists of the empty string or otherwise null input).

Rationale

There's currently no viable way to target a blank form field. The most common vanilla workaround for this so far is to mark the field as required and then check for :valid along with some pattern matching, however there are quite a few fundamental problems with that approach:

  • What if there is already some non-blank-related validation logic at play which conflicts with the mere non-blank check?
  • What if the form field should NOT be required but still styled differently when blank for aesthetic purposes?

More recently, another workaround for this that has been growing in popularity is :placeholder-shown but this doesn't appear to work when there is no placeholder set.

Related discussions:

Specification

https://w3c.github.io/csswg-drafts/selectors-4/#blank

Tests

Struggling to find any tests

Activity

  1. added this to the milestone on Oct 2, 2022
  2. foolip commented on Oct 3, 2022

    @foolip
    Member

    I also can't find any tests. All matches for :blank in WPT are for about:blank, and typos of it fixed in web-platform-tests/wpt#36222.

  3. moved this to Proposed in Interop 2023on Oct 7, 2022
  4. removed this from the milestone on Oct 7, 2022
  5. annevk commented on Oct 28, 2022

    @annevk
    Member

    This seems like a reasonable feature, but the HTML standard needs to define how this actually works for its various elements. As far as I can tell that work hasn't been done.

    E.g., does this work for textarea elements? What does it mean for <input type=range> or <input type=checkbox>?

  6. brandonmcconnell commented on Oct 28, 2022

    @brandonmcconnell
    Author

    @annevk Good call out! Sharing some thoughts in the related issue you opened. Thanks!

  7. smaug---- commented on Nov 8, 2022

    @smaug----

    Would :blank apply when placeholder is set?

  8. foolip commented on Nov 11, 2022

    @foolip
    Member

    In the State of CSS 2022 question about browser incompatibilities, there were no mentions of :blank.

    (I'm not commenting on all proposals where there wasn't any signal from State of CSS, but thought I would here because it's similar to #180 where I did comment.)

  9. foolip commented on Nov 11, 2022

    @foolip
    Member

    In the MDN short survey on CSS & HTML, "CSS :blank and :empty pseudo-classes" was selected by ~19% of survey takers, putting it in the middle third of the 20 options. (There is some uncertainty as with any survey data.)

    Since :blank and :empty were bundled we can't say which of them resonated more. (This was done to reduce the total number of options.)

  10. nairnandu commented on Feb 1, 2023

    @nairnandu
    Contributor

    Thank you for proposing the :blank pseudo-selector for inclusion in Interop 2023.

    We wanted to let you know that this proposal was not selected to be part of Interop this year. The specifications for :blank are not yet complete enough to allow interoperable implementations. To make progress on this area in the future it will first be necessary to ensure that the feature has a clear specification in a standards track document.

    For an overview of our process, see the proposal selection summary. Thank you again for contributing to Interop 2023!

    Posted on behalf of the Interop team.

  11. brandonmcconnell commented on Sep 22, 2023

    @brandonmcconnell
    Author

    @foolip @nairnandu Could we look into resurrecting this one for Interop 2024 as well?

  12. annevk commented on Sep 25, 2023

    @annevk
    Member

    I'm not convinced we have seen enough progress on w3c/csswg-drafts#1967 and whatwg/html#8451.

  13. brandonmcconnell commented on Sep 25, 2023

    @brandonmcconnell
    Author

    @annevk Fair point. whatwg/html#8451 seems pretty thorough to me, but w3c/csswg-drafts#1967 may still require further discussion.

  14. kerryj89 commented on Sep 14, 2026

    @kerryj89

    This would be my Interop 2026 vote. Are we able to reopen or do I need to create a new one (if we have enough info now)? We got so many cool advanced features, this just feels like one that would have already been done. But it's one I've needed every year.

  15. benface commented on Sep 14, 2026

    @benface

    Yeah this one is getting a bit ridiculous! Too late for Interop 2026 though, but please can we try to have it ready for 2027?

  16. annevk commented on Sep 15, 2026

    @annevk
    Member

    The issues are still unresolved unfortunately.

  17. benface commented on Sep 15, 2026

    @benface

    Yes sorry, to be clear that's what I meant by "have it ready" – can we please try to resolve those issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    focus-area-proposal

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions