HTML, CSS, and JavaScript Integration
> Organize a frontend project and connect HTML documents to external CSS and JavaScript files.
**Cyber Code Academy · HTML Tutorial · Lesson 31 · Intermediate**
## 1. How frontend technologies work together
A browser-based frontend commonly uses three core technologies:
– HTML provides structure and meaning.
– CSS controls presentation and layout.
– JavaScript adds behaviour and application logic.
Keeping these responsibilities in separate files makes projects easier to maintain, debug, reuse, and extend.
## 2. Recommended beginner project structure
“`text
my-website/
├── index.html
├── about.html
├── css/
│ └── styles.css
├── js/
│ └── app.js
└── images/
└── logo.png
“`
Each folder has a clear responsibility:
– HTML files describe pages.
– css contains stylesheets.
– js contains scripts.
– images contains image assets.
## 3. Connect CSS to HTML
Inside the head element, use a link element:
“`html
“`
The href path is relative to the HTML document. Check spelling and directory names if the stylesheet does not load.
## 4. Create an external CSS file
styles.css:
“`css
* {
box-sizing: border-box;
}
body {
font-family: system-ui, sans-serif;
line-height: 1.6;
margin: 0;
padding: 2rem;
color: #172033;
}
h1 {
color: #2563eb;
}
“`
The universal selector sets box sizing for all elements and pseudo-elements can be included when needed. The body rule defines common page styles.
## 5. Connect JavaScript to HTML
Add a script element with defer:
“`html
“`
This loads a classic external script without blocking HTML parsing, then runs it after parsing.
## 6. Create an interactive page
HTML:
“`html
Welcome to my website
“`
JavaScript:
“`javascript
const button = document.querySelector(“#change-title”);
const title = document.querySelector(“#title”);
button.addEventListener(“click”, () => {
title.textContent = “You connected JavaScript!”;
});
“`
When the visitor selects the button, JavaScript finds the heading by its ID and changes its text.
## 7. Add an image asset
“`html

“`
Keep image paths organized and provide appropriate alternative text. Avoid storing local absolute paths from your computer in public HTML.
## 8. Full starter example
“`html
Welcome
HTML structures this content.
“`
## 9. Debugging integration problems
If styles do not appear:
1. Check the link href.
2. Confirm styles.css exists.
3. Inspect the Network panel.
4. Look for a 404 response.
5. Check the CSS selector and specificity.
If JavaScript does not run:
1. Check the script src path.
2. Confirm the file exists.
3. Inspect the Console panel.
4. Check for spelling errors and null selectors.
5. Verify the script is loaded after the relevant elements are parsed.
## 10. Common mistakes
– Wrong relative paths.
– Forgetting to save changes.
– Missing defer when the script depends on page elements.
– Repeating IDs.
– Mixing all CSS and JavaScript into a very large HTML file.
– Using inline styles for every element.
– Expecting a CSS or JavaScript file to work when linked with the wrong attribute.
## 11. Practice project
Create a mini course landing page:
1. Build the HTML structure.
2. Add a separate CSS stylesheet.
3. Add a separate JavaScript file.
4. Create a Change Theme button that toggles a class on body.
5. Keep keyboard focus visible.
6. Test at mobile and desktop widths.
## 12. Knowledge check
1. What is the responsibility of HTML?
2. How is CSS linked to a page?
3. How is JavaScript linked to a page?
4. What does defer do?
5. Why should files be organized into folders?
6. How can the Network panel help debug missing assets?
**Next lesson:** HTML Validation and Debugging.
Want to learn this professionally?
Explore practical IT training at Cyber Code Academy.
View Academy Courses