Attribute Selectors
What are Attribute Selectors?
Attribute selectors target elements based on their attributes and values. They're powerful for styling forms, links, and data attributes!
Has Attribute [attr]
Select elements that have a specific attribute, regardless of its value.
Exact Match [attr=value]
Select elements where the attribute exactly matches the specified value.
Starts With [attr^=value]
Select elements where the attribute value starts with the specified string.
Ends With [attr$=value]
Select elements where the attribute value ends with the specified string. Great for file types!
Contains [attr*=value]
Select elements where the attribute value contains the specified string anywhere.
Data Attributes
Style elements based on custom data attributes. Perfect for state management!
Summary
[attr]- Has attribute[attr=value]- Exact match[attr^=value]- Starts with[attr$=value]- Ends with[attr*=value]- Contains- Great for forms, links, and data attributes
- Case-insensitive with
iflag:[attr=value i]
Quick Quiz
Which selector matches attributes that end with a value?
Enjoying these tutorials?