Metadata
- Date :: 13-04-2025
- Tags :: web-dev
Notes
π Creating Multi-Page Websites Using File Paths
Learn how to connect multiple HTML pages and use images as clickable links using correct file path strategies.
π 1. Website Folder Structure
πΈ Single Page Project (Before):
Project/
βββ index.html
βββ assets/
β βββ images/
β βββ cat.png
-
index.htmlis the homepage. -
Assets (like images, CSS, JS) are stored in separate folders like
/assets/images/.
πΈ Multi-Page Project (Now):
Project/
βββ index.html β Homepage
βββ public/
β βββ about.html β About Me page
β βββ contact.html β Contact Me page
βββ assets/
β βββ images/
β βββ cat.png
-
Now we include additional HTML files inside the
public/folder. -
index.htmlis still the homepage, but we link to other pages using anchor (<a>) tags.
π 2. Linking Web Pages with Anchor Tags
πΉ Basic Syntax:
<a href="path/to/page.html">Link Text</a>π§ Example from the Lesson:
If youβre inside index.html and want to link to about.html (which is in /public/):
<a href="./public/about.html">About Me</a>-
./points to the current directory (whereindex.htmllives). -
Then we go into the
public/folder β and toabout.html.
β When clicked, the browser navigates to that HTML file and displays its contents.
πΌοΈ 3. Linking Images (as Content)
πΉ Displaying an Image:
<img src="path/to/image.jpg" alt="Description" />π§ Example:
To show an image from this structure:
index.html
assets/
βββ images/
βββ cat.png
You would write:
<img src="./assets/images/cat.png" alt="A cute cat" />-
./β current directory (whereindex.htmlis). -
/assets/images/cat.pngβ path to the image.
ππΌοΈ 4. Making an Image Clickable (Using as a Link)
To create an image that functions like a button (links to another page):
β Correct Way:
<a href="./public/about.html">
<img src="./assets/images/cat.png" alt="About Me Image" />
</a>-
The
<a>tag wraps around the<img>tag. -
When the image is clicked, the user is redirected to the
about.htmlpage. -
This is how we created a clickable image that links to the About page in the challenge.
π 5. File Path Quiz Recap
You were asked:
From index.html, what is the correct path to display cat.png inside assets/images/?
β Incorrect Options:
-
../assets/images/cat.png- β Goes up one level (outside the Project folder) β unnecessary here.
-
Using
hrefinstead ofsrcinside<img>tag:- β
<img>usessrc, nothref.
- β
-
Using
<a>tag to display an image:- β
<a>creates links, not image displays.
- β
β Correct Option:
<img src="./assets/images/cat.png" alt="Cat Image" />Why itβs correct:
-
./means look in the current folder. -
From
index.html, go intoassets/images/β findcat.png.
π» 6. Challenge Breakdown
You were asked to perform two tasks:
πΆ Task 1: Add a Link to the βContact Meβ Page
From index.html (in Project/) to contact.html (in public/):
<a href="./public/contact.html">Contact Me</a>β When clicked, it should open the contact page.
π· Task 2: Create a Clickable Image That Links to the βAbout Meβ Page
Steps:
-
Wrap image in anchor tag:
-
Correctly reference the image and page using relative paths.
<a href="./public/about.html">
<img src="./assets/images/cat.png" alt="About Me Image" />
</a>π Clicking the image redirects the user to about.html.
π 7. Revision: Understanding File Paths Again
| Path | Meaning | Example |
|---|---|---|
./ | Current directory | ./about.html |
../ | Move one level up | ../assets/logo.png |
folder/filename | Inside sub-folder | images/photo.jpg |
β Good Practices:
-
Always use relative paths in web projects.
-
Use
./for current directory files. -
Use
../only when needed to go up one level. -
Wrap your images in anchor tags if you want them to act as links.
-
Use VS Code auto-suggestions to avoid typos and find the correct paths quickly.
π 8. Debugging File Path Issues
If an image or link doesnβt work, check:
-
π€ Spelling errors in file or folder names.
-
π Wrong use of
../or./. -
π File may not exist or is in the wrong folder.
-
β Used
hrefinstead ofsrcfor images. -
β Forgot to wrap the image with
<a>for clickable links.
π― What You Can Do Now
You should now be able to:
-
β Structure a multi-page website properly.
-
β Link multiple HTML pages using anchor tags.
-
β Display images from nested folders using file paths.
-
β Make images clickable and link them to other pages.
-
β Debug broken paths by understanding folder structure.
π§ͺ Suggested Exercises for Practice
-
π Create a 3-page portfolio (Home, About, Projects).
-
πΌοΈ Add a personal image that links to a βResumeβ page.
-
π Reorganize your folders and see if your relative paths still work.
-
β Break the file path intentionally and fix it to build muscle memory.
Let me know if youβd like:
-
β A starter multi-page template.
-
β A cheat sheet of file path rules.
-
β A visual guide of folder navigation.