Welcome to the fascinating world of HTML file paths! This lesson will guide you through understanding how to organize your HTML files, link them together, and navigate them like a pro. 🎯
HTML file paths help you structure and connect your HTML files within a project. This organization not only makes your project manageable but also enhances its performance and readability.
Before diving into file paths, let's first discuss the basic structure of an HTML project:
project-name/
- index.html
- styles/
- style.css
- scripts/
- script.js
Here, the project has three main folders: index.html (the main HTML file), styles/ (for CSS files), and scripts/ (for JavaScript files).
Relative file paths are used to link one file to another within the same project. There are two types of relative paths:
/) or a double slash (//).Example:
<!-- Linking to a CSS file in the same folder -->
<link rel="stylesheet" href="style.css">
<!-- Linking to a CSS file in the parent folder -->
<link rel="stylesheet" href="styles/style.css">//) before the file path.<!-- Linking to a CSS file in the root directory -->
<link rel="stylesheet" href="/styles/style.css">Absolute file paths are used to link files using the full path from the project root. This is useful when linking to external files.
<!-- Linking to an external CSS file -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">What are the two types of relative file paths in HTML?
Happy coding! 🎉