- Introduction
- HTML Document
- Basic Structure
- Comments
- Elements
- Document Structure Elements
- Metadata Elements
- Sections and Layout Elements
- Headings
- Text Content Elements
- Inline Text Semantic Elements
- Media Elements
- Form Elements
- Table Elements
- Interactive Elements
- Scripting / Template Elements
- Edit Elements
- Semantic, Void and Nested Elements
- Block-level and Inline Elements
- Semantic vs. Non-Semantic Elements
- Attributes
- Favicon
- Colors
- File Paths
- URL (Uniform Resource Locator)
- Responsive Web Design
File Paths
Learn how to use relative and absolute file paths in HTML to link files like images, CSS, and scripts.
HTML file paths are used to link external files such as images, stylesheets, scripts, and other HTML pages to the document.
The file path tells the browser where to find the file on the server or localhost.
There are two types of file paths in HTML:
- Absolute file paths: An absolute file path is the complete URL of the file. These are used to link the resources that are located on a different server than the current HTML file.
For example:
<img src="https://www.example.com/images/img.png" alt="Example image">
- Relative file paths: A relative file path is relative to the current HTML file location. These are used to link the resources that are located on the same server as the current HTML file.
There are three types of relative file paths:
- Same folder: If the file you want to link to the document is in the same folder as the current file, you can simply use the file name.
For example:
<img src="img.png">
- Subfolder: If the file you want to link to the document is in a subfolder, you need to specify the subfolder name in the path.
For example:
<img src="images/img.png">
- Parent folder: If the file you want to link to the document is located in a parent folder, you need to use
../
to indicate going up one level in the folder hierarchy.
The ../
symbol tells the browser to move one folder level up. This is useful when referencing files that are located in a parent folder relative to the current file.
For example:
<img src="../img.png">
You can also combine ../
multiple times to move up multiple levels.
For example, if your folder structure is like this:
project/
├── index.html
├── img.png
├── images/
│ └── img.png
└── assets/
└── icons/
└── icon.png
Then you can provide the path like this:
<img src="../../assets/icons/icon.png">