HTML File Paths: Complete Guide to Absolute and Relative Paths

Learn HTML file paths with simple examples. Understand absolute paths, relative paths, ./, ../, root-relative paths, folder structures, common errors, and best practices.

HTML File Paths

HTML file paths tell the browser where a file, image, stylesheet, JavaScript file, document, or another resource is located. They are an essential part of HTML because modern web pages rarely contain everything in one file. A webpage may need images from an images folder, CSS from a css folder, JavaScript from a js folder, or another HTML page from a different directory.

Understanding file paths helps you create websites that work correctly both on your computer and after they are uploaded to a web server.

What Is an HTML File Path?

An HTML file path is the location or address used to find a file.

For example:

<img src="images/photo.jpg" alt="A beautiful landscape">

Here, images/photo.jpg is the file path. It tells the browser to look for photo.jpg inside a folder named images.

File paths are commonly used with attributes such as:

  • src
  • href
  • action
  • poster
  • srcset
  • data-* attributes in some applications

Common HTML elements that use file paths include:

<img>
<a>
<script>
<link>
<iframe>
<video>
<audio>
<form>

Why Are File Paths Important in HTML?

A browser needs to know where external resources are located. If the path is incorrect, the browser cannot find the requested file.

For example:

<img src="images/logo.png" alt="Website logo">

If logo.png does not exist in the specified location, the image will not appear.

Similarly:

<link rel="stylesheet" href="css/style.css">

If the stylesheet is in another location, the CSS will not load.

Correct file paths therefore help ensure that:

  • Images display correctly.
  • CSS files load properly.
  • JavaScript files execute.
  • Links open the intended pages.
  • Videos and audio files work.
  • Documents can be downloaded or opened.
  • Websites behave consistently on different environments.

Types of HTML File Paths

HTML file paths are generally divided into two major categories:

  1. Absolute file paths
  2. Relative file paths

There is also an important distinction between paths that use a web URL and paths that point to files within a website.

Absolute File Paths

An absolute path gives the complete location of a resource.

For example:

<img src="https://example.com/images/logo.png" alt="Logo">

The complete web address is provided.

Another example is:

<a href="https://example.com/about.html">About Us</a>

The browser knows exactly where the resource is located.

Absolute URLs are commonly used when linking to resources hosted on another website or domain.

Example

<!DOCTYPE html>
<html>
<head>
    <title>Absolute Path Example</title>
</head>
<body>

<img src="https://example.com/images/photo.jpg" alt="Photo">

<a href="https://example.com/about.html">About Us</a>

</body>
</html>

Advantages of Absolute Paths

Absolute URLs are useful when:

  • Linking to another website.
  • Using resources hosted on a CDN.
  • Referencing an external service.
  • Sharing a complete URL.
  • Connecting to a resource outside the current website.

Disadvantages

Absolute paths can be less convenient when building a website because they may contain the full domain name.

For example:

https://example.com/images/logo.png

If you move the website to another domain, these URLs may need to be changed.

Relative File Paths

A relative path specifies the location of a file in relation to the current HTML document.

For example:

<img src="images/logo.png" alt="Logo">

The browser interprets the path relative to the location of the current HTML file.

Relative paths are widely used in website development because they make projects easier to move from one location to another.

Current Folder

Suppose your project looks like this:

website/
├── index.html
└── logo.png

The HTML file and image are in the same directory.

You can write:

<img src="logo.png" alt="Logo">

You can also explicitly refer to the current directory with:

<img src="./logo.png" alt="Logo">

Both commonly point to the same file.

File Inside a Subfolder

Suppose the project looks like this:

website/
├── index.html
└── images/
    └── logo.png

The image is inside the images folder.

Use:

<img src="images/logo.png" alt="Logo">

The path means:

  • Start from the folder containing index.html.
  • Enter the images folder.
  • Find logo.png.

File in a Parent Folder

The .. notation means “go up one directory.”

Consider:

website/
├── index.html
└── pages/
    └── about.html

If about.html needs to link back to index.html, use:

<a href="../index.html">Home</a>

Here:

..

means to move one level upward.

Starting from:

website/pages/

the browser moves to:

website/

and then finds:

index.html

Moving Up Multiple Directories

You can use multiple .. segments.

For example:

<a href="../../index.html">Home</a>

This tells the browser to move up two directory levels before looking for index.html.

Suppose the structure is:

website/
├── index.html
└── pages/
    └── products/
        └── details.html

From details.html, the following path:

<a href="../../index.html">Home</a>

moves:

products → pages → website

and then finds index.html.

The ./ Notation

The ./ notation refers to the current directory.

For example:

<script src="./script.js"></script>

This tells the browser to look for script.js in the same directory as the current HTML file.

Similarly:

<link rel="stylesheet" href="./css/style.css">

means the browser should look for the css directory relative to the current document.

The ./ is often optional.

For example:

<img src="logo.png" alt="Logo">

and:

<img src="./logo.png" alt="Logo">

normally refer to the same file when used from the same directory.

The ../ Notation

The ../ notation means “go to the parent directory.”

Example:

<img src="../images/logo.png" alt="Logo">

If the current HTML file is inside a folder, the browser moves up one level and then enters images.

Example of a Website Folder Structure

Consider this project:

my-website/
├── index.html
├── about.html
├── contact.html
├── css/
│   └── style.css
├── js/
│   └── script.js
├── images/
│   ├── logo.png
│   └── banner.jpg
└── pages/
    └── services.html

From index.html, you can use:

<link rel="stylesheet" href="css/style.css">

<script src="js/script.js"></script>

<img src="images/logo.png" alt="Website logo">

<a href="about.html">About</a>

<a href="pages/services.html">Services</a>

File Paths in the <img> Element

The src attribute specifies the image location.

Example:

<img src="images/photo.jpg" alt="Photo">

If the image is in the same folder:

<img src="photo.jpg" alt="Photo">

If the image is one directory above:

<img src="../photo.jpg" alt="Photo">

If it is two directories above:

<img src="../../photo.jpg" alt="Photo">

File Paths in Links

The <a> element uses the href attribute.

Example:

<a href="about.html">About Us</a>

For a page inside a folder:

<a href="pages/about.html">About Us</a>

For a page in the parent folder:

<a href="../index.html">Home</a>

An external website normally uses an absolute URL:

<a href="https://example.com">Visit Example</a>

File Paths in CSS

HTML file paths are also important when loading CSS files.

Example:

<link rel="stylesheet" href="css/style.css">

Remember that a relative path in CSS itself is normally resolved relative to the CSS file, not the HTML document.

For example:

website/
├── index.html
├── css/
│   └── style.css
└── images/
    └── background.jpg

Inside style.css, use:

body {
    background-image: url("../images/background.jpg");
}

Why?

The CSS file is inside:

css/

So:

../

moves from css back to the website root, and then:

images/background.jpg

points to the image.

This is an important concept for beginners.

File Paths in JavaScript

JavaScript files can be included with:

<script src="js/script.js"></script>

Suppose:

website/
├── index.html
└── js/
    └── script.js

The path from index.html is:

js/script.js

However, paths used inside JavaScript modules can follow different resolution rules depending on how the JavaScript code is written and loaded. Module imports are generally resolved relative to the importing module.

For example:

import helper from "./helper.js";

Here, ./helper.js is relative to the JavaScript module containing the import.

File Paths in <link>

The <link> element is commonly used to load stylesheets.

Example:

<link rel="stylesheet" href="css/style.css">

It can also reference other resources, depending on the rel value.

For example:

<link rel="icon" href="images/favicon.ico">

File Paths in <script>

Example:

<script src="js/app.js"></script>

If the JavaScript file is in the parent directory:

<script src="../app.js"></script>

File Paths in Audio and Video

The src attribute can also contain file paths for multimedia.

Example:

<audio controls src="audio/music.mp3"></audio>

For video:

<video controls src="videos/movie.mp4"></video>

You can also use <source>:

<video controls>
    <source src="videos/movie.mp4" type="video/mp4">
</video>

File Paths in <iframe>

An iframe can load another page using a path.

Example:

<iframe src="pages/info.html"></iframe>

If the page is in the parent directory:

<iframe src="../info.html"></iframe>

An iframe can also use an absolute URL:

<iframe src="https://example.com"></iframe>

Root-Relative Paths

A root-relative path begins with /.

For example:

<img src="/images/logo.png" alt="Logo">

This means the browser should start from the root of the website.

If the website is:

https://example.com/

then:

/images/logo.png

generally refers to:

https://example.com/images/logo.png

This is different from:

<img src="images/logo.png" alt="Logo">

The second path is relative to the current document’s location.

Important Difference

Suppose you have:

https://example.com/blog/article.html

and write:

<img src="images/photo.jpg">

the browser generally looks for:

https://example.com/blog/images/photo.jpg

But:

<img src="/images/photo.jpg">

generally points to:

https://example.com/images/photo.jpg

This distinction becomes especially useful on larger websites.

Absolute URLs vs Relative Paths

TypeExampleMeaning
Absolute URLhttps://example.com/img/a.jpgComplete web address
Relative pathimages/a.jpgRelative to current document
Current directory./a.jpgFile in current directory
Parent directory../a.jpgFile one level above
Root-relative path/images/a.jpgStarts from website root

Windows File Paths vs Web Paths

A common beginner mistake is copying a Windows computer path into HTML.

A Windows path may look like:

C:\Users\John\Pictures\photo.jpg

That is a local operating-system path.

A web path generally uses forward slashes:

images/photo.jpg

Do not normally write:

<img src="C:\Users\John\Pictures\photo.jpg" alt="Photo">

Instead, place the image inside your website project and use a web-friendly path:

<img src="images/photo.jpg" alt="Photo">

Forward Slash and Backslash

Web URLs and HTML file paths conventionally use the forward slash:

images/photo.jpg

not:

images\photo.jpg

Forward slashes are portable and work properly across web environments.

File and Folder Names Matter

File paths can fail because of incorrect spelling.

Suppose the actual file is:

Logo.png

but your HTML contains:

<img src="logo.png" alt="Logo">

On case-sensitive hosting systems, these may be treated as different names.

Therefore, it is safer to keep naming consistent.

For example:

images/logo.png

and:

<img src="images/logo.png" alt="Logo">

Spaces in File Names

File names containing spaces can create unnecessary problems.

For example:

my photo.jpg

Although browsers can handle encoded URLs, simpler file names are usually better.

Prefer:

my-photo.jpg

or:

my_photo.jpg

Then:

<img src="images/my-photo.jpg" alt="My photo">

Recommended File Naming Practices

Good file names are:

  • Short.
  • Descriptive.
  • Consistent.
  • Usually lowercase.
  • Free from unnecessary spaces.
  • Easy to type.
  • Easy to understand.

For example:

about.html
contact.html
main.css
script.js
logo.png
product-image.jpg

Avoid unnecessarily complicated names such as:

My Final Website Image 2026 NEW.jpg

A cleaner version is:

website-image.jpg

File Extensions

A file path commonly includes the file extension.

Examples:

index.html
style.css
script.js
logo.png
photo.jpg
video.mp4
document.pdf

If you reference the wrong extension, the resource may not load.

For example:

<img src="images/photo.png" alt="Photo">

will not correctly reference a file that is actually:

photo.jpg

HTML File Paths and Website Deployment

A file path that works on your computer should also be tested after uploading the website to a web server.

For example, your local project might be:

C:\website\

with:

C:\website\index.html
C:\website\images\logo.png

The HTML should use:

<img src="images/logo.png" alt="Logo">

rather than depending on the computer’s local drive path.

This makes the website portable.

Common File Path Mistakes

Mistake 1: Wrong Folder

Incorrect:

<img src="image/logo.png" alt="Logo">

when the actual folder is:

images/

Correct:

<img src="images/logo.png" alt="Logo">

Mistake 2: Wrong Capitalization

Incorrect:

<img src="images/logo.png" alt="Logo">

when the actual file is:

Logo.png

Use the correct name consistently.

Mistake 3: Incorrect Number of ../

For example:

<a href="../../../index.html">Home</a>

may go too far upward.

Count the directory levels carefully.

Mistake 4: Using a Computer Path

Avoid:

<img src="C:\Users\John\Desktop\photo.jpg" alt="Photo">

Use a file inside the website project instead.

Mistake 5: Forgetting the Extension

Incorrect:

<img src="images/logo">

if the actual file is:

logo.png

Correct:

<img src="images/logo.png" alt="Logo">

Mistake 6: Incorrect Relative Reference

If the current file is:

pages/about.html

and the image is:

images/logo.png

this is usually incorrect:

<img src="images/logo.png" alt="Logo">

because the browser looks under:

pages/images/

The correct relative path is:

<img src="../images/logo.png" alt="Logo">

A Complete File Path Example

Consider this structure:

mywebsite/
├── index.html
├── about.html
├── css/
│   └── style.css
├── js/
│   └── script.js
├── images/
│   ├── logo.png
│   └── banner.jpg
└── pages/
    └── services.html

In index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Website</title>

    <link rel="stylesheet" href="css/style.css">
</head>
<body>

    <img src="images/logo.png" alt="Website logo">

    <img src="images/banner.jpg" alt="Website banner">

    <nav>
        <a href="index.html">Home</a>
        <a href="about.html">About</a>
        <a href="pages/services.html">Services</a>
    </nav>

    <script src="js/script.js"></script>

</body>
</html>

This example demonstrates several common types of relative paths.

Paths from a Nested HTML Page

Now consider pages/services.html.

To access the website logo:

<img src="../images/logo.png" alt="Website logo">

To access the CSS file:

<link rel="stylesheet" href="../css/style.css">

To access JavaScript:

<script src="../js/script.js"></script>

To return to the home page:

<a href="../index.html">Home</a>

The ../ is necessary because services.html is one directory below the website root.

File Paths and the Browser

When the browser sees:

<img src="images/logo.png" alt="Logo">

it does not simply search the entire computer for logo.png.

It resolves the path according to the document’s location and URL rules.

This is why understanding the folder structure is essential.

File Paths and URLs

On the web, a path becomes part of a URL.

For example:

https://example.com/images/logo.png

can be divided into:

https://

the protocol,

example.com

the domain,

and:

/images/logo.png

the path.

A relative path such as:

images/logo.png

is resolved by the browser against the current document’s URL.

File Paths and the <base> Element

HTML also supports the <base> element, which can establish a base URL for relative URLs in a document.

Example:

<head>
    <base href="https://example.com/">
</head>

Then:

<a href="about.html">About</a>

can be resolved relative to the specified base URL.

The <base> element should be used carefully because it can change how many relative URLs in the document are interpreted.

File Paths in HTML5

HTML5 continues to use standard URL resolution rules for resource references. File paths are therefore not a separate special language feature. They are generally relative or absolute URLs used by HTML attributes.

Understanding URL resolution is particularly important when working with:

  • HTML.
  • CSS.
  • JavaScript.
  • Images.
  • Fonts.
  • Videos.
  • Audio.
  • Web applications.

Security Considerations

File paths can also have security implications.

A web application should not blindly accept a user-provided file path and use it to access files on a server. Unsafe handling can lead to path traversal vulnerabilities.

For example, sequences such as:

../

can be abused in poorly designed server-side applications to attempt access to files outside an intended directory.

HTML itself does not create this vulnerability simply because it supports ../. The security problem generally occurs when server-side software processes untrusted paths without proper validation.

Relative Paths and Website Portability

One major advantage of relative paths is portability.

Suppose a website is developed at:

localhost

and later moved to:

https://example.com

A relative path such as:

<img src="images/logo.png" alt="Logo">

can continue to work without changing the domain.

This is one reason relative paths are popular in website projects.

Best Practices for HTML File Paths

Follow these practices when working with file paths:

1. Organize Your Files

Use clear folders such as:

css/
js/
images/
videos/
audio/
pages/

2. Use Relative Paths for Project Resources

For example:

<img src="images/logo.png" alt="Logo">

3. Keep Names Consistent

Use the same capitalization in filenames and references.

4. Prefer Simple File Names

Use:

product-image.jpg

instead of complicated names containing unnecessary spaces and symbols.

5. Use Forward Slashes

Use:

images/photo.jpg

rather than Windows-style backslashes.

6. Check Your Directory Level

Before using ../, determine exactly where the current HTML file is located.

7. Test Links After Deployment

A path that works locally should also be checked on the live website.

8. Avoid Unnecessary Absolute URLs

For resources belonging to your own website, relative or appropriate root-relative paths are often easier to maintain.

9. Keep Folder Structures Logical

A clean structure reduces broken links and makes future maintenance easier.

10. Check Case Sensitivity

Use exact filenames, especially when deploying to Linux-based web servers.

HTML File Paths: Quick Reference

PathMeaning
image.jpgFile in the current directory
./image.jpgFile in the current directory
images/image.jpgFile inside the images folder
../image.jpgFile one directory above
../../image.jpgFile two directories above
/images/image.jpgPath from the website root
https://example.com/image.jpgComplete absolute URL

HTML File Paths vs File URLs

A local file may sometimes be opened through a file: URL, such as:

file:///C:/website/index.html

However, websites should generally be developed and tested through a local web server when possible.

For example, a development server might provide:

http://localhost:8000/

This better reflects how resources behave on an actual website.

Some browser features also behave differently under file: URLs because of security restrictions and origin rules.

How to Troubleshoot a Broken File Path

If an image, stylesheet, script, or page is not loading, check these points:

  1. Confirm that the file actually exists.
  2. Check the filename carefully.
  3. Check the file extension.
  4. Check uppercase and lowercase letters.
  5. Check the current HTML file’s location.
  6. Count how many directories you need to move upward.
  7. Check whether the folder name is correct.
  8. Use / instead of \.
  9. Inspect the browser’s developer tools.
  10. Check the browser’s Network or Console panel for errors.
  11. Test the resource URL directly when appropriate.
  12. Check the deployed server’s folder structure.

A common error is:

404 Not Found

A 404 usually means the requested resource could not be found at that URL.

Frequently Asked Questions

What is a file path in HTML?

A file path tells the browser where a resource such as an image, CSS file, JavaScript file, or HTML page is located.

What does ../ mean in HTML?

../ means to move one directory level upward from the current location.

What does ./ mean?

./ refers to the current directory.

What does / at the beginning of a path mean?

A leading / generally indicates a root-relative path on the current website.

What is the difference between absolute and relative paths?

An absolute URL provides a complete web address, while a relative path identifies a resource in relation to the current document or website root.

Why is my HTML image not displaying?

Common causes include a wrong filename, incorrect folder, incorrect extension, incorrect capitalization, or an incorrect relative path.

Should I use absolute or relative paths?

For resources within your own website, relative or appropriate root-relative paths are often convenient. Absolute URLs are useful when referencing resources on another domain or when a complete URL is required.

Can I use Windows paths in HTML?

You should not normally use Windows computer paths such as C:\Users\... for website resources. Put the resource inside your project and reference it with a web path.

Are HTML file paths case-sensitive?

The behavior depends on the server and filesystem. Many web servers, especially those running on Linux, treat filenames as case-sensitive. It is best to always use exact and consistent capitalization.

Why does a path work locally but not online?

Your local computer and web server may have different directory structures, URL rules, or case-sensitivity behavior. Carefully compare the actual deployed folder structure and the URL being requested.

Conclusion

HTML file paths are a basic but extremely important part of web development. They connect HTML documents with images, stylesheets, JavaScript files, videos, audio, other webpages, and many other resources.

The most important concepts to remember are simple:

file.html

means a file in the current directory.

./file.html

also refers to the current directory.

folder/file.html

means the file is inside a subfolder.

../file.html

means move up one directory.

../../file.html

means move up two directories.

/images/file.html

generally refers to a path from the website root.

And:

https://example.com/file.html

is a complete absolute URL.

Once you understand how folders relate to one another, HTML file paths become much easier to use. A well-organized project with clear filenames and consistent relative paths will also be easier to develop, move, deploy, and maintain.

Scroll to Top