html
/

HTML File Paths: Absolute and Relative Paths

Last Sync: Today

On this page

11
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

html

HTML File Paths: Absolute and Relative Paths

What are File Paths?

File paths specify the location of files such as images, CSS, JavaScript, or other pages in HTML.

Types of File Paths

TypeDescriptionExample
Absolute PathFull URL to a filehttps://example.com/image.jpg
Relative PathPath relative to current fileimages/photo.jpg
Root RelativePath from root directory/images/photo.jpg

Absolute Path Example

HTMLRead-only
1
<img src="https://example.com/image.jpg" alt="Image">

Relative Path Example

HTMLRead-only
1
<img src="images/photo.jpg" alt="Image">

Going Up a Folder

HTMLRead-only
1
<img src="../images/photo.jpg" alt="Image">

Root Relative Path

HTMLRead-only
1
<img src="/assets/images/photo.jpg" alt="Image">

Using Paths in Links

HTMLRead-only
1
<a href="pages/about.html">About Us</a>

Using Paths in CSS and JS

HTMLRead-only
1
<link rel="stylesheet" href="css/styles.css">
<script src="js/script.js"></script>

Best Practices

  • Use relative paths for local projects
  • Use absolute paths for external resources
  • Keep folder structure organized
  • Avoid deep nested paths when possible
  • Use consistent naming conventions

Common Mistakes

  • Incorrect folder structure
  • Wrong use of ../
  • Broken links due to incorrect paths
  • Mixing absolute and relative paths improperly

Conclusion

Understanding file paths is essential for linking resources correctly in HTML. Proper usage ensures your website works smoothly across environments.

Try it yourself

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

Test Your Knowledge

Q1
of 3

Which path uses full URL?

A
Relative
B
Absolute
C
Local
D
Root
Q2
of 3

What does ../ mean?

A
Same folder
B
Next folder
C
Parent folder
D
Root
Q3
of 3

Which is root-relative?

A
images/photo.jpg
B
/images/photo.jpg
C
../photo.jpg
D
http://img.com

Frequently Asked Questions

What is a relative path?

It is a path relative to the current file location.

What is an absolute path?

It is a full URL pointing to a resource.

What does ../ mean?

It moves one directory up.

Previous

html block inline

Next

html favicon

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.