In HTML, file paths are used to link to resources such as images, stylesheets, and scripts. Understanding how to correctly specify these paths is crucial for properly linking resources in your web pages.
Absolute paths specify the full URL to the resource, including the protocol and domain. For example:
<img src="https://www.shariqsp.com/image1.jpg" alt="image1">
Relative paths specify the location of the resource relative to the current document. There are different types of relative paths:
<img src="logo.png" alt="Logo">
<link rel="stylesheet" href="../styles/main.css">
<script src="scripts/app.js"></script>
Absolute paths are useful for linking to external resources or when the resource location is fixed. Relative paths are more flexible and are used when linking resources within the same website. Here is a comparison:
<a href="https://www.shariqsp.com/about">About Us</a>
<a href="about.html">About Us</a>
When working with file paths, consider the following best practices: