CSS [attribute operator value s] Selector
Description
The [attribute operator value s] selector is a powerful CSS tool that allows authors to target elements based on the presence and value of their attributes. Unlike simple attribute selectors that only check for the existence of an attribute, this selector uses an operator to match the attribute’s value against a specific pattern, giving you more precision and flexibility when styling elements. It can be used to apply styles to elements dynamically without requiring additional classes or IDs.
This selector is particularly useful when working with structured content or forms. For example, if you want to style all <input> elements of type "text", you could use [type="text"]. However, with the [attribute operator value s] selector, you can perform more advanced matching, such as selecting elements whose attributes start with, end with, or contain certain values. This enables designs that adapt to varying attribute values without hardcoding multiple selectors.
A common application is for styling links or buttons dynamically. Suppose you have several <a> tags with a data-role attribute that varies, such as data-role="admin" or data-role="guest". You can style all elements starting with "admin" using the appropriate operator in this selector. Combined with other selectors like .class or pseudo-classes, it allows for sophisticated targeting strategies.
Additionally, [attribute operator value s] can enhance responsiveness by controlling styles for elements based on attributes like lang, title, or aria-*. For instance, you might apply different font sizes or colors depending on a language attribute, linking to CSS properties like color or font-size. This selector therefore helps maintain semantic HTML structure while still providing rich, conditional styling.
In practice, its flexibility means that developers can write CSS rules that adapt to changes in the HTML without needing extra markup. By leveraging the operators thoughtfully, such as ^= (starts with), $= (ends with), and *= (contains), this selector can target a wide array of elements efficiently, making stylesheets cleaner and more maintainable.
Syntax
[attribute=value i] { css declarations; }
Example
Browser Support
The following information will show you the current browser support for the CSS [attribute operator value s] selector. Hover over a browser icon to see the version that first introduced support for this selector.
This CSS [attribute operator value s] selector is supported in some modern browsers, but not all.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 2nd January 2026
