In HTML, file paths are used to specify the location of external resources, such as images, stylesheets, scripts, or other HTML documents. There are three types of file paths commonly used in HTML: absolute, relative, and root-relative.
An absolute file path specifies the complete URL or file system path to the resource. It includes the protocol (such as "http://" or "https://") for remote resources or the root directory for local files. Here are some examples:
- Remote resource:
html
<img src="https://www.example.com/images/image.jpg" alt="Example Image">
- Local file:
html
<link href="/css/style.css" rel="stylesheet">
Relative file paths are specified relative to the current HTML document's location. They don't include the protocol or root directory. Relative paths are often used to refer to resources within the same website or directory. Here are some examples:
- Same directory:
html
<img src="image.jpg" alt="Example Image">
- Subdirectory:
html
<img src="images/image.jpg" alt="Example Image">
- Parent directory:
html
<img src="../images/image.jpg" alt="Example Image">
Root-relative file paths are specified relative to the website's root directory. They start with a forward slash ("/") and provide a consistent path regardless of the current page's location. Here's an example:
html
<img src="/images/image.jpg" alt="Example Image">
It's important to note that when using file paths, the file names and directories are case-sensitive in most web servers, so make sure to use the correct letter case in your file paths.
Additionally, you can use the `<base>` tag within the `<head>` section of your HTML document to set a base URL for all relative URLs within the document.
Understanding and using file paths correctly is essential for properly referencing external resources in your HTML documents and ensuring they are loaded and displayed as intended.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc