How to add an image in HTML (and why it breaks when you share the page)
The img tag, how to write the src path, sizing and alt text, the usual reasons an image shows as a broken icon, and how to keep images in a page you share.
An image is not stored inside an HTML page. The page holds an <img> tag that points at the image file, and the browser fetches that file when it draws the page. Most broken images come down to that pointer.
Add the img tag
Put this inside <body> where the image should appear:
<img src="photo.jpg" alt="Front of the shop at night">
src is the path to the image file. alt is the text shown if the image cannot load, and the text screen readers read out. The tag has no closing tag. Save the file and reload the page in the browser.
Write the src path from where the HTML file sits
- ✓Same folder: src="photo.jpg".
- ✓In a subfolder: src="images/photo.jpg".
- ✓One folder up: src="../photo.jpg".
- ✓An image on another site uses its full https:// address, such as src="https://example.com/logo.png".
- ✓Do not use a path from your own disk, such as C:\Users\... or /Users/.... It works on your computer and nowhere else.
Set the size
Add width and height in pixels so the page does not jump when the image loads:
<img src="photo.jpg" alt="..." width="800" height="533">
To make it shrink on phones, add this to your CSS: img { max-width: 100%; height: auto; }. The image then fits narrow screens and keeps its proportions.
Resize large photos before you add them. A 5 MB camera photo shown 800 pixels wide makes the page slow for everyone who opens it; export it at the size you display it, as JPEG or WebP.
When the image shows a broken icon
- ✓Open the browser console (F12, or Cmd+Option+J in Chrome on a Mac). A "Failed to load resource" line shows the exact path the browser tried.
- ✓Check the spelling and case. Photo.JPG and photo.jpg are different files on most web servers, even if your laptop treats them the same.
- ✓Check the real extension. A file named photo.png may actually be photo.png.webp, and Windows may hide it.
- ✓Check spaces in the file name. Rename my photo.jpg to my-photo.jpg rather than relying on the browser to handle the space.
- ✓An image linked from another site can be blocked by that site, or removed later. Host your own copy if it matters.
- ✓An http:// image on an https:// page is blocked as mixed content. Use the https:// address.
Before you share the page
The <img> tag points at a separate file. Send only the .html file, by email, chat or upload, and the other person sees broken image icons with your alt text where the pictures should be.
Three ways to keep the images:
- ✓Use images that are already online, with full https:// addresses in src.
- ✓Embed each image into the HTML as a data: URI, so the one file carries the picture. This suits a few small images; it makes the file larger. See making an HTML file self-contained.
- ✓Host the page and send a link, with images either embedded or on https:// addresses.
Share it as a link
With FileShare Pro you upload the .html file from the dashboard, copy the link and send it. It opens as a page in any browser, on phones too, and the person opening it needs no account. If you change the page later, upload the new version to the same link instead of sending a new file. Sign up free to share your first page.
Frequently asked
Add <img src="photo.jpg" alt="description"> inside <body>, with src set to the path of the image file relative to the HTML file, or to a full https:// address.
Usually the src path is wrong, the file name or case does not match, the extension is different from what you typed, or the image is http:// on an https:// page. The browser console shows the path it tried.
Set width and height on the img tag, or use CSS such as img { max-width: 100%; height: auto; } so it scales with the screen. Resize the file itself too, so the page loads quickly.
The images are separate files that were not sent. Use https:// image addresses, embed the images as data: URIs, or host the page and send the link.
Drop the file, copy the link — live in seconds, free plan included.
Start sharing free