alt length

I was asked to write up some notes on the length of alt attributes.

I know that Steve Falkener did some research; I did some too, so this
incorporates some helpful comments from Steve a year or so ago.

(1) if alt doesn't fit in the space where the image would have gone:

Some Webkit browsers do not display the alt text at all; I don't know
whether they make it available for readers because I wasn't able to
test.

Firefox here by default truncates it, clipping the text to the size of
the image (if given) and does not wrap the text. But you can use the
CSS overflow property on img elements to change it so it no longer is
clipped.

If you don't specify height and width for your image in the HTML, the
browser will presumably use all of the alt text, but I didn't test
that: it's very common to include height and width because the page
renders much more quickly, without reflowing and jumping about as the
images load.

Part of the goal of HTML 5 was to document browser behaviour and get
this sort of incompatibility fixed. So probably we should decide what
*should* happen and document it.

(2) skip out

A related question is whether you can skip out of an alt attribute
being read out loud by a reader easily. I've heard different people say
different things, which might mean you can but not everyone knows how,
or that it varies by reader and/or browser, leading me to think its
isn't that easy.

If you can't, imagine a symbol like a letter-sized ankh cross occurring
40 times in a page about Egyptian symbolism with alt text like,
    "Picture of an ankh cross used as a symbol. The cross has an oblate
loop in the upper part replacing the top vertical part of the cross;
the lower vertical is longer than the upper. The cross is black on a
white background and was scanned by an Epson scanner at 1200dpi by
ImageScan Inc of Plethora, USA."

OK, that's extreme, but even alt="[ankh cross icon, text-sized]" would
seem reasonable in a content management system's image database and not
so good if you have to hear it 40 times.

Some Web publishing packages use the filename, but "img300001.dsc" is
even worse than "[ankh cross, text-sized]".

The [...] was a convention used in early Web days so you could tell
what was going on; it still seems common today even though I'm guessing
a program like Orca will say "open bracket .... close bracket" at you.

(3) hard length limit

Is there an actual upper bound on the length other than the amount of
memory on the computer? Do browsers truncate after 1024 character?
After a megabyte? After 127 character? I haven't tested this at all.

Since it's a plain string (an HTML attribute), it can't have paragraph
breaks, formatting, mathematics, Ruby annotations etc in it so I'm not
sure this one is an issue in practice -- if you run into a length limit
in the browser you were doing it wrong :-)


Liam

Received on Friday, 5 February 2016 07:36:00 UTC