The [attribute=value] selector matches elements when an attribute value is exactly equal to a given string. It is perfect for form controls, link targets, and other predictable HTML attributes.
01
Exact match
Full value only.
02
= operator
Equals operator.
03
Forms
type, target.
04
Buttons
submit vs button.
05
vs *=
Exact vs contains.
06
:focus
Combine states.
Fundamentals
Introduction
The [attribute=value] selector in CSS is an attribute selector that targets elements whose specified attribute has a value that exactly matches the string you provide.
This allows precise styling based on HTML attributes like type, target, role, and lang — without adding extra classes to every element.
Definition and Usage
Write the attribute name in brackets, then = and the exact value in quotes: button[type="submit"]. The element matches only if the attribute value is identical to that string — no partial matches.
💡
Beginner Tip
= means “equals exactly.” Use [attr*=value] when the value only needs to contain a substring, or [attr^=value] / [attr$=value] for start/end matches.
Foundation
📝 Syntax
The signature of the exact-match attribute selector is:
input[type="checkbox"] matches only checkboxes. An email input with type="email" would not be selected by this rule.
Watch Out
⚠️ Common Pitfalls
Partial values — [type="button"] does not match type="button-primary" or values containing extra text.
Case sensitivity — type="Submit" and type="submit" are different matches.
Missing attribute — If the attribute is absent, the selector never matches.
Wrong operator — Use ^=, *=, or $= when you need partial matching instead of exact equality.
A11y
♿ Accessibility
External link cues — Pair target="_blank" styling with visible text or an icon indicating a new tab.
Focus states — Always provide a visible :focus style on form inputs; do not remove outlines without a replacement.
Color alone — Do not rely only on color to distinguish submit vs cancel buttons; use clear labels.
🧠 How [attribute=value] Works
1
Read attribute value
The browser reads the full string from the HTML attribute.
DOM
2
Compare exactly
= checks that the entire value equals your quoted string.
Match
3
Apply styles
Elements with an exact match receive the CSS rule.
Render
=
✅
Precise attribute targeting
Ideal for forms, link targets, and known attribute values.
Compatibility
Browser Compatibility
The [attribute=value] selector is supported in all modern browsers.
✓ Universal · All browsers
Exact 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 form types, link targets, and other exact attribute values.
Wrap Up
Conclusion
The [attribute=value] selector gives you precise control over styling by matching attribute values exactly. It is especially useful for forms, links, and semantic HTML attributes.
Combine it with pseudo-classes like :focus, compare it with partial-match operators, and remember that only the full value counts — not a substring inside it.