Skip to main content

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:

javascript
GET /img/photo.jpg

If 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:

html
<img src="notfound.jpg" alt="Photo temporarily unavailable">

The screen will show:

javascript
Photo temporarily unavailable

Benefit:

  • the user understands that there was supposed to be an image;
  • screen readers can read this text aloud;
  • search engines take alt into account during indexing.

4. Example without alt

html
<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:

SituationWhat the browser does
Image foundLoads and shows the picture
File not found (404)Shows a "broken image" icon
alt specifiedDisplays the text from alt instead of the picture
alt missingJust empty space
Format corruptedDisplay 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 ready
Premium

A concise answer to help you respond confidently on this topic during an interview.