Skip to content

[css-selectors] Selectors for “text-ish” and “button-ish” inputs #2296

@keithjgrant

Description

@keithjgrant

Spec: https://drafts.csswg.org/selectors/

In almost every project I do, I want to style all text-like inputs the same way. But targeting those, while not targeting button-like <input>s is tricky. I usually end up doing either of these solutions:

input[type="text"], input[type="search"], input[type="tel"], input[type="url"],
input[type="email"],input[type="password"], input[type="date"],
input[type="month"], input[type="week"], input[type="time"],
input[type="number"], input[type="color"], textarea {
  …
}

/* or */

input:not([type="button"], [type="submit"], [type="reset"]), textarea {
  …
}

Both of these are more verbose than they should be, and they feel prone to breakage if/when new input types are added to HTML later on. I think there should be a pseudo-class to target all “text-ish” inputs.

Buttons are not quite as bad, but still tedious:

button, input[type="button"], input[type="submit"], input[type="reset"] {
  …
}

A pseudo-class shorthand for this would be useful as well.

And finally, a third pseudo-class to target checkboxes and radio buttons together (equivalent to input[type="checkbox"], input[type="radio"]).

Possible names for these pseudo-classes could be :text-input, :button, and :toggle.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions