HTML Tutorial
HTML File Paths
Relative, root, and absolute paths decide whether images and links actually load.
Why the path matters
src and href are instructions to fetch another file: an image, a stylesheet, a second page, a script. If the path is wrong, you get a broken image, a page with no CSS, or a link that 404s. The tag can be perfect. The address still has to point at a real file.
There are three common kinds of path: relative to this file, relative to the site root, and a full URL on the web.
Same folder and a subfolder
A path with no leading slash is relative to the HTML file you are in. cat.jpgmeans “the file named cat.jpg next to this page”. images/cat.jpg means “go into theimages folder beside this page, then take cat.jpg”.
Example
<!-- page.html and cat.jpg sit in the same folder -->
<img src="cat.jpg" alt="A grey cat">
<!-- page.html sits beside a folder named images -->
<img src="images/cat.jpg" alt="A grey cat">
<a href="images/gallery.html">Photo gallery</a>Relative paths move with the folder. If you keep page.html and images/ together, the picture still works when you copy the project to another computer.
From the site root
A path that starts with / is root-relative. It starts at the root of the site, not at the current file. /images/cat.jpg always means “images/cat.jpg at the top of this site”, whether the HTML file lives in / or in /menu/lunch/.
Example
<!-- From any page on the same site -->
<img src="/images/cat.jpg" alt="A grey cat">
<link rel="stylesheet" href="/css/site.css">
<a href="/about.html">About</a>Root paths are handy on a real website with a header reused on every page. They are awkward if you open the HTML file directly from disk (file://), because there is no site root — only a folder. For local files, prefer relative paths.
Absolute URLs
An absolute path includes the scheme and host: https:// and the domain. Use it for files that do not live in your project: a CDN stylesheet, an image on another site, or a link to someone else’s page.
Example
<a href="https://studygrid.example/html/intro">HTML intro</a>
<img src="https://example.com/images/cat.jpg" alt="A grey cat">
<script src="https://example.com/js/tiny.js"></script>Absolute URLs do not care which folder your HTML sits in. They do depend on the network and on the other host staying up. For your own images, keep files in the project and use a relative path.
One folder up with ..
.. means the parent folder. From pages/menu.html, ../images/cat.jpggoes up to the project folder, then into images.
Example
<!-- File: pages/menu.html -->
<img src="../images/cat.jpg" alt="A grey cat">
<a href="../index.html">Home</a>
<link rel="stylesheet" href="../css/site.css">Stack them if you must: ../../logo.png goes up two folders. Deep ../ chains are hard to read. A flatter folder tree, or root-relative paths on a server, stays clearer.
Path types at a glance
| Path | Type | Meaning |
|---|---|---|
cat.jpg | Relative | Same folder as this HTML file |
images/cat.jpg | Relative | Folder images next to this file |
../cat.jpg | Relative | One folder above this file |
/images/cat.jpg | Root-relative | From the site root |
https://example.com/cat.jpg | Absolute | Full URL on the web |
Spelling and case count. Cat.jpg is not cat.jpg on many servers. Match the real filename.
When a file does not load
- Check the filename and folder. Open the path in the browser or in your editor.
- If you used
/images/..., confirm you are on a server with a real site root. - If you used
../, count the folders from the HTML file, not from the project root. - For images, keep
altso a missing file still has a text fallback.
The StudyGrid editor at /html/try is a single preview document. Relative files on disk are not sitting next to that preview unless you paste a full https:// URL. Use absolute example URLs there, or tiny inline SVG, when you want a picture to show in the live pane.
Next: the head — charset, viewport, title, and where those stylesheet paths usually go.
Worked examples
The short listings above show the tag in isolation. These pages use the same markup on documents you would actually publish: a lab report, a clinic form, a timetable, a weather card.
HTML does not calculate. It names the pieces so a browser, a screen reader, and a search engine can tell a heading from a paragraph. The numbers below are classroom values — the same Ohm, pH, and pulse figures as the C track — now sitting in real page structure.
Preview them in the HTML editor at /html/try. Change a heading or a number and watch the page, not a print log.
Engineering
Where the loaf photo lives
Relative paths start from the current file. Root paths start with / and start from the site root. Absolute paths include the scheme and host.
Broken images are almost always a wrong path, not a wrong tag. Match the folder you actually deployed.
Example
<p>Same folder: <code>loaf.jpg</code></p>
<p>Up one folder: <code>../images/loaf.jpg</code></p>
<p>From the site root: <code>/images/loaf.jpg</code></p>Biology
A specimen image from the root
A root path still works if you move the HTML file to another folder. A relative path may break. Pick one convention per project and keep it.
Example
<img src="https://picsum.photos/seed/leaf/160/90" alt="Leaf specimen" width="160" height="90">
<p>This demo uses a full URL so the preview can load.</p>