alt attribute not working

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, This must be simple but I don't see it. Given:

<!DOCTYPE html PUBLIC ?-//W3C//DTD XHTML 1.0 Strict//EN?

        <title>My Test Page</title>
        <script type=?text/javascript? src=?jquery-1.10.1.js?><
        <script type=?text/javascript?>
                // Your code goes here.
        <strong>This is my test page.</strong>
        <img src="smiley.gif" alt="Smiley face" height="42"

There is no file smiley.gif so the alt text should show. But it does

If I remove the height and width attributes it works, just:

<img src="smiley.gif" alt="Smiley face">  and the alt text shows.

But if I keep the height and width I get of course no pic but see a
"placeholder" and no alt text. Why?


Re: alt attribute not working

also, using FF 17.0.6 ESR on Win XP.

Re: alt attribute not working

On 6/15/13 12:23 PM, goldtech wrote:
Quoted text here. Click to load it

For Firefox and SeaMonkey, see Mozilla bug #41924 at
< .  Note that this
bug report is now 13 years old.  Fixing it depends on also fixing three
other bugs, ranging in age from 3 to 15 years.

David E. Ross

Concerned about someone (e.g., the government)
snooping into your E-mail?  Use PGP.
See my <

Re: alt attribute not working

2013-06-15 22:22, goldtech wrote:

Quoted text here. Click to load it

It?s a small difference in quotation marks that causes the problem.

Quoted text here. Click to load it

The use of jQuery is irrelevant here, especially since it is not really  
used. In general, problem demo pages should be minimal.

Quoted text here. Click to load it


This is a longstanding bug in many browsers: they treat the dimension  
attributes as applying to the alternate text presentation, too, and  
instead of letting that text overflow the box, they just omit it and  
display a broken image icon instead, if the text does not fit in.

Quoted text here. Click to load it

It also works if you use attributes that specify a large enough box,  
e.g. width="200" height="50". But this of course is not the right  
approach if the image (when available) should be in a different size.

What you see here is really ?Quirks Mode? behavior. In ?Standards Mode?,  
Firefox displays the alt text correctly in all cases.

In Quirks Mode, Firefox emulates old, broken browsers. Normally any  
doctype string conforming to HTML specifications puts Firefox to  
Standards mode (or at last to ?Almost Standard Mode?). So what is the  
problem here. It is the use of ?smart? quotation marks instead of  
"vertical" Ascii quotation marks in the doctype string (and later in the  
script elements, by the way). To the human eye, they may look rather  
similar. To a computer program, they are very different. Here the  
doctype string is not recognized, hence Quirks Mode is triggered.

For Quirks Mode phenomena in general, see


Re: alt attribute not working

Quoted text here. Click to load it

And in some not so old too, Safari 5.1.9 on Mac misbehaves in this  
respect no matter how kosher the doctype.


Re: alt attribute not working

2013-06-16 0:53, dorayme wrote:

Quoted text here. Click to load it

The situation is worse that I thought; I had not checked it for some  
time, and I naively expected Firefox standard mode to be typical browser  
behavior in dealing with alt attributes.

On Chrome, the alt text is not shown in any mode, even when the  
dimensions are not specified - unless you specify them as rather large  
(a height of 54px seems to be the minimum).

IE 10 always tries to render the alt text but only as far as fits into  
the dimensions if they are specified. In the original example case,
<img src="smiley.gif" alt="Smiley face" height="42"
IE shows just "S" and below it something that is probably part of some  
letter. For <img src=testxxx.png alt="foo" width=50 height=50> it shows  
"fo" on one line and "o" on the next.

Opera behaves like IE 10 except that it does not show a broken image  
icon and uses the entire area of the image for the alt text. In the  
original example case, it displays "Smile" and the left half of "y".

Why is this so? Presumably because browser vendors think that it is more  
important not to disturb the page layout than to display the alternate text.

Conclusions? Do not specify the dimensions of images (in HTML or in  
CSS), except for large image that have alt texts that will surely fit  
into the area, even when some space is consumed by the broken icon.

This will not help against the Chrome bug, though.


Re: alt attribute not working

Sat, 15 Jun 2013 23:13:46 +0300, /Jukka K. Korpela/:
Quoted text here. Click to load it

Firefox/Gecko users may set (<about:config>):

browser.display.force_inline_alttext = true

I have it set since ages.


Re: alt attribute not working

Mon, 17 Jun 2013 00:51:56 +0300, /Stanimir Stamenkov/:
Quoted text here. Click to load it

It appears to be mentioned in the Mozilla bug David E. Ross refers  
to in another reply to this thread:

See also:


Site Timeline