Moreover, these file paths are useful in adding external documents such as an image, a video, a style sheet, a JavaScript file, or other web pages into your current HTML web page.
Types of HTML file path
There are, in general, two types of HTML file paths.
- Absolute File Path
- Relative File Path
The above-mentioned file paths are explained is detail below.
1. Absolute File Path
This file path in HTML represents the full URL address of a file.
Syntax
Syntax of an absolute file path is as follows.
Example
Output
2. Relative File Path
A relative file path denotes the address of relative file associated with the location of the current web page. There are three conditions when a relative file path can be used.
Condition 1: When the external file and the current web page file are located in the same folder.
When the file is in the same folder as the current page file.
Output
The image was added successfully.
Condition 2: When the file is present in a folder that is located above the folder of the web page file.
When the file is present in a folder that is located above the folder of the web page file.
Output
Condition 3: When the file is present in a folder that is placed at the root of the web file.
When the location of the folder that contains the file is at root of web file.
Output
Relative file paths should be given priority over the absolute file paths because using a relative file path your source code will be free of URL.
Conclusion
A file path in HTML refers to the location of the file inside a web folder that contains relevant data. These file paths are used as addresses by the web browser to extract the files. File paths are useful when adding external documents such as an image, a video, a style sheet, a JavaScript file, or other web pages into your current HTML web page. This write-up discusses HTML file paths and its types in detail along with the appropriate examples.