In HTML and CSS, there are two types of links that are commonly used for linking files and navigating through directories: relative links and absolute links.
1. Relative Links:
Relative links are used to link files within the same directory or in a subdirectory of the current directory. They are specified using a relative path, which is a path relative to the current location of the file. Relative links are convenient when you want to link files within your project without specifying the entire URL.
There are two types of relative links: relative file paths and relative directory paths.
a. Relative File Paths:
A relative file path specifies the location of a file relative to the current file. It is used when you want to link to a specific file within the same directory or in a subdirectory. The relative file path is specified by simply specifying the file name or the path to the file from the current file.
For example, if you have an HTML file called "index.html" and you want to link to a CSS file called "styles.css" in the same directory, you can use the following relative file path:
<link rel="stylesheet" href="styles.css">
If the CSS file is located in a subdirectory called "css", you can use the following relative file path:
<link rel="stylesheet" href="css/styles.css">
b. Relative Directory Paths:
A relative directory path specifies the location of a file relative to the current directory. It is used when you want to link to a file in a different directory than the current file. The relative directory path is specified by using "../" to indicate moving up one directory level, and then specifying the path to the file from there.
For example, if you have an HTML file called "index.html" in the root directory, and you want to link to an image file called "image.jpg" in a subdirectory called "images", you can use the following relative directory path:
<img src="../images/image.jpg">
The "../" moves up one directory level from the current file (index.html), and then the path "images/image.jpg" specifies the location of the image file.
2. Absolute Links:
Absolute links are used to link files by specifying the complete URL or file path. They are not relative to the current file or directory. Absolute links are useful when you want to link to a file on a different website or specify an exact file path.
Absolute links can be specified in two ways: absolute URLs and absolute file paths.
a. Absolute URLs:
An absolute URL specifies the complete web address of a file, including the protocol (http or https), domain name, and file path. It is used when you want to link to a file on a different website.
For example, to link to a CSS file hosted on a different website, you can use the following absolute URL:
<link rel="stylesheet" href="https://example.com/styles.css">
b. Absolute File Paths:
An absolute file path specifies the complete file path of a file on the local system. It is used when you want to link to a file on your computer or specify an exact file path.
For example, to link to an image file located at "C:imagesimage.jpg" on a Windows system, you can use the following absolute file path:
<img src="file:///C:/images/image.jpg">
The "file:///" indicates that it is an absolute file path, and then the path "C:/images/image.jpg" specifies the location of the image file.
Relative links and absolute links are the two types of links used in HTML and CSS for linking files and navigating through directories. Relative links are used to link files within the same directory or in a subdirectory, while absolute links are used to link files by specifying the complete URL or file path. Understanding the differences and appropriate usage of these link types is essential for effective file linking and directory navigation in web development.
Other recent questions and answers regarding Examination review:
- Why is it not recommended to use a forward slash at the beginning of a file path to go back to the main directory of a website?
- What is the purpose of ".." followed by a forward slash in a file path?
- How do you specify the path for a URL path to link to an external website?
- How do you specify the path for an internal link to a file within the same website?

