A website is not just one file. It is a collection of files: HTML, CSS, JavaScript, images, fonts, and videos. These files are organized into folders (directories). A file path tells the browser exactly where to find a resource.
If index.html needs to show logo.png, how does the browser find it? It needs an exact address (path). Paths can be:
my-website/
├── index.html
├── about.html
├── images/
│ ├── logo.png
│ └── hero.jpg
└── pages/
├── contact.html
└── terms.html
Relative paths describe a file's location starting from the file you are editing.
|
|
<img src="/images/logo.png" alt="Logo from root">
Works only on servers, not on local files.
Use full URLs for resources hosted on other websites or CDNs:
<a href="https://www.google.com">Google</a>
<img src="https://upload.wikimedia.org/.../Html5_logo_and_wordmark.svg" alt="HTML5 Logo">
Wrong examples:
Windows: C:\Users\Arjun\Desktop\my-website\images\logo.png
macOS/Linux: /Users/johndoe/Desktop/my-website/images/logo.png
These paths only exist on your computer. They will break when uploaded or opened elsewhere.
Browsers block access to your personal files for safety. Example of a dangerous attempt:
<img src="C:\Users\Arjun\Documents\Passwords.txt">
Browsers block this → otherwise websites could steal your private data.
| Feature | Windows | macOS / Linux |
|---|---|---|
| Starting Root | C:\ (Drive letter) |
/ (Single root) |
| Separator | \ (backslash) |
/ (forward slash) |
| Example Path | C:\Users\John\Docs\file.txt |
/Users/john/Docs/file.txt |
Logo.png ≠ logo.png).
<!-- CSS in same folder -->
<link rel="stylesheet" href="styles.css">
<!-- JS inside a js/ folder -->
<script src="js/app.js"></script>
<a href="about.html">About</a>
<img src="images/logo.png" alt="Logo">
<img src="../images/logo.png" alt="Logo">
<img src="https://example.com/photo.jpg" alt="External">
<a href="https://example.com" target="_blank">Visit Site</a>
Every HTML file should start with a boilerplate. It sets encoding, title, viewport, etc.
<!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>
</html>
<!DOCTYPE html> → tells browser to use HTML5.<meta charset="UTF-8"> → encoding for all characters.<meta name="viewport"> → responsive for mobiles.<title> → shown in browser tab.A website is often made of multiple HTML files. Example: Home, About, Contact.
<nav>
<a href="index.html">Home</a> |
<a href="about.html">About</a> |
<a href="contact.html">Contact</a>
</nav>
Use: To group multiple elements as one block.
<div>
<img src="avatar.png">
<h2>Priyanka</h2>
<p>Loves HTML</p>
</div>
<div id="main-header">Header</div>
<div class="profile-card">Card</div>
<div class="profile-card">Card</div>
Use: To highlight words inside text.
<p>This is very <span>important</span> text.</p>