Published by Patrick Mutisya · 8 days ago
Know and understand relative file path and absolute file path including the reason absolute file paths must not be used for hyperlinks to locally saved web pages/objects.
file:///C:/Users/John/Documents/site/index.html or https://www.example.com/images/logo.png).images/logo.png, ../styles/main.css).Characteristics:
Example of an absolute path on a Windows system:
file:///C:/Users/John/Documents/website/index.htmlExample of an absolute URL on the web:
https://www.example.com/assets/css/style.cssCharacteristics:
. to refer to the current folder and .. to move up one level.Common forms:
images/photo.jpg – same folder → sub‑folder.../scripts/app.js – one level up, then into scripts folder.../../styles/main.css – two levels up, then into styles.| Reason | Explanation |
|---|---|
| Portability | An absolute path ties the link to a specific drive letter or server address. If the folder is copied to another computer, the link will break. |
| Security & Privacy | Absolute paths can expose the full directory structure of a user’s computer, which is undesirable when sharing files. |
| Collaboration | When multiple users work on the same project, each may have different folder structures. Relative paths ensure everyone can open the pages correctly. |
| Web Publishing | When the site is uploaded to a web server, the root changes. Relative paths automatically adjust, while absolute paths would still point to the original local location. |
Folder structure:
website/│
├─ index.html
├─ about.html
├─ images/
│ └─ logo.png
└─ css/
└─ style.css
Linking from about.html to the logo image:
file:///C:/Users/John/website/images/logo.pngimages/logo.png../ to move up directories as needed./) – even on Windows.about.html to images/logo.png and css/style.css.