Skip to content

Allow select[value=""] as a selector #7042

@bramus

Description

@bramus

To style a <progress> element based on its value, it's possible to use a selector like this (demo on CodePen):

progress[value="50"] { /* ✅ Works */
	accent-color: lime;
}

For <select> elements that's not possible, though:

select[value="1"] { /* ❌ Doesn't work */
  …
}

We can work around this using :has() (demo on CodePen, use Safari TP):

select:has(option[value="1"]:checked) { /* ✅ Works */
   …
}

Would be nice if select[value="…"] worked as well, as it's easier to use. It's also a less specific selector of (0,1,1) (vs (0,2,2) using :has()).

I know that value is not an attribute of <select>, but perhaps this could be exposed similar to how JavaScript makes document.querySelector('select').value work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions