CSS [attribute=value] Selector

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The [attr=value] selector matches elements whose attribute value is exactly value—the whole string must match.

Common uses: button[type="submit"], input[type="email"], and a[target="_blank"]. For substrings use *=; for suffixes use $=.

Standard-track.

Part of CSS attribute selectors (Selectors Level 3/4). Baseline widely available. Not deprecated or experimental.

Exact means exact note

[class="btn"] does not match class="btn primary". For a token in a space-separated list, use ~=.

CSS Syntax

syntax.css
[attr= value] { … }

Optional flags before ]: i (case-insensitive) or s (force case-sensitive). Quote values that contain spaces or special characters.

Selector Parts

PartMeaningTry it
attrAttribute name (type, target, role, …)Try it
=Exact-value operatorTry it
valueFull string to match, e.g. "_blank" or "email"Try it
i flagASCII case-insensitive exact matchTry it

How to Use =

Match the full attribute value, then style only those elements.

  1. Choose the attribute that holds a discrete value (type, target, role).
  2. Write [attr="exact-value"] with the full string.
  3. Apply styles to those matches only.
  4. Use i when casing may vary; use ~= when you need one word in a list.
GoalTypical selector
New-tab linksa[target="_blank"]
Submit buttonsbutton[type="submit"]
Email fieldsinput[type="email"]
Ignore case[type="submit" i]

Live Preview

Pick an exact value. Matching controls highlight with real [attr=value] rules.

Exact match

Only elements whose attribute equals the chosen value light up.

Result

Matching a[target="_blank"]

CSS Examples

Each snippet focuses on =. Use Try It Yourself for a live editor.

Example 1 — Style New-Tab Links

Highlight anchors that open in a new tab.

CSS
<style>
  a[target="_blank"] {
    color: #b91c1c;
    font-weight: 600;
    text-decoration: underline;
  }
</style>

<a href="https://example.com" target="_blank">New tab</a>
<a href="/about">Same tab</a>
Try It Yourself

How It Works

  1. Pick the attribute. target controls where the link opens.
  2. Require the full value. ="_blank" matches only that exact string.
  3. Style matches. The new-tab link turns red and bold.
  4. No partial match. Links without target, or with another value, stay normal.

Example 2 — Style Submit Buttons

Give submit buttons a distinct look from regular buttons.

CSS
<style>
  button[type="submit"] {
    color: #fff;
    background: #15803d;
    border: 1px solid #15803d;
    padding: 0.4em 1em;
  }
</style>

<button type="submit">Submit</button>
<button type="button">Cancel</button>
Try It Yourself

How It Works

  1. Use type. Buttons expose their role via the type attribute.
  2. Exact string. type="submit" must match fully.
  3. Style that button. Only Submit gets the green look.
  4. Leave others. type="button" keeps the browser default (or your base styles).

Example 3 — Style Email Inputs

Emphasize email fields among other inputs.

CSS
<style>
  input[type="email"] {
    border: 2px solid #1d4ed8;
    padding: 0.35em 0.5em;
  }
</style>

<input type="email" value="[email protected]">
<input type="text" value="plain text">
Try It Yourself

How It Works

  1. Target inputs. Combine the element with the attribute: input[type="email"].
  2. Exact type. Only email matches—not text or password.
  3. Apply the cue. A blue border marks the email field.
  4. Scale the pattern. Same idea works for password, number, and more.

Edge Cases & Pitfalls

If an exact match fails, one of these is usually why.

partial

Partial strings never match

[href="example.com"] misses https://example.com. Use *=, ^=, or $= for parts.

class

Multiple classes need ~=

[class="btn"] fails on class="btn primary". Prefer .btn or [class~="btn"].

case

Watch letter case

Default matching is often case-sensitive. Add i when values may differ only by case.

quotes

Quote special values

Values with spaces or punctuation should be quoted: [title="Hello world"].

presence

Presence is different

[disabled] matches any element with that attribute. [disabled="disabled"] requires that exact value. See attribute overview.

Browser Support

[attr=value] is a browser CSS selector. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

[attr=value]

Supported in Chrome 4+, Firefox 2+, Safari 3.1+, Edge 12+, Opera 10+, IE 7+. The i case flag needs Chrome 49+, Firefox 47+, Safari 9+, Edge 79+.

98% Global support
Google Chrome 4+
Full support
Mozilla Firefox 2+
Full support
Apple Safari 3.1+
Full support
Microsoft Edge 12+
Full support
Opera 10+
Full support
Samsung Internet 4+
Full support
Internet Explorer 7+
Full support
= Universally supported

Bottom line: Safe for production. Prefer exact matches for discrete values like type and target.

Key Takeaways

  • Role: = matches an attribute value exactly.
  • Common use: button[type="submit"], a[target="_blank"].
  • vs *= / ~=: substring vs word-in-list vs full exact string.
  • Pitfall: multi-class attributes need ~= or a class selector, not =.

One line: use [attr="value"] when the entire attribute value must match.

Frequently Asked Questions

It matches elements whose attribute value is exactly equal to the given string. The whole value must match — not a substring.
= requires an exact match. *= matches when the substring appears anywhere inside the value.
= matches the entire attribute value. ~= matches one whole word in a space-separated list (useful for class-like tokens).
For attributes like class, id, data-*, and many others, matching is case-sensitive by default. Use the i flag for ASCII case-insensitive matching: [type="submit" i].
Styling form controls and links: button[type="submit"], input[type="email"], or a[target="_blank"].
Widely available: Chrome 4+, Firefox 2+, Safari 3.1+, Edge 12+, IE 7+. The i case flag needs Chrome 49+, Firefox 47+, Safari 9+, Edge 79+. It is a browser CSS selector, not a Node.js API.

Next: [attribute|=value]

Match an exact value or a value followed by a hyphen (language codes).

hyphen selector →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful