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
| Type | Description | Example |
|---|---|---|
| Absolute Path | Full URL to a file | https://example.com/image.jpg |
| Relative Path | Path relative to current file | images/photo.jpg |
| Root Relative | Path from root directory | /images/photo.jpg |
Absolute Path Example
HTMLRead-only
1
Relative Path Example
HTMLRead-only
1
Going Up a Folder
HTMLRead-only
1
Root Relative Path
HTMLRead-only
1
Using Paths in Links
HTMLRead-only
1
Using Paths in CSS and JS
HTMLRead-only
1
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.