img height="" width="" - undefined?

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

Threaded View
Dear Experts,

It looks as if the HTML4 spec does not define a meaning for empty height
and width attributes in an IMG element.  Moz seems to ignore them, while
IE7 sets the dimension to 1 pixel (or something like that).

I have a vague recollection that "" did have a defined meaning at some
point in the past, but maybe I am mis-remembering.  Can anyone confirm?

I have encountered this in some third-party PHP code that I'm using on
my web site, which seems to not work for an IE7 user.

Regards,  Phil.

Re: img height="" width="" - undefined?

Phil Endecott:

Quoted text here. Click to load it

An empty height or width attribute is an error because height and
width, if specified, must have a length (either a pixel value or a
percentage).  The HTML4.01 specification doesn't say how user-agents
should handle errors, but I think ignoring the empty value is
reasonable error recovery.

With error recovery like that, small wonder MS Explorer crashed.


Re: img height="" width="" - undefined?

On 11/26/2007 4:42 AM, Phil Endecott wrote:
Quoted text here. Click to load it

While the height and width attributes are recommended, they may be
omitted.  I think omitting them would be better than leaving empty sizes.

The reason that these attributes are recommended is that they speed up
the rendering of a Web page.  Browsers generally use these attributes to
allocate space for the image on the rendered page before the image
itself is available from the server.  Without the attributes, some kind
of default space is allocated because the image's size is still unknown.
 Then, when the image is available, the page must be re-rendered for the
actual size of the image.

With dynamically generated pages, however, even the image itself might
not yet known when the page starts to render.  Thus, its size cannot be
predetermined for the height and width attributes.

David E. Ross

Natural foods can be harmful:  Look at all the
people who die of natural causes.

Re: img height="" width="" - undefined?

and talented Phil Endecott broadcast on comp.infosystems.www.authoring.html:

Quoted text here. Click to load it

I believe you are misremembering or confusing something.  Possibly you are
thinking of the ALT attribute.  For that, an empty value is recommended for
purely decorative images (e.g. scroll work).  This can be interpreted by the
user agent so as to avoid junking up a text screen with some default ALT
text it might otherwise include if this required attribute were missing.
I'm not too crazy about the example in the spec.  It (correctly) suggests
that if an image is purely decorative, ALT="" should be prefered to ALT="red
ball".  However, if you use the image to mean "Don't", "Bad Example", or
"Stop", those should be the value of ALT.

However, I do not recall and cannot of think of an reasonable use for an
empty height or width attribute.  These are not required attributes, and
they default to the natural size of the object.  But not supplying an
optional attribute and supplying it with an empty value are two different
things.  An empty value has to be an error, and what various user agents do,
if anything, to attempt to recover from this error is likely to vary from
agent to agent.

From the Bad Idea Hall of Fame are various schemes for pre-caching images.
Most such schemes used at least 1x1 for the 'hidden' images, but perhaps you
read some guy's plan to use empty dimensions for this purpose.  I think I
have hinted 'precaching' is a really Bad Idea, and probably wouldn't work
this way anyway.

Quoted text here. Click to load it

It's an error.  It cannot be expected that different browsers will each
handle it the same way.

Lars Eighner <
                         Countdown: 420 days to go.

Site Timeline