By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,411 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,411 IT Pros & Developers. It's quick & easy.

What is the different between "title" and "alt" for html tag "img"?

P: n/a
Hi all,
It is a newbie's question about html tag "img".
The attributes "title" and "alt" for "img" seems having the same
function. So what is the main difference between them?
Can i use them at the same time and set different values?

Thank you for suggestions!
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Quoth the raven Lian:
Hi all,
It is a newbie's question about html tag "img".
The attributes "title" and "alt" for "img" seems having the same
function. So what is the main difference between them?
The alt attribute is an 'alternative' to the image, and is what the
browser shows if images are turned off, or the visitor is using a text
browser. One popular operating system component masquerading as a
browser also displays the alt text as a "tooltip" if hovered (and if
there is no title attribute).

The title attribute is generally for additional descriptive text to go
along with the image. This is where you place text you want to display
in the "tooltip".
Can i use them at the same time and set different values?


By all means.

--
-bts
-This space intentionally left blank.
Jul 23 '05 #2

P: n/a
In comp.infosystems.www.authoring.html Lian said:

It is a newbie's question about html tag "img". The attributes "title"
and "alt" for "img" seems having the same function. So what is the
main difference between them?


alt = text [CS]
For user agents that cannot display images, forms, or applets, this
attribute specifies alternate text. The language of the alternate text
is specified by the lang attribute.
http://www.w3.org/TR/html401/struct/....html#adef-alt

title = text [CS]
This attribute offers advisory information about the element for which
it is set.
[...]
Values of the title attribute may be rendered by user agents in a
variety of ways. For instance, visual browsers frequently display the
title as a "tool tip" (a short message that appears when the pointing
device pauses over an object). Audio user agents may speak the title
information in a similar context. For example, setting the attribute on
a link allows user agents (visual and non-visual) to tell users about
the nature of the linked resource:
http://www.w3.org/TR/html401/struct/...tml#adef-title
Web Content Accessibility Guidelines 1.0
Checkpoints: 1.1 Provide a text equivalent for every non-text element
(e.g., via "alt", "longdesc", or in element content). This includes:
images, graphical representations of text (including symbols), image map
regions, animations (e.g., animated GIFs), applets and programmatic
objects, ascii art, frames, scripts, images used as list bullets,
spacers, graphical buttons, sounds (played with or without user
interaction), stand-alone audio files, audio tracks of video, and video.
[Priority 1]
http://www.w3.org/TR/WCAG10/wai-page...ext-equivalent

Use of ALT texts in IMGs
http://ppewww.ph.gla.ac.uk/~flavell/alt/alt-text.html

The "tooltip" effect and the title attribute
http://www.cs.tut.fi/~jkorpela/html/alt.html#tooltip
--

v o i c e s o f t h e l i t t l e
Jul 23 '05 #3

P: n/a
On Fri, 29 Oct 2004 11:39:53 +0800, Lian <da**@dfaf.com> wrote:
The attributes "title" and "alt" for "img" seems having the same
function. So what is the main difference between them?
In theory, (as others have posted) the difference is that one's an
annotation to an image (title) and the other (alt) is an alternative
for when the image isn't shown.

In practice, the difference depends on browser variations between IE
and FireFox.

IE 4 (4 ?) started to show the alt text as a floating tooltip. It
wasn't _wrong_ to do this, although a better implementation would have
used the new title attribute. The feature was popular and it probably
encouraged use of alt attributes when they'd have been ignored
entirely if it were just for their real purpose.

The recently popular Firefox though takes a different approach. This
is no more "correct", as the HTML spec is generous. Firefox _only_
uses the title attribute to display a tooltip, even when there's an
alt but no title. Obviously the best behaviour for both browsers would
have been to use title correctly in the first place, and (debatably)
to use alt instead if that was the only one available.

So if you carry on authoring according to last year's impression of
"best practice" (using alt religiously and ignoring title) then
you're now going to get a surprise from Firefox -- your tooltips
disappear.

So if you want tooltips for both IE and Firefox, you have to put them
in twice.
Can i use them at the same time and set different values?


Yes. This is good practice, although tedious. Set both though, even
if they're just the same because you don't have time to do the
copywriting to make them different,

There _may_ be a page reader out there that responds clumsily to
simultaneous use. If they're both used together than a user agent
(speech or visual) shouldn't ever render both attributes
simultaneously, just because they were both supplied. I don't know
much about readers, but I'd appreciate feedback if anyone knows of
one?

--
Smert' spamionam
Jul 23 '05 #4

P: n/a
Andy Dingley wrote:
IE 4 (4 ?) started to show the alt text as a floating tooltip. It
wasn't _wrong_ to do this, although a better implementation would
have used the new title attribute. The feature was popular and it
probably encouraged use of alt attributes when they'd have been
ignored entirely if it were just for their real purpose.


Unfortunately, IE's behavior tended to encourage abuse of the alt
attribute. It probably would have been better if MS had not implemented
alt as tooltip. And if they had implemented title as tooltip, all the
better, since authors would have flocked to title, using it for its
intended purpose instead of abusing alt. After all, alt is an
accessibility issue, while title is merely a means to provide "advisory"
information.

--
Brian (remove "invalid" to email me)
Jul 23 '05 #5

P: n/a
On Sat, 30 Oct 2004, Andy Dingley wrote:
On Fri, 29 Oct 2004 11:39:53 +0800, Lian <da**@dfaf.com> wrote:
The attributes "title" and "alt" for "img" seems having the same
function.
HTML is markup. The markup is descriptive. It's the browsers which
take that markup and do something with it. That "something" is called
"rendering". This partitioning of the problem space is an important
feature of the design of HTML, in my opinion, and seems to me to be
missing in the above-quoted remark.

In order to find out what the "title" and "alt" attributes were meant
for, it's no use looking at the behaviour of a few browsers - you need
to look at the specifications (of HTML) and guidelines (e.g web
accessibility content authoring guidelines). You're then in a
position to evaluate how well various browsers implement those
guidelines in their various rendering modes.
In theory, (as others have posted) the difference is that one's an
annotation to an image (title) and the other (alt) is an alternative
for when the image isn't shown.
Agreed.
In practice, the difference depends on browser variations
I'd have to disagree. You're supposed to author documents in
accordance with guidelines, not by targetting at specific browser
variations.
between IE and FireFox.
There *are* other browsers...
IE 4 (4 ?) started to show the alt text as a floating tooltip.
Let's not get bogged down in detail, but I don't think that behaviour
was in any way exclusive to InternetExploder.
It wasn't _wrong_ to do this,
I know at least one purist who says it /was/ wrong: browsers have no
business displaying -alternative- text while the image is being
presented. That's what -alternative- means, after all: either the
one, or the other. At least not as their default behaviour
(accessibility guidelines *for client agent design* would suggest
making the alternative text an available *user option* in the browser,
for those who feel they want/need it - and we know one who says that
he does).
although a better implementation would have used the new title
attribute.
Indeed.
The feature was popular and it probably encouraged use of alt
attributes when they'd have been ignored entirely if it were just
for their real purpose.
But a very mixed blessing, since some entirely unsuitable alternative
texts were being chosen as a consequence of misinterpreting the role
of this attribute as being supplementary tool-tip information, instead
of mandatory alternative information.

IMNSHO, the presence of an inappropriate alt attribute is often worse
- sometimes significantly worse - than the offence of having none at
all.
The recently popular Firefox though takes a different approach. This
is no more "correct", as the HTML spec is generous.
Hixie has some well-argued reasoning:
http://www.hixie.ch/advocacy/alttext

Not everyone agrees with his conclusions, but I think it's entirely
fair to say that at least he's presented the reasoning in an open and
logical fashion. In fact I find myself in agreement with most of what
he says, and any disagreements I have are fairly specialised.
Firefox _only_ uses the title attribute to display a tooltip, even
when there's an alt but no title.
This is the right thing to do, IMHO.
Obviously the best behaviour for both browsers would
have been to use title correctly in the first place,
Theoretically, yes. Except that, for a long time, authors were
hampered by the wide usage of Netscape 4, which failed to render the
title attribute. However, I think it's fair to say that even authors
who care that their content is still browseable on Netscape4, no
longer consider that browser to be worth further consideration on
subtle details of presentation.
and (debatably) to use alt instead if that was the only one
available.
On this point I think Hixie's conclusion is better. One shouldn't
tempt authors to choose inappropriate -alternative- texts by
presenting them as -tooltips-.
So if you carry on authoring according to last year's impression of
"best practice" (using alt religiously and ignoring title) then
you're now going to get a surprise from Firefox -- your tooltips
disappear.
Rightly so...
So if you want tooltips for both IE and Firefox, you have to put them
in twice.
Eh? Given that we seem to agree that title= is the theoretically
correct place for tooltips, you only have to put them in once, for
quite a range of browsers. This is -not- an alternative to providing
"appropriate"[1] alternative text, in its proper place: that provision
is made mandatory by the guidelines, but only the context can be
decisive as to whether the chosen -alternative- text was apt.
Can i use them at the same time and set different values?


Yes. This is good practice,


Absolutely.
although tedious.
As "Callie" said to me, many years back now:

Many authors haven't figured out exactly what they are trying to
present; they don't know what it is about the image that's important
to the page's intended audience. The reason you can't figure out why
their alt [texts] aren't working is that they don't know why the
images are there.

Choosing the (mandatory) alternative text -should- be no big deal, in
the majority of cases, for an author who knows what the page is trying
to communicate to the reader: it just needs to become a habit. It's
got almost nothing to do with - in the majority of cases - appropriate
selection of optional "short supplementary text" (to precis the
guidelines), intended to be presented as an optional tooltip etc.
Set both though, even if they're just the same because you don't
have time to do the copywriting to make them different,


I wouldn't choose that as an authoring guideline, frankly.
Occasionally, it might just turn out to be the right answer, but I'd
rather reason my way there, in a particular instance, based on some
well-founded authoring guidelines.

all the best

[1] where "appropriate" sometimes means alt="" or alt=" "
Jul 23 '05 #6

P: n/a
On Sat, 30 Oct 2004 16:15:13 +0100, Andy Dingley
<di*****@codesmiths.com> declared in
comp.infosystems.www.authoring.html:
In practice, the difference depends on browser variations between IE
and FireFox.
AFAIK IE is the only ("common") browser that exhibits the behaviour you
mention.
IE 4 (4 ?) started to show the alt text as a floating tooltip. It
wasn't _wrong_ to do this,
I disagree. The fact that alt text is supposed to be an "alternative"
implies that the 2 are mutually exclusive. So a UA shouldn't ever render
both at the same time.
although a better implementation would have
used the new title attribute.
Agreed.
The recently popular Firefox though takes a different approach. This
is no more "correct", as the HTML spec is generous.
Again, I disagree. We had a discussion about this recently in (IIRC)
alt.html too, so I don't really feel like going into a lot of detail
here.
Firefox _only_
uses the title attribute to display a tooltip, even when there's an
alt but no title.
As do most other browsers.
So if you want tooltips for both IE and Firefox, you have to put them
in twice.
Not so. If both alt and title are present, IE will display the title
text as the tooltip, not alt. So title is the only one necessary for
tooltips.
Yes. This is good practice, although tedious. Set both though, even
if they're just the same because you don't have time to do the
copywriting to make them different,


Like Alan, I disagree with this too. The alt text is supposed to be an
alternative to the image, the title is supposed to give additional
(non-crucial) information. On some occasions the two _may_ need to be
the same, but this would be very rare.

--
Mark Parnell
http://www.clarkecomputers.com.au
Jul 23 '05 #7

P: n/a
Mark Parnell <we*******@clarkecomputers.com.au> wrote in message news:<d2*****************************@40tude.net>. ..
AFAIK IE is the only ("common") browser that exhibits the behaviour you
mention.


I believe Netscape 4.x did as well, but it's not really "common" any more.

--
Dan
Jul 23 '05 #8

P: n/a
Mark Parnell wrote:
The alt text is supposed to be an alternative to the image, the title
is supposed to give additional (non-crucial) information. On some
occasions the two _may_ need to be the same, but this would be very
rare.


Perhaps not so rare. An online art gallery might use identical alt and
title attributes for images.

--
Brian (remove "invalid" to email me)
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.