Skip to main content

HTML File Paths

A file path describes where a file sits in a website's folder structure. File paths are used when linking to external files like web pages, images, style sheets, and JavaScripts.

Some examples: picture.jpg is in the same folder as the current page; images/picture.jpg is in an images folder inside the current folder; /images/picture.jpg is in an images folder at the root of the site; and ../picture.jpg is in the folder one level up from the current one.


Absolute File Paths

An absolute file path is the full URL to a file.

Example

An image referenced by its full URL.

Prompt
A page with an image using an absolute file path: the full URL https://prompt-cookbook.com alt "Mountain".
Output: complete HTML page

Relative File Paths

A relative file path points to a file relative to the current page.

Root of the site

A path to the images folder at the root of the site.

Prompt
A page with an image using a relative path to the images folder at the root of the site: /images/picture.jpg, alt "Mountain".
Output: complete HTML page

Current folder

A path to the images folder in the current folder.

Prompt
A page with an image using a relative path to the images folder in the current folder: images/picture.jpg, alt "Mountain".
Output: complete HTML page

One level up

A path to the images folder one level up from the current folder.

Prompt
A page with an image using a relative path to the images folder one level up: ../images/picture.jpg, alt "Mountain".
Output: complete HTML page

Best Practice

It is best practice to use relative file paths when possible. With relative paths, your pages are not tied to your current base URL, so links work on your own computer (localhost) as well as on your current and future public domains.