CSS hide all images with matching SRC attribute

Devil's Advocate picture Devil's Advocate · Jul 20, 2011 · Viewed 60.9k times · Source

Is it possible to create a CSS rule that would apply a style to any IMG tag with a SRC that contained a specific string, say "hideme"? For instance, if I had the following 3 images on a page it would hide the second one?

<img src="images/test1.png">
<img src="images/hideme.gif">
<img src="images/test3.jpg">

Answer

BoltClock picture BoltClock · Jul 20, 2011

Use this CSS3 attribute selector:

img[src*="hideme"] {
    display: none;
}

I'd prefer to use a hideme class instead, but if you must hide an image based on its src attribute, the above is fine.