HTML File Paths
HTML File Paths: Linking Assets Without Broken URLs
An HTML file path tells the browser where to find an image, stylesheet, script, or another page. Choose the wrong type of path, and you get broken images, unstyled pages, and 404 errors, usually right after you move a page into a subfolder or deploy to a server.
This guide explains the three kinds of HTML file paths, when to use each, and the case-sensitivity trap that makes a site work on your laptop but fail online.
The Three Types of HTML File Paths
Relative paths
A relative path is resolved from the folder of the current HTML file. Think of it as directions from where you are standing.
photo.jpg looks in the same folder.
images/photo.jpg steps into a subfolder named images.
../css/main.css goes up one folder, then into css. Each extra ../ climbs one more level.
Relative paths are handy for small sites, and for projects you might move as a whole, because the links keep working as long as the folder structure stays the same.
Root-relative paths
A root-relative path starts with a forward slash, such as /images/photo.jpg. It always resolves from the root of the site, no matter how deep the current page is. That makes it a reliable choice for shared assets on multi-page sites. One caution: if you open the file straight from your computer (a file:// address), the slash points to your drive's root, not your project, so test with a local server instead.
Absolute URLs
An absolute URL includes the protocol and domain, such as https://cdn.example.com/app.js. Use it for resources on other hosts, like a CDN or an external documentation page.
HTML File Paths in a Working Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML File Paths Demo</title>
<!-- Root-relative: works from any nested page -->
<link rel="stylesheet" href="/assets/css/main.css">
</head>
<body>
<!-- Same folder as this HTML file -->
<a href="contact.html">Contact (same folder)</a>
<!-- One folder up, into a shared images directory -->
<img src="../images/diagram.webp" alt="Architecture diagram" width="480" height="270">
<!-- External absolute URL -->
<a href="https://developer.mozilla.org" target="_blank" rel="noopener noreferrer">External docs</a>
</body>
</html>The stylesheet link uses a root-relative path, so it works whether this page lives at /index.html or /tutorials/html/lesson/intro. The image uses ../ to reach a sibling images folder. The width and height attributes reserve space so the layout does not jump while the image loads. See our lessons on HTML images and HTML links for more on those elements. The rel="noopener noreferrer" on the external link is good practice with target="_blank", as MDN explains.
How to check that a path works
Open your browser's DevTools, go to the Network tab, and reload the page. Any file path that fails shows a red 404 entry, and clicking it reveals the exact URL the browser requested. Compare that URL with the file's real location. The Chrome DevTools network guide shows how.
Why Case Sensitivity Breaks File Paths
Windows and macOS file systems usually ignore letter case during local development, so Avatar.WEBP can match avatar. webp on your laptop. Many Linux web servers treat the two as different files, so the same link returns a 404 after deployment. Exact behavior depends on the server and file system, so the safe habit is to use lowercase folder and file names, with hyphens instead of spaces (team-photo.webp, not Team Photo.WEBP).
Common File Path Mistakes
Linking to a local drive path. A path like C:\Users\Name\... only exists on your own computer. Visitors cannot load it, so copy the file into your project and use a relative or root-relative path.
Using relative CSS paths on nested routes. On a URL such as /tutorials/html/lesson/intro, a link to styles.css is resolved against /tutorials/html/lesson/, not the site root. Use /styles.css instead. If the page URL does not end with a slash, the browser resolves against the last folder in the path, which is a common source of confusion with framework routes.
Using backslashes. Web URLs use forward slashes /. Windows-style \ may appear to work in some browsers, but it is not valid, so avoid it.
Spaces and special characters in file names. These must be encoded in URLs, such as %20 for a space. Renaming the file is simpler.
Moving files without updating links. After reorganizing folders, search your project for the old file name and update every reference.
Frequently Asked Questions
What does ../ mean in an HTML file path?
It tells the browser to go up one parent folder from the current file's location before looking for the next folder or file.
When should I use root-relative paths that start with /?
Use them on multi-page sites and frameworks, so shared assets such as /images/banner.webp load correctly from any nested URL. Avoid them if the site will be hosted in a subfolder (for example, example.com/blog/), because the leading slash would skip that folder.
What is the difference between a relative and an absolute path?
A relative path depends on the current page's location. An absolute URL contains the full protocol and domain and works from anywhere.
Why does my image work locally but show as broken online?
The most common causes are letter-case differences in the file name, a path that points to a local drive, or a relative path that resolves differently on a nested URL. Check the Network tab for the exact failing request.
Can I use ./ in a path?
Yes. ./photo.jpg means the same folder and works the same as photo.jpg.
Conclusion
Use relative paths for nearby files, root-relative paths for shared site assets, and absolute URLs for outside resources. Keep file names lowercase, use forward slashes, and check the Network tab when something fails to load. For the next step, learn how the HTML <img> element and HTML <link> for CSS use these paths.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.