Intern
What is a relative link?
sobes.tech AI
Answer from AI
A relative link points to the location of a resource relative to the current document.
Types of relative links:
- Link in the current directory: Points to a file in the same directory as the current document.
<a href="page.html">Go to page</a> - Link to a subdirectory: Points to a file in a subdirectory.
<a href="images/image.png">View image</a> - Link to the parent directory: Points to a file in the directory one level above the current.
../is used to go up one level.<a href="../index.html">Home</a> - Link to several levels above:
../../and so on.<a href="../../styles/style.css">Include styles</a> - Link to the root of the site: Uses
/at the beginning, indicating the root directory of the website.<a href="/about.html">About us</a>
Advantages of using:
- Simplifies site transfer, as they do not depend on the domain name.
- Shorter and more readable URLs.
Disadvantages:
- Can be incorrect when the directory structure changes.