The most fundamental truth is this: A website is not one single file.
It's a collection of different files (HTML, CSS, JavaScript, images, videos, fonts) that all need to work together. These files are organized into folders, just like documents on your computer.
If your index.html
file needs to display an image named logo.png
, how does the HTML file tell the browser where to find logo.png?
You can't just say src="logo.png"
and expect it to work every time. What if the logo is in an images
folder? What if it's on a completely different website?
The browser needs an exact, unambiguous address to locate the file. A file path is that address.
A relative file path gives directions to a file starting from the location of the file you are currently in. You will use this 99% of the time for linking your own files together (images, CSS, other HTML pages).
my-website/ ├── index.html ├── about.html │ ├── images/ │ ├── logo.png │ └── hero.jpg │ └── pages/ ├── contact.html └── terms.html
index.html
and want to link to about.html
.my-website/
folder. The directions are as simple as possible.<!-- This code is inside index.html --> <a href="about.html">About Us</a>
index.html
and want to display logo.png
.index.html
, you need to go into the images
folder to find the logo./
, and then the filename.<!-- This code is inside index.html --> <img src="images/logo.png" alt="My Website Logo">
contact.html
(which is inside pages/
) and you want to display logo.png
(which is inside images/
).pages/
to images/
. You must first go up one level out of the pages
folder to get back to the main my-website/
folder. From there, you can go down into the images
folder.../
) means "go up one level."<!-- This code is inside pages/contact.html --> <img src="../images/logo.png" alt="My Website Logo">
../
takes you from pages/
up to my-website/
.images/logo.png
then takes you down into the images
folder to find the file.
An absolute file path gives the full, complete URL to a resource on the web. It starts with http://
or https://
.
When to use it:
You ONLY use absolute paths when you are linking to a resource that is NOT on your own website.
<!-- Linking to an external website --> <a href="https://www.google.com">Search on Google</a> <!-- Using an image hosted on another server --> <img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/Html5_logo_and_wordmark.svg" alt="HTML5 Logo">
A beginner might be tempted to copy the full path from their computer, like this:
src="C:/Users/Arjun/Desktop/my-website/images/logo.png"
This is a major mistake. This address only works on your computer. The moment you upload your website to a real web server, that path becomes meaningless and the image will be broken.
Think of a web browser (like Chrome, Firefox, etc.) as a secure prison for the code it runs. This prison is called a "sandbox."
The primary rule of this prison is: Code running inside the sandbox is NOT allowed to freely access the host computer's file system.
Imagine if this security rule didn't exist. You could visit a malicious website, evil-website.com
, and it could contain the following HTML:
<!-- Malicious code --> <img src="C:/Users/Arjun/Documents/MyPrivatePasswords.txt">
If the browser allowed this, the website could potentially read the contents of your private files, your photos, your documents—anything on your computer. It would be a catastrophic security disaster.
Relative paths, however, will always work because they describe the location of files relative to each other, no matter what computer or server they are on.
filename.html
(Same folder)folder/filename.html
(Go down)../filename.html
(Go up)https://www.example.com/page.html
The Windows file system is organized into separate drives, each identified by a letter (like C:
, D:
, etc.).
C:\
. This is the "root" of that specific drive.Windows Structure:
Drive:\Folder\SubFolder\file.txt
Example:
Imagine a file named report.docx
located in the Documents
folder of a user named JohnDoe
on the main C:
drive.
The absolute path would be:
C:\Users\JohnDoe\Documents\report.docx
C:\
- Start at the root of the C drive.The macOS file system (like Linux and other Unix-like systems) does not use drive letters. Instead, it has a single, unified file system.
macOS Structure:
/Folder/SubFolder/file.txt
Example:
Let's find the same file: report.docx
in the Documents
folder for the user johndoe
.
The absolute path would be:
/Users/johndoe/Documents/report.docx
/
- Start at the absolute root of the entire file system.The HTML boilerplate is a standard template that every HTML file should start with. It provides essential setup information for the browser, such as the document type, language, character encoding, viewport settings, and the page title.
Browsers are forgiving and will try to render pages even if boilerplate code is missing, but omitting it can cause unpredictable behavior, poor mobile experience, broken characters, and bad SEO/accessibility.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> </body> </html>
The fundamental truth is that complex information is almost never presented on a single, infinitely long page. We naturally break information into distinct, self-contained topics. A book has chapters, a store has departments, and a company has different aspects (About, Services, Contact).
A multi-page website is the digital equivalent of this.
We need a way to create these distinct topic pages and, most importantly, a way for a user to navigate between them seamlessly. How do we connect home.html
to about.html
and contact.html
so that they feel like a single, cohesive "website" rather than three disconnected files?
The solution involves two key components:
<a>
(anchor) tag to create a navigation menu that appears on every single page, providing reliable doorways to all other pages.<div>
(The Generic Box)We need a way to group different elements (<h1>
, <p>
, <img>
, etc.) together into a single, conceptual unit.
Imagine you have a "user profile card" on a webpage. It consists of an image, a heading for the user's name, and a paragraph for their bio.
<img src="avatar.png"> <h2>Arjun Kumar</h2> <p>Loves to code and teach HTML.</p>
These are three separate elements. What if you want to put a border around all three of them as a single block? Or give them all a shared background color? Or move them all to the right side of the page as one unit? You have no way to target them as a group.
The most basic solution is to invent a generic, meaningless container. Its only job is to be a box that you can put other things into. It shouldn't have any inherent meaning or style; it's just a grouping mechanism.
This is the <div> (short for "division").
By wrapping our elements in a <div>
, we create a single "box" that we can now control.
<div> <img src="avatar.png"> <h2>Arjun Kumar</h2> <p>Loves to code and teach HTML.</p> </div>
Now, using CSS, we can say "put a border on that <div>
" and it will wrap around the entire group.
class
and id
(The Labels for the Box)Once we have boxes (<div>
s), we need a way to identify and find them.
Your webpage might have ten different profile cards, a sidebar, a main content area, and a photo gallery—all made of <div>
s. How do you tell the browser (specifically, your CSS or JavaScript) which box you want to style? How do you say, "Make all the profile cards have a gray background, but make the one featured profile card have a gold border?" You need a targeting system.
The logical solution is to invent two types of labels (which we call attributes) that you can add to any HTML tag.
Analogy:
Example:
<!-- The one and only main header on the page --> <div id="main-header">...</div> <!-- A card that is special --> <div id="featured-profile" class="profile-card">...</div> <!-- A standard card --> <div class="profile-card">...</div> <!-- Another standard card --> <div class="profile-card">...</div>
Now in CSS, you can target them:
#main-header { ... }
(Targets the one unique element with that ID).profile-card { ... }
(Targets ALL THREE elements with that class)#featured-profile { ... }
(Targets only the one special card to give it a gold border)<span>
(The Inline Highlighter)Sometimes we need to label and style a piece of content within a line of text, without creating a new block.
What if you want to make just a single word inside a paragraph red?
<p>This is very important information.</p>
You need to select the word "important". If you wrap it in a <div>
, it will create a line break, ruining the sentence:
<p>This is very <div>important</div> information.</p> --> Renders incorrectly.
We need a container that works just like a <div>
, but is inline, meaning it does not create a line break. It just wraps a small piece of content within the natural flow of the text.
This is the <span>.
<p>This is very <span class="highlight">important</span> information.</p>
Now you can use CSS to target the .highlight
class and make that one word red, without affecting the layout of the paragraph.
Analogy: A <span>
is like using a highlighter pen. You can mark a few words in a book without having to rip out the page and put it in a separate box.
<nav>
), and main heading.<main>
tag per page.Previous page | ![]() |
![]() |
![]() |
Next page |