—HTML Series · Post 13: File Structure & Organization

HTML File Structure & Organization
File Structure & Organization — Your Project's Blueprint | CodeHerWay
Post 13 · HTML Fundamentals

HTML File Structure:
Your Project's Blueprint

A clean folder structure is the difference between a project you can maintain and a project that makes you cry at 2am. Let's set it up right from the start.

#HTML #ProjectSetup #Beginner 8 min read

You can write perfect HTML, flawless CSS, and brilliant JavaScript — but if your files are scattered everywhere with no structure, your project is a ticking time bomb. One wrong file path and your styles vanish. One misplaced script and nothing works.

File structure isn't glamorous. Nobody's going to compliment your folder names. But it's the invisible architecture that holds everything together. And if you learn it now, you'll never have to untangle a messy project later.

This post covers three things: how to link CSS to your HTML, how to link JavaScript, and how to organize your project folders like a professional.

Linking CSS — The <link> Tag

CSS goes in its own file (never inline in your HTML for real projects). You connect it to your HTML using the <link> tag inside the <head>.

HTML · index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Project</title> <!-- Link your stylesheet here --> <link rel="stylesheet" href="css/styles.css"> </head>

Three attributes matter here: rel="stylesheet" tells the browser this is a CSS file, href is the path to the file, and the fact that it's in the <head> means the browser loads styles before rendering the page — so users never see a flash of unstyled content.

💡 Multiple Stylesheets

You can link more than one CSS file. This is common in larger projects where you might split styles into reset.css, layout.css, and components.css. They load in order — so styles in the last file override earlier ones if there are conflicts.

Linking JavaScript — The <script> Tag

JavaScript gets connected with the <script> tag. But unlike CSS, where you place it matters a lot.

HTML · index.html
<!-- ❌ In the <head> without defer — blocks page rendering --> <head> <script src="js/app.js"></script> </head> <!-- ✅ Option 1: At the bottom of <body> --> <body> <!-- ...all your HTML content... --> <script src="js/app.js"></script> </body> <!-- ✅ Option 2: In <head> with defer --> <head> <script src="js/app.js" defer></script> </head>
⚠️ Why Placement Matters

When the browser hits a <script> tag, it stops rendering the page and downloads/runs that JavaScript first. If your script is in the <head> without defer, users see a blank page while the script loads. Put it at the bottom of <body> or use defer — both ensure the HTML loads first.

What About "defer" vs "async"?

You'll see both of these attributes on script tags. Here's the quick version:

defer — downloads the script in the background and runs it after the HTML is fully parsed. Scripts run in order. This is what you want 99% of the time.

async — downloads in the background but runs as soon as it's ready, even if the HTML isn't done. Scripts might run out of order. Use this only for independent scripts like analytics that don't interact with your page content.

Folder Structure — The Professional Setup

Here's the folder structure you should use for every project from this point forward. It's simple, scalable, and what you'll see in real-world codebases:

📁 my-project/
📄 index.html entry point
📁 css/
🎨 styles.css styles
📁 js/
app.js logic
📁 images/
🖼️ hero.jpg
🖼️ logo.svg
🖼️ profile.png
📁 assets/
🔤 fonts/
🎬 videos/

index.html sits in the root — it's your entry point, the first page browsers load. CSS goes in its own css/ folder. JavaScript in js/. Images in images/. Everything has a home.

🧠 Why This Matters

When you push code to GitHub, deploy to Netlify, or hand off a project to another developer — they should be able to open your folder and immediately understand what's what. If everything is dumped in one folder with names like style2-final-FINAL.css, that's chaos. Organization is communication.

Growing Projects — The Expanded Structure

As your projects get bigger, the structure scales naturally:

📁 codeherway/
📄 index.html
📄 about.html
📄 courses.html
📄 blog.html
📁 css/
🎨 reset.css
🎨 layout.css
🎨 components.css
📁 js/
app.js
navigation.js
📁 images/
📁 assets/

Multiple HTML pages sit in the root. CSS files split by concern. JavaScript files split by feature. Same principle — just more files.

Understanding File Paths

When you link a CSS file or an image, the browser needs to know where that file lives. That's what file paths are — directions from one file to another. There are three types you'll use:

Relative
css/styles.css — relative to the current file's location. Most common. Use this for your own project files.
Parent
../images/logo.png — the .. goes up one folder. Use when linking from a nested file back to a sibling folder.
Root-relative
/css/styles.css — starts from the website's root. Works on live servers but can break locally.
Absolute
https://fonts.google.com/... — the full URL. Use only for external resources like CDNs and Google Fonts.
HTML · File Paths in Action
<!-- From index.html in the root --> <link rel="stylesheet" href="css/styles.css"> <img src="images/hero.jpg" alt="Hero image"> <script src="js/app.js" defer></script> <!-- From a page inside a /pages/ folder --> <link rel="stylesheet" href="../css/styles.css"> <img src="../images/hero.jpg" alt="Hero image"> <!-- External resources — full URL --> <link href="https://fonts.googleapis.com/css2?family=..." rel="stylesheet">
💡 The #1 Debugging Tip

If your CSS isn't loading or your image is broken, it's almost always a path issue. Open your browser's DevTools (F12), check the Console for 404 errors, and look at the Network tab to see which file path the browser is trying to load. Fix the path, fix the problem.

Naming Conventions — The Unwritten Rules

File naming seems trivial until you deploy a project and discover that your server is case-sensitive and Hero.jpg is not the same as hero.jpg. Here are the rules that will save you pain:

Naming Rules
// ❌ Don't do this My Project/ Home Page.html Style Sheet (Final).css IMG_4892.JPG App copy 2.js // ✅ Do this my-project/ index.html css/styles.css images/hero-banner.jpg js/app.js // Rules: // → All lowercase // → Hyphens for spaces (not underscores, not spaces) // → No special characters // → Descriptive but short // → Your main page is always index.html
ℹ️ Why "index.html"?

Web servers look for index.html by default. When someone visits yoursite.com, the server automatically serves index.html. If your file is named home.html or main.html, the server won't find it without extra configuration. Always name your main page index.html.

// dev_fession

My first project had everything in one folder. HTML, CSS, JavaScript, 47 images, a README, and a random text file called "notes.txt" that I used as a to-do list. Finding anything meant scrolling through a wall of files.

When I tried to deploy it, half the image paths broke because I had spaces in folder names and mixed uppercase and lowercase letters. The entire site loaded with broken images and no styles.

Spent an entire Saturday renaming files and fixing paths. Now I set up my folder structure before I write a single line of code. Every time. 📁

🔨 Mini Build: Set Up a Portfolio Project

Create a properly structured portfolio project from scratch:

1
Create a root folder called portfolio with subfolders: css/, js/, images/.
2
Create index.html in the root with a full HTML boilerplate. Link a css/styles.css file in the head and a js/app.js file at the bottom of the body (or in the head with defer).
3
In styles.css, add a simple body style (background color, font family) to verify the link works.
4
In app.js, add a console.log("Connected!") and verify it appears in DevTools to confirm the script is linked.
5
Add a placeholder image to images/ and reference it in your HTML with the correct relative path. Confirm it renders.

The Bottom Line

File structure is one of those skills that seems boring until the day it saves you hours of debugging. CSS connects via <link> in the head. JavaScript connects via <script> at the bottom of the body (or with defer). Your project lives in organized folders with lowercase, hyphenated file names.

Set up your folder structure first — before you write any HTML. Get your links working — before you build any features. It takes two minutes and prevents hours of frustration. This is how professionals start every project.

Previous
Previous

—HTML Series · Post 14: HTML Meta Tags & SEO

Next
Next

—HTML Series · Post 12: HTML Tables