What happens if the image is not found at the specified path?
If the browser cannot find the image at the path specified in the src attribute, it will not complete the load and will perform fallback behavior:
1. The browser will try to load the image
It will send an HTTP request to the address specified in src:
GET /img/photo.jpgIf the server responds with an error (for example, 404 Not Found, 403 Forbidden, 500 Internal Server Error) or the file is physically missing, the browser will not be able to display the picture.
2. A "broken image" is displayed
Instead of the picture, the browser shows empty space or an error icon: usually a small icon with a cross, a torn file, or the text "image not found". Visually, it looks like this: such an icon, or empty space with an outline.
3. If the alt attribute is set, its text is shown
If the <img> element has an alt attribute, the browser will display this text in place of the unavailable image:
<img src="notfound.jpg" alt="Photo temporarily unavailable">The screen will show:
Photo temporarily unavailableBenefit:
- the user understands that there was supposed to be an image;
- screen readers can read this text aloud;
- search engines take
altinto account during indexing.
4. Example without alt
<img src="missing.jpg">If the file is not found, the user will see empty space or an error icon, but will not understand what was supposed to be there.
5. Behavior for different kinds of errors
- If the path is wrong → the browser cannot find the resource.
- If the format is corrupted → the browser cannot decode the image.
- If the server is unavailable → loading "hangs" and then is aborted.
In all cases the visual result is the same: the image is not displayed,
and alt is used (if present).
Summary:
| Situation | What the browser does |
|---|---|
| Image found | Loads and shows the picture |
| File not found (404) | Shows a "broken image" icon |
alt specified | Displays the text from alt instead of the picture |
alt missing | Just empty space |
| Format corrupted | Display error, failure icon |
In simple terms:
if the browser did not find the picture,
it shows nothing or an error icon,
and if you added alt,
it will display your text instead of the image.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.