selector

attribute-presence — CSS reference

Tests whether the attribute exists, even when its value is empty. It does not test whether a reflected DOM property is truthy.

Formal Syntax & Structure

css syntaxcss
[attr]

Working Example

Example Snippetcss
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Selector lab</title><style>:where(.sample) { color: rgb(32, 32, 32); }[data-role] { color: rgb(0, 96, 80); }</style></head><body><p id="a" class="sample" data-role="">A</p><p id="b" class="sample" >B</p></body></html>
CSS Reference