TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

HTML File Path

HTML File Path or HTML 5 Tutorial for beginners and professionals with tags, elements, tables, forms, anchor, image, heading, marquee, textarea, div, audio, video, header, footer etc.

<< Back to HTML

HTML File Paths

An HTML file path is used to describe the location of a file in a website folder. File paths are like an address of file for a web browser. We can link any external resource to add in our HTML file with the help of file paths such as images, file, CSS file, JS file, video, etc.

The src or href attribute requires an attribute to link any external source to HTML file.

Following are the different types to specify file paths:

  1. <img src="picture.jpg"> It specifies that picture.jpg is located in the same folder as the current page.
  2. <img src="images/picture.jpg"> It specifies that picture.jpg is located in the images folder in the current folder.
  3. <img src="/images/picture.jpg"> It specifies that picture.jpg is located in the images folder at the root of the current web.
  4. <img src="../picture.jpg"> It specifies that picture.jpg is located in the folder one level up from the current folder.

File paths are used on webpages to link external files like:

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

There are two types of File Paths:

  1. Absolute File Paths
  2. Relative File Paths

Absolute File Paths

Absolute file path specifies full URL address.

Example:

<!DOCTYPE html>
<html>
<body>
<h2>Using a Full URL File Path</h2>
<img src="https://www.TheDeveloperBlog.com/images/nature-1.jpg" alt="image" style="width:300px">
</body>
</html>
Test it Now

Relative File Paths

The relative file path specifies to a file which is related to the location of current page.

Example:

Let's take an example to see how the file path points to a file in the images folder located at the root of the current web.

<!DOCTYPE html>
<html>
<body>
<h2>Using a Relative File Path</h2>
<img src="/images/nature-2.jpg" alt="Mountain" style="width:300px">
</body>
</html>
Test it Now

Example:

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

<!DOCTYPE html>
<html>
<body>
<h2>Using a Relative File Path</h2>
<img src="images/nature-3.jpg" alt="Mountain" style="width:300px">
</body>
</html>
Test it Now

Example:

When the images folder located in the folder one level above the current folder.

<!DOCTYPE html>
<html>
<body>
<h2>Using a Relative File Path</h2>
<img src="../images/nature4.jpg" alt="Mountain" style="width:300px">
</body>
</html>
Test it Now

Important Points for File path:

  • Always remember to use proper URL, file name, image name, else it will not display on the webpage.
  • Try to use relative file paths, so that your code will be independent of URL.

Next TopicHTML Head




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf