Attribute selector

The attribute selector matches elements based on the presence or value of an attribute.

Since CSS2 Spec ↗

Syntax

[attr], [attr=value], [attr^=v], [attr*=v], [attr$=v]

Examples

input[type='email'] { border-color: teal; }
a[href^='https://'] { color: green; }
[data-state='open'] { display: block; }
[aria-current='page'] { font-weight: 700; }
Output
Styles email inputs, external https links, open-state elements, and the current page nav link.

Notes

Operators: = exact, ^= starts-with, $= ends-with, *= contains, ~= space-list, |= prefix. Add i before ] for case-insensitive matching. Specificity equals a class (0,1,0).

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 3.1
edge 12

See also