HTML File Paths

An HTML file path tells you where a file is in a website\’s folder. For a web browser, a file\’s path is like its address. With the help of file paths, we can add any external resource to our HTML file, such as an image, file, CSS file, JS file, video, etc. A file path shows where a file is in the folder structure of a web site. Links to outside files, such as Web pages, use file paths.

 

To link any outside source to an HTML file, you need to use the src or href attribute.

Here are the different ways to say where a file is:

  • <img src=\”image_name.jpg\”> It says that picture.jpg is in the same folder as the page that is being shown.
  • <img src=\”img/image_name.jpg\”> It says that picture.jpg can be found in the current folder\’s images folder.
  • <img src=\”/img/image_name.jpg\”> It says that picture.jpg is in the images folder at the root of the current web.
  • <img src=\”../image_name.jpg\”> It says that picture.jpg is in the folder that is one level above the current one.

HTML File Paths

A file path shows where a file is in the folder structure of a website.

File paths are used to link to files on other servers, like:
 

  1. Web pages
  2. Images
  3. Style sheets
  4. JavaScripts

There are two types of File Paths:

  1. Absolute File Paths
  2. Relative File Paths

Absolute File Paths

The full URL to a file is an absolute file path:

Example

<!DOCTYPE html>
<html>
<body>
<h2>We are Using a Full URL File Path (Absolute File Path) here</h2>
<img src=\”https://www.coderazaa.com/img/coderazaa-logo.png\” alt=\”alt text\” style=\”width:300px\”>
</body>
</html>

Relative File Paths

A relative file path sends you to a file that is close to the page you are on.

In the following example, the file path points to a file in the images folder at the root of the current web:

Let\’s look at an example to see how the file path points to a file in the images folder at the root of the current web.

 

Example

<!DOCTYPE html>
<html>
<body>
<h2>We are Using a Relative File Path here</h2>
<img src=\”/img/coderazaa-logo.png\” alt=\”alt text\” style=\”width:300px\”>
</body>
</html>

This is how a file path points to a file in the images folder in the current folder.

Example

<!DOCTYPE html>
<html>
<body>
<h2>We are Using a Relative File Path here</h2>
<img src=\”img/coderazaa-logo.png\” alt=\”alt text\” style=\”width:300px\”>
</body>
</html>

When the images folder is in the folder one level up from where you are now.

Example

<!DOCTYPE html>
<html>
<body>
<h2>We are Using a Relative File Path here</h2>
<img src=\”../img/coderazaa-logo.png\” alt=\”alt text\” style=\”width:300px\”>
</body>
</html>

Key points about File path:

  • If you don\’t use the right URL, file name, or image name, it won\’t show up on the page.
  • Try to use relative file paths so that your code will work no matter what URL is used. Use relative file paths as much as possible (if possible).
  • When you use relative file paths, your web pages won\’t be tied to the URL of your current base site. All links will work on your own computer (localhost), as well as on your current public domain and all future public domains.
Related Posts
Introduction to HTML

HTML Introduction HTML is the most common language used to mark up Web pages. What does HTML mean? Hyper Text Read more

What is HTML

HTML stands for Hyper Text Markup Language, which is a programming language used to make web pages and web apps. Read more

HTML Basic Examples

In this chapter, we\'ll show you some simple examples of HTML code. Don\'t worry if we use tags that you Read more

HTML text Editors

Editors for HTML text HTML files are text files, so any text editor can be used to make them. Text Read more

HTML Tags

Learn HTML Tags HTML tags are kind of like keywords that tell a web browser how to format and show Read more

HTML Elements

Elements make up an HTML file. These elements are what make web pages and tell you what content is on Read more

HTML Attributes

Attribute in HTML Attributes in HTML are special words that tell you more about an element. Attributes change the way Read more

HTML Headings

Headings in HTML The <h1> to <h6> tags are used to set up headings in HTML. <h1> shows which heading Read more

Scroll to Top