The [attribute^=value] selector matches elements when an attribute value begins with a specific string. It is ideal for URL schemes, path prefixes, and class naming patterns.
01
Starts with
Prefix match.
02
^= operator
Caret-equals.
03
href URLs
https, /.
04
Class prefix
btn-, nav-.
05
vs $=
Start vs end.
06
vs |=
Prefix vs hyphen.
Fundamentals
Introduction
The [attribute^=value] selector in CSS is an attribute selector that targets elements whose specified attribute value starts with a given substring.
This is particularly useful for styling links by protocol, internal paths, form field name prefixes, or utility classes that share a common beginning — without adding extra classes to every element.
Definition and Usage
Write the attribute name in brackets, then ^= and the prefix in quotes: a[href^="https"]. The element matches only if the attribute value begins with those exact characters at the first position.
💡
Beginner Tip
^= means “starts with.” Use [attr$=value] when the match must be at the end, and [attr|=value] when you need an exact value or a hyphen-separated suffix like en-US.
Foundation
📝 Syntax
The signature of the starts-with attribute selector is:
user_name and user_email share the user_ prefix. Fields like order_id use a different naming pattern and are not selected.
Watch Out
⚠️ Common Pitfalls
http vs https — [href^="http"] also matches https:// URLs because https starts with http. Put the more specific rule first or use https alone.
Case sensitivity — HTTPS and https are different prefixes.
Not substring — The match must be at the start of the value, not anywhere inside it.
vs |= — Use |= for hyphen-separated locale codes; ^= is a plain character prefix match.
A11y
♿ Accessibility
External link cues — Do not rely only on color to mark external links; add clear link text or icons.
Form labels — Prefix-based input styling is visual only; always pair inputs with <label> elements.
Contrast — Ensure styled link and button colors meet WCAG contrast requirements.
🧠 How [attribute^=value] Works
1
Read attribute value
The browser gets the full string from the HTML attribute.
DOM
2
Check the prefix
^= compares the beginning of the value to your quoted string.
Match
3
Apply styles
Elements with a matching prefix receive the CSS rule.
Render
^
✅
Precise prefix targeting
Ideal for URLs, paths, and naming conventions.
Compatibility
Browser Compatibility
The [attribute^=value] selector is supported in all modern browsers.
✓ Universal · All browsers
Prefix matching everywhere
Chrome, Firefox, Safari, Edge, and Opera all support the ^= 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 URL schemes, paths, and attribute prefixes in modern projects.
Wrap Up
Conclusion
The [attribute^=value] selector is a precise tool for matching attribute values that begin with a specific string. It shines when styling links by protocol, internal paths, and shared naming prefixes.
Combine it with pseudo-classes like :hover, compare it with $= and |=, and watch out for overlapping prefixes like http and https.