HTML File Paths

Beginner
9 min read
Updated: Nov 2026
6 examples
src / href

Definition and Usage

An HTML file path describes where a file lives in your site’s folder structure (or on another server). You use paths whenever a page links to images, stylesheets, scripts, or other pages.

What are file paths for in an HTML tutorial?

Tell the browser how to fetch photo.jpg, styles.css, or about.html. Wrong paths cause broken images and 404s; correct paths keep assets working on localhost and production.

Where do paths appear?

In URL attributes: src on <img> / <script> / <iframe>, href on <a> / <link>, and similar attributes on forms and media.

When should you use each kind?

Prefer relative or root-relative paths for your own files. Use a full absolute URL when the resource lives on another domain (CDN or third party).

Best practice.

Relative paths are not tied to one domain. The same markup often works on your computer, staging, and the live site.

Case and spelling matter.

Many hosts treat Photo.JPG and photo.jpg as different files. Match folder and file names exactly.

URL vs path.

A full URL includes scheme and host (https://…). A path alone (/images/a.jpg or ../a.jpg) is resolved against the current page URL.

HTML File Path Syntax

Common forms (shown with <img>):

paths.html
<img src="path-or-URL" alt="…">
HTML
<!-- Absolute URL (full address) -->
<img src="https://example.com/images/photo.jpg" alt="Photo">

<!-- Same folder as the HTML file -->
<img src="photo.jpg" alt="Photo">
<img src="./photo.jpg" alt="Photo">

<!-- Subfolder of the current folder -->
<img src="images/photo.jpg" alt="Photo">

<!-- One folder up, then into images/ -->
<img src="../images/photo.jpg" alt="Photo">

<!-- From the site root -->
<img src="/images/photo.jpg" alt="Photo">

The same path strings work in href, src on scripts, and other URL attributes.

Core HTML Concepts

How each path form is resolved:

PathMeaning
https://example.com/img/a.jpgAbsolute URL — full address including host
photo.jpg or ./photo.jpgSame folder as the current page
images/photo.jpgimages folder inside the current folder
../images/photo.jpgUp one folder, then into images
/images/photo.jpgRoot-relative — from the website root

Absolute URL vs path

Absolute URLRelative / root path
Includes domain?YesNo
Depends on page folder?NoRelative: yes · Root (/): no
Best forCDN / other sitesYour own site files

How to Choose a File Path

Practical habits for reliable links.

  1. Sketch your folder tree (for example site/, site/images/, site/pages/).
  2. From the HTML file’s folder, decide: same folder, child folder, parent, or site root.
  3. Use ../ only as many times as you need to climb.
  4. Use /… for shared assets that every page should reach the same way.
  5. Use a full https://… URL for external hosts.
  6. Test after moving pages between folders—relative links often break first.
GoalPattern
Asset next to the pagesrc="logo.png"
Asset in a subfoldersrc="images/logo.png"
Climb then enter a foldersrc="../images/logo.png"
Sitewide assetsrc="/images/logo.png"
External / CDNsrc="https://cdn.example.com/logo.png"

Live Preview

Pick a path form and see how it is described relative to a sample folder layout.

Assume the HTML page is at /blog/post.html. The demo image uses a working placeholder URL.

Rendered page

HTML Examples

Six patterns: absolute URL, same folder, subfolder, parent folder, root-relative, and mixed assets on one page.

Example 1 — Absolute URL

HTML
<h1>Absolute file path</h1>
<img
  src="https://placehold.co/320x200/2563eb/white?text=Photo"
  alt="Demo photo"
  width="320"
  height="200">
Try It Yourself

How It Works

  1. https://… is a complete URL with host.
  2. Works from any page because it does not depend on folders.
  3. Use for CDNs and third-party images.
  4. See also the HTML Images tutorial.

Example 2 — Same Folder

HTML
<!-- HTML and photo.jpg live in the same folder -->
<img src="photo.jpg" alt="Team photo">
<img src="./photo.jpg" alt="Team photo">
Try It Yourself

How It Works

  1. Bare filename resolves next to the current page.
  2. ./ is optional and means the current directory.
  3. Moving the HTML without the image breaks the link.
  4. Simple pages often keep a few assets beside the file.

Example 3 — Subfolder (images/)

HTML
<!-- page.html and images/ are siblings -->
<img src="images/photo.jpg" alt="Landscape">
Try It Yourself

How It Works

  1. images/ is relative to the HTML file’s folder.
  2. Organize assets in subfolders to keep pages tidy.
  3. No leading slash — this is not root-relative.
  4. Nested pages deeper in the tree need different relative paths.

Example 4 — Parent Folder with ../

HTML
<!-- HTML is in pages/; image is in images/ next to pages/ -->
<img src="../images/photo.jpg" alt="Landscape">
Try It Yourself

How It Works

  1. ../ moves up one directory.
  2. Stack ../../ to climb two levels, and so on.
  3. Common when pages live in a pages/ or blog/ folder.
  4. Easy to break if you reorganize folders later.

Example 5 — Root-Relative Path

HTML
<!-- Always from the site root, no matter where the page lives -->
<img src="/images/photo.jpg" alt="Landscape">
<link rel="stylesheet" href="/styles/main.css">
Try It Yourself

How It Works

  1. Leading / means “from the site root.”
  2. Stable for logos and global CSS shared across deep folders.
  3. Local file:// opening can behave differently than a real server root.
  4. Subfolder deploys (site under /project/) may need a different base.

Example 6 — Mixed Paths on One Page

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>File paths demo</title>
  <link rel="stylesheet" href="/styles/main.css">
</head>
<body>
  <h1>Welcome</h1>
  <img src="../images/hero.jpg" alt="Hero banner">
  <p><a href="about.html">About (same folder)</a></p>
  <p><a href="https://example.com">External site</a></p>
  <script src="/js/app.js"></script>
</body>
</html>
Try It Yourself

How It Works

  1. Root-relative CSS and JS stay stable sitewide.
  2. ../images reaches shared media from a nested page.
  3. about.html is a same-folder relative link.
  4. https:// opens an external absolute URL.

Edge Cases & Pitfalls

Most “missing image” bugs are wrong relative paths after a folder move—not broken browsers.

move

Moving HTML without updating paths

Relative links are tied to the page location. After relocating a file, re-check every src and href.

slash

Confusing /images with images/

/images/ is root-relative; images/ is under the current folder. They resolve differently.

case

Case sensitivity on the server

Windows may forgive case; Linux hosting often does not. Match exact casing.

spaces

Spaces in file names

Prefer hyphens. If a name has spaces, encode them as %20 in URLs.

base

<base href> changes resolution

A <base> element rewrites how relative URLs resolve for the whole document. Use sparingly.

file

Opening via file://

Root-relative / paths expect a web server root. Prefer a local server when testing sitewide assets.

Browser Support

Absolute and relative URL resolution is part of how every browser loads HTML resources.

✓ Baseline · Widely available

HTML file paths

Browsers resolve src and href the same way across platforms. Correct paths—not special APIs—are what make assets load.

100% URL resolution
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
HTML paths Universal

Bottom line: Focus on the right path form for your folder layout—browser support for loading linked files is not the limiting factor.

Key Takeaways

  • Absolute URLs include the host; use them for other domains.
  • ./ and ../ navigate from the current page’s folder.
  • Leading / is root-relative from the website root.
  • Prefer relative paths for your own site when possible.

One line: Point src/href at the right place with a full URL, a relative path (./, ../, folders), or a root-relative / path—matching how your folders are laid out.

Frequently Asked Questions

A file path tells the browser where to find a resource—an image, stylesheet, script, or linked page. You write paths in attributes such as src, href, and action.
An absolute path (full URL) includes the protocol and domain, such as https://example.com/img/photo.jpg. A relative path is resolved from the current page’s location (or from the site root if it starts with /).
./ means the current folder (often optional). ../ moves one folder up. You can stack ../ to climb multiple levels before entering another folder.
A path that starts with / is resolved from the website’s root, not from the current page’s folder. Example: /images/logo.png always means site-root/images/logo.png.
Use a full absolute URL when the file lives on another domain (CDN, third-party host). Prefer relative or root-relative paths for your own site so links keep working across localhost and production.
Yes. The same absolute, relative, and root-relative rules apply to src on img/script, href on link/a, and similar URL attributes.

Practice in the editor

Open a Try It demo and compare absolute, relative, and root paths.

Open Try It editor →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful