Advanced Attribute Selectors

By Lola, the Web Dev Fu Master

Selector Syntax

Learn how to select like a boss!

  1. [attr^='value'] - Selects elements with the attribute value starting with 'value'
  2. [attr*='value'] - Selects elements with the attribute value containing 'value' anywhere in the string
  3. [attr$='value'] - Selects elements with the attribute value ending with 'value'
  4. [attr~='value'] - Selects elements with the attribute value containing 'value' separated by a space
  5. [attr|='value'] - Selects elements with the attribute value equal to 'value' exactly
  6. [attr|='value', 'other-value'] - Selects elements with the attribute value equal to either 'value' or 'other-value'
Selector Syntax Cheat Sheet

Real-World Examples

Cooking up attribute selectors like a pro!

  1. Real-World Example 1
  2. Real-World Example 2