A broken image on a live site that worked perfectly during development is one of the most common beginner experiences, and the cause is nearly always a path written in the wrong form. There are three forms, they behave differently, and knowing which to use where removes the problem permanently.
Document relative paths
A document relative path is resolved from the location of the file containing it. No leading slash.
<img src="photo.jpg"> <img src="images/photo.jpg"> <img src="../images/photo.jpg"> The first looks in the same folder as the current page. The second looks in a subfolder of it. The two dots in the third mean go up one level first, and they can be chained to climb several.
These are portable, since the whole folder can be moved or renamed and the internal links continue to resolve. Their weakness is that the same path means different things on different pages, so a shared header cannot use them safely. Move a page one level deeper and every relative path inside it silently points somewhere else.
Root relative paths
A leading slash means start from the root of the site, ignoring where the current page sits.
<img src="/assets/images/photo.jpg"> <a href="/html/basics/">HTML Basics</a> This is the form to use for anything shared across a site: stylesheets, scripts, logos, navigation. The path is identical on every page regardless of depth, so one header include works everywhere.
The catch is the one that produces the classic bug. Opening a file directly from your hard drive means the root is the root of your drive, not your project, so every root relative path fails while every document relative path works. Upload to a server and the situation reverses. The fix is not to change your paths but to run a local server, which every language and editor provides in some form, so that local and live behave identically.
Absolute URLs
An absolute URL includes the scheme and domain and points at one exact location on the internet.
<a href="https://example.com/html/">HTML tutorials</a> Use these for external links, and for the handful of places where a full address is required regardless of context: canonical links, Open Graph images, sitemap entries and anything appearing in an email.
Do not use them for your own internal pages. Hardcoding your domain means every link breaks when you work on a staging copy, and moving between environments becomes a search and replace exercise across the whole codebase.
Case sensitivity is the hidden one
Most Linux servers treat file paths as case sensitive. Most Windows and Mac development machines do not. A file saved as Photo.JPG and referenced as photo.jpg therefore works locally and returns a not found error the moment it is uploaded.
This produces the most baffling version of the broken image problem, because the path looks correct and the file is visibly present. Adopting lowercase filenames throughout, with hyphens instead of spaces, removes an entire class of bug for no effort.
Spaces and characters in filenames
A space in a filename must be encoded in a URL, and while browsers usually cope, the result is fragile and unreadable. Underscores work but are treated differently from hyphens by search engines, which read a hyphen as a word separator. Hyphens are therefore the better default for anything public facing.
Avoid accented characters, ampersands and question marks in filenames entirely, since the last two carry meaning in a URL and will truncate the path.
Trailing slashes matter more than they appear to
A path ending in a slash is treated as a directory, and a relative path inside that page resolves from it. A path without one is treated as a file, and relative paths resolve from its parent. Mixing the two forms for the same page also creates two addresses for identical content, which is why the canonical link exists.
Protocol relative paths are obsolete
Older code sometimes omits the scheme and begins a path with two slashes, which tells the browser to use whichever protocol the current page is using. This was a workaround from the period when sites were partly secure and partly not. Now that encrypted connections are the default everywhere, it serves no purpose and creates a risk of loading a resource insecurely. Write the full scheme.
The diagnosis
When something does not load, open the network panel in your browser tools and look at the address that was actually requested. It shows the resolved path rather than what you typed, and the difference between the two identifies the mistake immediately, usually a missing leading slash or a folder level that is not where you assumed.