HTML · Chapter 26 of 45

HTML File Paths

File paths tell the browser where to find linked resources like images, stylesheets, and scripts. Paths can be absolute (full URL) or relative (based on the current file's location).

Relative paths use ./ for the current folder and ../ to move up one directory level, making websites portable across different domains or folder structures.

Syntax
<img src="images/photo.jpg">

Absolute paths

An absolute path is a complete URL like https://example.com/images/logo.png, working regardless of where the current page is hosted.

Relative paths

A relative path like images/logo.png or ../css/style.css is resolved relative to the current HTML file's location, ideal for local project resources.

Example 1 (html)
<img src="https://example.com/logo.png" alt="Logo">
Output
(loads logo from full URL)

An absolute path always points to the same resource regardless of hosting location.

Example 2 (html)
<link rel="stylesheet" href="../css/style.css">
Output
(loads a stylesheet one folder up in css/)

../ moves up one directory level from the current file's folder.

Key points

  • Absolute paths include the full URL (https://...).
  • Relative paths are based on the current file's location.
  • ./ refers to the current folder, ../ moves up one level.
  • Relative paths make sites portable across environments.
💡 Note: Broken relative paths are a common cause of missing images or styles after deployment.

📝 Quick Quiz

1. What does ../ mean in a file path?

2. Which is an absolute path?

3. Relative paths are resolved based on: