Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML How to Make a Website Creating HTML Content Build the Footer

Hezi Debby
Hezi Debby
4,236 Points

alt inside an image

I didn't understand the need for alt. in this class Nick said that now because we don't have a description we will write something inside(for example: "Twitter logo") but there's no difference if I leave it blank or write something down.

3 Answers

SERGIO RODRIGUEZ
SERGIO RODRIGUEZ
17,532 Points

The "alt" attribute is used primarily for 3 reasons:

1) To make your images accesible. There are software programs that read out web pages to visually impaired people. These software programs rely on the alt attributes to give the user an idea of the image being displayed.

2) To have a fallback text to show on the web page in case the image becomes not available. Sometimes you can decide to upload your code to a server and your images to another server for performance reasons. If by any chance the server where the images is down and someone visits your page, the text in the alt attribute will show up.

3) For SEO purposes (Search Engine Optimization). Google's, Bing's and other SEO crawlers are unable to "read" images, so they rely on the alt attribute to index what your image is about.

So, why does nick includes alt attributes only in some images?

If you have an image that is followed by a caption, the caption may "serve" as an explanation to your image. In this case, reasons 1, 2 and 3 for the alt attribute will be accomplished by the caption (although you may still use the alt attribute if you like).

Nick includes the alt attribute in the twitter and fb logos because they are not being followed by a caption.

Hope this helps,

Sergio

Wayne Priestley
Wayne Priestley
19,579 Points

Hi Hezi,

There are a few reasons for the alt description.
One is so that people who are visually impaired and use screen readers get an explanation of what the image is when its read out to them.
Another is so that if for some reason your image doesn't load there is still a description of what should be there.

Hope this helps.

Hezi Debby
Hezi Debby
4,236 Points

thank you very much Sergio and Wayne!