In HTML, we often refer to other files like images, CSS, or JavaScript. To load these elements properly, we must specify the correct file path.
An absolute path is a complete URL starting with the protocol (https://) and domain. Use it when referring to external files.
html
<img src="https://example.com/images/logo.png" alt="Logo">
A relative path defines the location relative to the current file. This is the most common method within your project’s structure.
html
<img src="images/photo.jpg" alt="Photo">
If the target file is one level above the current one, use ../ to reach the parent folder.
html
<img src="../assets/image.png" alt="Image from parent folder">
If the file is in the same folder as your HTML file, just write the filename.
html
<link rel="stylesheet" href="style.css">
If the file is in a subfolder, first write the folder name, then the filename, e.g., 'scripts/main.js'.
html
<script src="scripts/main.js"></script>
Always double-check your folder and file structure. Avoid invalid characters (e.g., spaces or accents) and use consistent naming. Remember that filenames can be case-sensitive, especially on servers.
The folder structure below helps illustrate what a basic HTML project might look like:
plaintext
project/
├── index.html
├── style.css
├── images/
│ └── logo.png
└── scripts/
└── app.js
In the structure above, this is how you can access other files from index.html. This kind of visual helps you understand pathing.
Let’s look at a practical example of how to correctly reference various files in a real project:
html
<!-- Reference to an image -->
<img src="images/logo.png" alt="Logo">
<!-- Reference to a CSS file -->
<link rel="stylesheet" href="style.css">
<!-- JavaScript script -->
<script src="scripts/app.js"></script>
Specifying paths accurately is crucial, especially for larger projects. Always make sure the path reflects the actual file structure.
Please sign in to ask Lara about HTML file paths.
Select Language
Set theme
© 2025 ReadyTools. All rights reserved.