It is to put the description of what the image contains. It will be shown in place of the image if it can not be displayed. Useful for:
- make content easier to index, so it's for SEO,
- show something informative if the browser does not load the image for some reason or is slow,
- be able to report something to anyone with visual impairment.
The latter is important because reading software for those who are visually impaired can read what is written and "speak" to the person. There is no way to "tell" the person what the image is, you can only do it with a description.
Many people think that everything will always work, but there are several reasons why the image should not be displayed:
- has browser that can not show the image, it is textual,
- the browser can be configured not to display images,
- has a network that can block the location where the image is located,
- the image may no longer exist where you were and you do not notice,
- There may be several errors in the middle of the process,
Do not use space to put the name of the image or something less useful. The text should describe the image as best as possible to meet these requirements stated above. If necessary you can put a long text, but this is not always necessary, you do not need to make an artistic critique of the image :). If there is conflict between the goals, do your best to address the most important and try to help the others.
Do not use if the image is merely decorative, use
<alt = ""> in these cases, only images important to the general context of the page will require this. Be sure to use this form so that the browser does not show anything, so you do not try to describe it as having an image there, which in fact would only be useful for the page rendered completely.
The appropriate example is what is in the question itself :) It does not have much secrecy.
MDN Documentation .
Here on the site you can do this when you add an image and few do, that's bad.