Image paths and file locations
This lesson covers
- Organizing an images folder
- Relative and absolute src paths
- Naming image files
- Troubleshooting broken images
Short answer
The src of an image follows the same rules as link URLs. A relative path like images/logo.png starts from the current HTML file. A root-relative path like /images/logo.png starts from the site root. Most broken images come from a wrong folder, a typo, or uppercase letters that do not match.
Organize your images
my-site/
index.html
about/
index.html
images/
logo.svg
team/
ana-reyes.webp
Keep images in one images folder, with subfolders for groups. It makes paths predictable.
Writing src paths
| HTML file | Image | src |
|---|---|---|
| index.html | images/logo.svg | images/logo.svg |
| about/index.html | images/logo.svg | ../images/logo.svg |
| Any page | images/logo.svg | /images/logo.svg |
| Any page, image on a CDN | https://cdn.example.com/logo.svg |
Name image files well
- Lowercase letters only.
- Hyphens between words, no spaces.
- Describe the image:
pili-tarts-box.jpg, notIMG_20260315_0912.jpg. - Keep the extension correct: .jpg, .png, .webp, .svg.
Descriptive file names help you find files, and Google Images uses them as a small hint about the image.
Troubleshooting a broken image
- Right click the broken icon and choose Open image in new tab. Read the URL the browser tried.
- Check the folder exists and the file is there.
- Compare spelling and capital letters: Logo.PNG is not logo.png on most servers.
- Check the extension. A file saved as .jpeg will not load from .jpg.
- Open DevTools (F12), go to the Network tab, and look for red 404 errors.
Try it: spot the broken path
Three images are broken because of path or name mistakes. Read each src and fix it. Hint: compare with the file names listed in the comment.
Live preview
Quick quiz
Common mistakes
- Linking to files on your computer. src=“C:\Users\…” only works on your own laptop.
- Hotlinking other sites’ images. Their image may vanish, and it uses their bandwidth.
- Camera file names. IMG_1234 says nothing about the image.
Your action
Tick each item when you can do it. Your progress saves on this device.
Key terms
- Image path
- The location written in an img src.
- Hotlinking
- Embedding an image hosted on someone else's site.
- 404 error
- The server message when a file is not found.
- DevTools
- Browser tools for inspecting pages, opened with F12.
- CDN
- Content Delivery Network that serves files from servers near the visitor.
Questions beginners ask
Why does my image work locally but not online?
Usually letter case or a missing upload. Check both.
Should I use absolute paths for images?
Root-relative paths are fine on your own site. Use absolute URLs for images on another domain or CDN.
Can I put images in the same folder as HTML?
Yes, but a separate folder keeps bigger sites tidy.
Related lessons
Need a website built or fixed while you practice? The team at Remar Digital can help.