Enable broken image placeholders in Firefox

Something that has always bugged me about Firefox is that if it encounters a broken image it doesn’t display an image place-holder. Instead it displays the alt attribute as in-line text. This can cause problems if your primary development browser is Firefox, as you may not notice broken images on a page.

For a while there has been an option in the config to display image place-holders while a page loads but not for broken images as on IE (yes I’m praising an IE feature!).

Image placeholders on load is set to ON by default, your can change this if you want by going to about:config and searching for ‘image’. The option your looking for is:

browser.display.show_image_placeholders

Just double click to change the value.

As I said before, this doesn’t affect broken images after the page has loaded, and after several searches it looks like the option just isn’t available to Fx users as a general setting. There is however a solution…

Firefox allows users to specify custom CSS to be applied to websites on a global basis, e.g if you want your default link colour on unvisited links to be black instead of the default blue.

You do this by making changes to your global content css file. You can find it at the following location (OS Specific – I’m on windows 7) ‘%appdata%\Mozilla\Firefox\Profiles\\chrome’ (if your on a domain you will need to edit it in your roaming folder), look for a file called ‘UserContent-example.css’ and rename it to ‘UserContent.css’, this will then be loaded by Firefox when it fires up.

Add the following CSS to the file and restart Firefox..
/* Enable image placeholders */
@-moz-document url-prefix(http), url-prefix(file) {
img:-moz-broken{
-moz-force-broken-image-icon:1;
width:24px;
height:24px;
}
}

Thats it… when you next come accross a broken/missing image, you will get a box the size you have defined in its place with the alt inside it.

Update:
I was asked if I could add a broken image in this post as an example to see the css tweak in action, so here it is -> <-

Tags: , , , , , ,

Enough of me, let me know your thoughts below...

  1. Uh. Turns out I had pasted that CSS rule in userChrome.css instead of userContent.css – https://bugzilla.mozilla.org/show_bug.cgi?id=672465#c6. Can you please delete BOTH my embarrassing comments now? Thanks.

  2. Gavin Gavin says:

    Hi Dan,

    I checked my comment spam and there’s nothing in there from you, akismet must have auto deleted it, strange??

    The image place holder is still working for me? Im using Fx6 tho so maybe it was a bug with 5.x, I didnt notice when I was using 5?

    My current BuildID: Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0 ID:20110713171652

  3. Not sure if my previous comment went through, because there was no feedback whatsoever from the blog.

    Re-submitting, this time without the link, in case some silly antispam engine caught it.

    This no longer works in Firefox 5.0. I’m sue that userChrome.css is read correctly because another rule there does work (enlarges the URL bar),
    #urlbar {
    font-size: 16px;
    }

    I’ve been liking other people to a StackOverflow page that discusses this issue (Google “StackOverflow Firefox non existing images IE”)

  4. Dan Dan says:

    Thanks for posting this. STUPID that FireFox doesn’t offer an image place holder in FireFox 4.

  5. Coffee Container Coffee Container says:

    Sweet trick! I am curious, though, when I add css to make a red border around it the border does not display, any ideas to make that piece work?

    • Gavin Gavin says:

      Im not sure, I guess the UI wont allow you to style that part of the element. I had a quick look but couldn’t get it to work either, if you manage to do it, let us know.

  6. pichoscosama pichoscosama says:

    Thanks for the fix.

  7. sikander sikander says:

    Brilliant, thanks!

  8. John John says:

    Adding the above CSS to UserContent.css worked for me! Thanks so much!!!

    (on a Mac, the chrome folder can be found under Library/Application Support/FireFox)

  9. Gavin Gavin says:

    Glad it helped you out 🙂

  10. Farhan Ahmad Farhan Ahmad says:

    This is exactly what I needed. Thanks for posting!