Skip to content
IGCSE·Tuition
ICT · Lessons

Create a working relative link

The link works perfectly on your computer and then fails the moment the folder is copied somewhere else.

On this page
  1. How do you read a folder tree?
  2. How do you write the path step by step?
  3. Worked example
  4. The mistake to watch for
  5. Check yourself
  6. Where this leads next

A relative link is a path written from the page that contains it, so the whole site keeps working when its folder moves. This skill appears in every task that links pages together or places an image, and it explains most “my picture has disappeared” problems in website authoring.

How do you read a folder tree?

Look at the invented site folder from the module guide:

club/
  index.html
  style.css
  pages/
    events.html
  images/
    hall.jpg

A path starts at the page that holds the link. A folder name goes down into that folder, and ../ goes up one level. Only the position of the files relative to each other matters, never the drive letter.

How do you write the path step by step?

  1. Find the page that will contain the link or image.
  2. Find the target file and note its folder.
  3. Climb up with ../ once for each folder you must leave.
  4. Go down by naming each folder you must enter.
  5. Finish with the exact file name and extension.
  6. Click the link in a browser to prove it works.

Worked example

Link 1: from index.html to events.html. Both are in different places: events.html is inside pages. No climbing is needed, so the path goes down:

<a href="pages/events.html">Events</a>

Link 2: from events.html back to index.html. The page is inside pages, and the target is one level up:

<a href="../index.html">Home</a>

Image: events.html also shows hall.jpg. Climb out of pages, then go down into images:

<img src="../images/hall.jpg" alt="Club members in the school hall">

The same idea checks all three: leave pages with ../, then name the folders to enter.

The mistake to watch for

A common slip is copying a path that the computer shows, not one written from the page.

<a href="C:\Users\Aina\Desktop\club\index.html">Home</a>

This opens on the author’s own computer and fails everywhere else, including on the marker’s computer. A second version of the same mistake writes images/hall.jpg on events.html: that path looks for pages/images/hall.jpg, which does not exist. The correction in both cases is a relative path counted from the page: ../index.html and ../images/hall.jpg.

Check yourself

1. From index.html, write the link path to images/hall.jpg.

Show answer

images/hall.jpg. The image folder is directly below the home page folder, so no ../ is needed.

2. A page at pages/events.html links to pages/contact.html. Write the href.

Show answer

contact.html. Both files are in the same folder, so the page name alone is enough.

3. The file is Hall.JPG on disk, but the page says src="../images/hall.jpg". What may go wrong?

Show answer

The capital letters and extension do not match, so a case-sensitive server will not find it. Write the name exactly: ../images/Hall.JPG, or better, rename the file to lower case.

Where this leads next

Now that your paths work, place and describe a picture properly in Size an image with meaningful alternative text. Return to the module guide, and test your own folder with the practical task and evidence checker.

Students can read a folder tree in class and still miscount the ../ steps in a real task. Our teachers practise that route with you in online one-to-one ICT tuition.

Questions people ask

What is a relative link?

A relative link gives the path to a file starting from the page that contains the link, such as pages/events.html. Because it does not mention the drive or the computer, it keeps working when the whole site folder is copied or uploaded, as long as the files keep the same positions to each other.

What does ../ mean in a path?

It means go up one folder from the current page. A page inside pages links to the home page with ../index.html. Use it twice, ../../, to go up two levels. Count the folders between the page and the target before you write the path.

Why do file names matter in links?

The path must match the file name exactly, including capital letters and the extension. Many web servers treat Events.html and events.html as different files. Avoid spaces in names, and use lower case with hyphens, so the same text works everywhere.

Updated:

Your next step

If your links break whenever the files move, a one-to-one teacher can draw your folder tree with you and walk each path from page to target until it clicks.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service