CSS [attr~=value] Selector

What is CSS [attr~=value] Selector?

CSS [attr~=value] Selector matches all elements whose have attr attribute and value contain like "value".

Syntax

This syntax apply to select every element whose have attr attribute and value contain like "value".

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

Example

Select every element whose have whose have href attributes and value contain like "http://www..com" to apply CSS style.

 <!DOCTYPE html> <html> <head>   <title>CSS [attr~=value] Selector</title>   <style type="text/css">     a[href~="http://www..com"] {         background:yellow;     }   </style> </head> <body>   <a href="http://www..com"></a>    <br />    <a href="http://webtuts..com">WebTuts</a> </body> </html>

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.