HTML File Path | Linking Files in a Website
An HTML File Path specifies the location of a file that is being linked to an HTML document. File paths are used for linking to external files such as images, CSS, JavaScript, and other resources in a web project.
Types of File Paths:
- Absolute Path: Specifies the full URL of a file, including the domain name. It is used for files hosted on external websites.
- Relative Path: Specifies the location of a file relative to the current document. It is commonly used for files within the same project.
Examples of File Paths:
Using Absolute Path
<!DOCTYPE html>
<html>
<head>
<title>Absolute Path Example</title>
</head>
<body>
<img src="https://example.com/images/logo.png" alt="Logo">
</body>
</html>
Using Relative Path
<!DOCTYPE html>
<html>
<head>
<title>Relative Path Example</title>
</head>
<body>
<img src="images/logo.png" alt="Logo">
</body>
</html>
Relative Path Variations:
- Same Folder: Reference files in the same directory as the HTML file.
Example
<img src="image.png" alt="Image in Same Folder">
- Subfolder: Reference files in a subfolder relative to the current file.
Example
<img src="images/image.png" alt="Image in Subfolder">
- Parent Folder: Reference files in the parent directory using `../`.
Example
<img src="../image.png" alt="Image in Parent Folder">
Output

Image displayed from an external URL (absolute path).
Best Practices for Using File Paths:
- Use relative paths for resources within your project to ensure portability.
- Use absolute paths for linking to external resources like APIs or hosted files.
- Organize files in well-structured folders for easier management.
- Test file paths to ensure that resources are correctly linked.
Understanding file paths is crucial for linking resources effectively and maintaining a well-organized web project. Practice using both absolute and relative paths to master this essential skill in web development.