CSS [attr|=value] Selector

What is CSS [attr|=value] Selector?

CSS [attr|=value] Selector matches all elements whose attribute value beginning with exactly "value" word immediately followed by "-".

Syntax

This general syntax of element[attr|=value] Selector,

[attr|=value] {
  property: value;
  property: value;
  ...
}

Example

Select every element whose hreflang attribute value beginning with exactly "en" word immediately followed by "-".

<!DOCTYPE html>
<html>
<head>
  <title>CSS [attr|=val] Selector</title>
  <style type="text/css">
    a[hreflang|=en] {
      background:yellow;
    }
  </style>
</head>
<body>
  <a hreflang="en" href="#">English International</a><br />
  <a hreflang="en-US" href="#">English US</a><br />
  <a hreflang="IN" href="#">Google</a><br />
  <a hreflang="fr" href="#">Frances</a>
</body>
</html>

Run it...   »

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 3+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 1.3+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.