78

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"> 
4
  • can you give more information on the situation you would use this? Commented Jul 20, 2011 at 14:59
  • 4
    This just became a "popular question" and I wish I remembered why I even wanted to do this :) Commented Nov 28, 2012 at 19:19
  • I believe this was a situation where I could not modify the HTML, but only "side-load" some CSS. Based on the date, it may have been customization to CA Service Catalog. FWIW. ¯\_(ツ)_/¯ Commented Mar 11, 2020 at 14:57
  • Useful for making userstyles. Commented Nov 20, 2024 at 22:52

1 Answer 1

167

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.

Sign up to request clarification or add additional context in comments.

1 Comment

As usual, some versions of IE are known to have bugs with CSS3 attribute selectors. The SitePoint Reference is useful: reference.sitepoint.com/css/css3attributeselectors