Cover Image for HTML File Path
212 views

HTML File Path

In HTML, file paths are used to specify the location of external files, such as images, stylesheets, and JavaScript files. There are two types of file paths in HTML are absolute and relative.

An absolute file path starts with the root directory of the file system, and specifies the full path to the file. For example:

<img src="/images/my-image.png">

In this example, the image file is located in the images directory at the root of the file system.

A relative file path, on the other hand, specifies the path to the file relative to the current page. There are three types of relative file paths:


(1) Relative to the current directory: If the file you’re linking to is in the same directory as the current page, you can simply use the file name. For example:

<link rel="stylesheet" href="styles.css">

In this example, the stylesheet file styles.css is located in the same directory as the current page.


(2) Relative to the root directory: To specify a file path relative to the root directory, you can use a forward slash at the beginning of the path. For example:

<img src="/images/my-image.png">

This file path specifies that the my-image.png file is located in the images directory at the root of the file system.


(3) Relative to a parent directory: To specify a file path that goes up one or more levels in the directory hierarchy, you can use the .. notation. For example:

<img src="../images/my-image.png">

In this example, the my-image.png file is located in the images directory one level up from the current page’s directory.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS