The [attribute*=value] selector matches elements when a specific substring appears anywhere inside an attribute value. It is perfect for URLs, file types, and naming patterns.
01
Substring
Partial match.
02
*= operator
Contains value.
03
URLs
href patterns.
04
Files
.png, .pdf.
05
Classes
btn- prefix.
06
vs =
Exact vs partial.
Fundamentals
Introduction
The CSS [attribute*=value] selector targets elements whose attribute value contains a specific substring. The match can occur at the start, middle, or end of the value.
This is especially useful when attribute values vary but share a common pattern — such as links containing https, images ending in .png, or class names that include btn-.
Definition and Usage
Write the attribute name in brackets, followed by *= and the substring in quotes: a[href*="about"]. The element matches if about appears anywhere in the href value.
💡
Beginner Tip
Think of *= as “contains.” If you need the value to start with a string, use [attribute^=value] instead. For ending with, use [attribute$=value].
Foundation
📝 Syntax
The signature of the substring attribute selector is:
[class*="btn-"] matches btn-primary, btn-danger, and btn-ghost because each class string contains btn-.
Watch Out
⚠️ Common Pitfalls
Case sensitivity — [href*="PDF"] will not match file.pdf.
Over-matching — [href*="a"] matches almost every URL; keep substrings specific.
Performance — Broad *= rules on large pages can be slower; prefer classes when possible.
Specificity — Combine with element names (a[href*="pdf"]) to avoid unintended matches.
A11y
♿ Accessibility
Do not rely on color alone — PDF indicators should include clear link text, not just red styling.
Generated labels — If using ::after with PDF markers, ensure the link text is still descriptive.
External links — Pair visual cues with accessible names and rel attributes where needed.
🧠 How [attribute*=value] Works
1
Browser reads attribute values
Each element’s attribute string is evaluated against the selector.
DOM
2
Substring search runs
*= checks whether the value contains the quoted substring.
Match
3
Matching elements styled
All elements with a containing match receive the CSS declarations.
Render
=
✅
Flexible partial matching
Style dynamic attribute values without exact strings.
Compatibility
Browser Compatibility
The [attribute*=value] selector is supported in all modern browsers.
✓ Universal · All browsers
Substring matching everywhere
Chrome, Firefox, Safari, Edge, and Opera all support the *= attribute operator.
99%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll versions
Full support
[attribute*=value] selector99% supported
Bottom line: Safe to use *= for partial attribute matching in modern projects.
Wrap Up
Conclusion
The [attribute*=value] selector gives you flexible control when attribute values share patterns but are not identical. It is ideal for URLs, file extensions, and naming conventions.
Use specific substrings, combine with element selectors, and reach for exact (=), starts-with (^=), or ends-with ($=) operators when they fit better.