Slide 1
Slide 2
Slide 3

Set image location in HTML5 (HTML-V40)

No Comments

10.2. Set Image Location

The image location (path) must be clearly set in the src attribute. You can use an absolute path, which starts from the root directory (/), followed by the directory name (if any), and then the image name with its extension.

· Absolute Path

An absolute path is the full path to a file or folder, starting from the root directory ( / ) to the target location.

Key features:

  • Starts with /
  • Does not depend on the current file's location
  • Always specifies the location clearly

Suppose we have an image named "test.png" stored in the "images" folder, which is inside the "html" folder on the root directory. You can easily use an image path like "/html/images/test.png".

· Relative paths

A relative path is a path that depends on the current file's location to reach another file or folder.

Key features:

  • Does not start with /
  • Uses ../ to go back to the previous (parent) folder
  • Easy to use within a project

Source Code:

Copied!
<!DOCTYPE html>
<html>
<head>
    <title>Absolute vs Relative Path</title>
</head>
<body>

    <h2>Using Absolute Path</h2>
    <!-- Absolute Path -->
    <img src="photo/images/photo55.jpg" alt="Absolute Image" width="200">

    <h2>Using Relative Path</h2>
    <!-- Relative Path -->
    <img src="../images/photo32.jpg" alt="Relative Image" width="200">

</body>
</html>

Result: 

Watch the video:


Ebook:
https://softkhpc.blogspot.com/2026/11/html-tutorial-beginners.html

back to top