CSS
CSS Attribute SelectorsCSS Attribute Selectors
CSS attribute selectors target elements by their HTML attributes.
Read Time
5 min readDifficulty
BeginnerLast Updated
Jun 15, 2026Version
v1.0.0Introduction
CSS styles elements based on the specific attributes they carry. Developers can target all links that open in a new tab or all input fields of a certain type. This avoids cluttering the HTML with extra class names.
Example
Example
Key Points
- Square brackets define an attribute selector.
- You can target the mere presence of an attribute.
- You can target an exact attribute value.
- You can target partial attribute values.