MyInternships.in

HTML Basics

HTML File Paths

A file path tells the browser where to find a file like an image, stylesheet, or another page. Getting paths right is the number one fix for broken images and links.


What is a File Path?

A file path is the address of a file inside your project or on the web. Whenever you use src or href, you provide a path. There are two kinds: absolute paths give the full location, and relative paths describe the location compared to the current file.

Relative paths are preferred for files within your own website because they keep working even if you move the whole project to a new server or domain.

Absolute vs Relative Paths

PathTypeMeans
https://site.com/img/a.pngAbsoluteThe full URL to a file anywhere on the web.
img/a.pngRelativeIn the img folder, inside the current folder.
a.pngRelativeIn the same folder as the current file.
../a.pngRelativeOne folder up from the current file.
/img/a.pngRoot-relativeFrom the site's root folder.

Example: Linking Files by Path

Different path styles
Example
<!DOCTYPE html>
<html>
<body>
  <!-- Absolute path to a web image -->
  <img src="https://picsum.photos/200" alt="Absolute path image">

  <!-- Relative path: image in an 'images' subfolder -->
  <img src="images/photo.jpg" alt="Relative path image">

  <!-- Relative link one folder up -->
  <a href="../index.html">Back to home</a>
</body>
</html>

More Examples

Linking a page in a subfolder
Example
<!-- Current file: index.html -->
<!-- Target file: blog/post.html -->
<a href="blog/post.html">Read the blog post</a>
Going up two levels then into a folder
Example
<!-- From deep/inside/page.html to css/style.css at the root -->
<link rel="stylesheet" href="../../css/style.css">
💡

Prefer relative paths for your own files. If you later change your domain or move the site into a subfolder, relative links keep working without edits.

⚠️

Paths are case-sensitive on most web servers. Photo.jpg and photo.jpg are different files online, even though they may look the same on Windows.

Key Takeaways

  • Absolute paths give the full URL; relative paths are relative to the current file.
  • Use ../ to move up one folder and folder/ to move into one.
  • Prefer relative paths for files within your own site.
  • Watch out for case sensitivity on real web servers.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships