HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML File Paths

HTML File Paths are used to specify the location of files that are linked to an HTML document. These files can be images, videos, audio files, or any other type of file that needs to be included in the HTML document. The file path tells the browser where to find the file so that it can be displayed or played.

There are two types of file paths that can be used in HTML: absolute file paths and relative file paths.

Absolute File Paths

An absolute file path is a complete URL that includes the protocol, domain name, and file path. This type of file path is used when linking to files that are located on a different server or domain. Absolute file paths always start with the protocol (http:// or https://) followed by the domain name and the file path.

Here is an example of an absolute file path:

<img src="http://www.example.com/images/picture.jpg" alt="Picture">

In this example, the file path starts with the protocol (http://), followed by the domain name (www.example.com), and the file path (/images/picture.jpg).

Relative File Paths

A relative file path is a file path that is relative to the location of the HTML document. This type of file path is used when linking to files that are located on the same server or domain as the HTML document. Relative file paths do not include the protocol or domain name, and always start with a forward slash (/) or a directory name.

Here is an example of a relative file path:

<img src="/images/picture.jpg" alt="Picture">

In this example, the file path starts with a forward slash (/), which indicates that the file is located in the root directory of the server. The file path then includes the directory name (images) and the file name (picture.jpg).

Relative file paths can also include directory names to specify the location of the file relative to the HTML document. For example:

<img src="../images/picture.jpg" alt="Picture">

In this example, the file path starts with two dots (..), which indicates that the file is located in the parent directory of the HTML document. The file path then includes the directory name (images) and the file name (picture.jpg).

Conclusion

HTML File Paths are an important part of creating web pages. They allow you to link to files that are located on the same server or on a different server. Absolute file paths are used when linking to files on a different server, while relative file paths are used when linking to files on the same server. By understanding how to use file paths, you can create web pages that are easy to navigate and that include all the necessary files.

References

Activity