Tags are <body>, <a>
, etc. They’re also known as “HTML elements” within the DOM. Attributes are things like title=, alt=, etc. Properties are parts of CSS, for instance background-color in <body style=”background-color: red; font-weight: bold;”>. Those are the 3 things people get mixed up most often.
alt is a required attribute. Title isn’t required, but I recommend including title. Title should be just a single word or phrase, whereas alt should be a sentence or two, describing what a missing image should result in, or a text-only browser or browser with images turned off should see. For some unimportant images you could put in alt=””, or navigation images, something like alt=”[Downloads]”. In the case of navigation images, you could make the title title=”click here to download”, since even though there is no rule on this in the specification, browsers generally honor title over alt when showing a tooltip/titletip (text that appears in a yellow box when you hover over an image). An example valid <img> tag would be:
<img src="images/gecko.png" alt="[ A picture of a gecko clinging to the wall, and a blowup of the microscopic hairs that help the gecko stay connected to it via van-der-walls forces]">
If you wanted to make a navigation link, you could do:
<a href="articles.html"><img src="images/nav/articles.png" alt="[Articles]" title="Click here to view articles"></a>
For bullets, you could do:
<img src="bullets.gif" alt="->">
For smilies:
<img src="smiley.gif" alt=":-)">
If the image isn’t important, like one some people use to clutter up their pages with animations, you could do:
<img src="annoyinganimatedgif.gif" alt="">
Take the second half of this comment, paste it into a blank html file, and look at it in Firefox to see the correct behavior. Since the images aren’t there, it’ll show the alt. Try hovering over the navigation link, and you’ll see the tooltip.
I can’t think of too many cases where you’d want alt to be an empty string, except for decorative images that don’t add any useful content.
See Hixie’s evil test for more info.