The alt attribute in an image should always be present - this is a requirement for accessible HTML.
The title attribute is optional.
- What is the alt attribute for?
- alt is an abbreviation for alternative; the text used for the alt attribute is a substitute (alternative) for the image when the image cannot be displayed. There are several reasons why an image may not be displayed, these include:
- Image is not available on the server - not on the server, incorrect link
- Browser does not support images - Lynx, Off by One browser
- User has configured the browser to not display images
- What is the title attribute for?
- The title attribute is used to provide rollover text when an image is hovered over.
- What is displayed in the browser?
- In modern browsers (including FireFox, IE7 and later, Opera, Safari) the following is rendered:
- If the image is not present, the alt text will be rendered, often in a box (image placeholder) the size of the missing image.
- If the image is present, the alt text will not be rendered.
- When the image (or image placeholder if the image is not present) is moused over the title text (if present) will be shown as a tooltip.