VOOZH about

URL: https://www.geeksforgeeks.org/css/css-attribute-selector/

⇱ CSS Attribute Selector - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CSS Attribute Selector

Last Updated : 11 Jul, 2025

CSS attribute Selector allows you to select elements based on the presence, value, or specific characteristics of their attributes. They are particularly useful for dynamic or structured content where attributes play a key role, such as in forms or data tables.

Types of CSS Attribute Selectors

1. [attribute] Selector

This selector matches all elements with the specified attribute, regardless of its value.

2. [attribute="value"] Selector

This selector matches elements with an attribute whose value is exactly equal to the specified value.

3. [attribute~="value"] Selector

This selector matches elements where the attribute's value is a space-separated list of words and one of the words matches the specified value.

4. [attribute|="value"] Selector

This selector matches elements whose attribute value is either exactly value or starts with value followed by a hyphen (-). It is often used for language attributes.

5. [attribute^="value"] Selector

This selector matches elements whose attribute value starts with the specified value.

6. [attribute$="value"] Selector

This selector matches elements whose attribute value ends with the specified value.

7. [attribute="value"] Selector*

This selector matches elements whose attribute value contains the specified value anywhere within it.

8. Combining Attribute Selectors

You can combine multiple attributeselectors to refine your targeting.

Practical Use Cases

Comment
Article Tags: