AbsoluteVs RelativePaths
AbsoluteVs RelativePaths
• An absolute file path contains the full path or URL to the file, starting from the root directory or
web server.
• When to use: best for linking external resources (e.g., online images or files stored on specific
places on the web).
• How it works: no matter where the web page is located, the link works as long as the online
resource stays available.
• Examples:
➔ This will work anywhere, because it links directly to the image on the
web.
➔ Problem: this only works on your computer. If you move the file or
open it from another machine, the link will break.
• A relative file path refers to a file relative to the location of the current web page.
• When to use: ideal when the files (e.g., images, CSS) are saved within the same folder structure
as the web page.
• How it works: if the files and the webpage are moved together, the links remain valid because
the relationship between files doesn’t change.
1. Folder Structure:
└──> images/
└──>MyLogo.png
Bayan H. Takruri
3. How this works:
o This path tells the browser to look for the logo.png file in the images folder, which is in
the same directory as index.html.
o If you move the entire "website" folder (e.g., to a USB or another computer), the image
link will still work.
• Absolute local paths (e.g., C:/Users/) are restricted to a specific computer or directory.
o So, if the files are moved or opened from a different machine, the paths won't work.
• Relative paths are better in this situation because they allow your project to be moved without
breaking the links.
Summary
Relative Path Linking files in the <img src="images/Mylogo.png"> Yes (if folder
same folder structure stays
structure the same)
https://www.youtube.com/watch?v=hxto_sRZsBg&ab_channel=kootkot
Bayan H. Takruri