The Three Layers of the Web
HTML structures, CSS styles, JavaScript behaves — and why this separation matters
Skills taught: web.three-layers, web.separation-of-concerns, web.progressive-enhancement
Three technologies, three jobs
Every web page is built from three technologies that each have a distinct role. Understanding this separation is the foundation of all web development.
┌─────────────────────────────────────────────────────────┐
│ JAVASCRIPT — Behavior (the verbs) │
│ Responds to events, manipulates the DOM, fetches data │
├─────────────────────────────────────────────────────────┤
│ CSS — Presentation (the adjectives) │
│ Colors, fonts, sizes, layout, animation │
├─────────────────────────────────────────────────────────┤
│ HTML — Structure (the nouns) │
│ Headings, paragraphs, images, buttons, links │
└─────────────────────────────────────────────────────────┘
Each layer builds on the one below it.
What each layer does
<!-- HTML: What is it? (structure, meaning) -->
<button class="buy-btn" id="addToCart"
aria-label="Add iPhone 15 to cart">
Add to cart
</button>
<!-- CSS: What does it look like? (in a separate .css file) -->
.buy-btn {
background: #ff6900;
color: white;
padding: 12px 24px;
border-radius: 6px;
font-size: 1rem;
cursor: pointer;
transition: background 0.2s;
}
.buy-btn:hover { background: #e55a00; }
// JavaScript: What does it do? (in a separate .js file)
document.getElementById('addToCart').addEventListener('click', () => {
cart.add(product);
showToast('Added to cart!');
});
- HTML — The skeleton. Defines what is on the page and its semantic meaning. Without HTML, there is nothing.
- CSS — The skin and clothes. Controls how everything looks. Without CSS, the page is readable but unstyled.
- JavaScript — The muscles. Makes the page respond to user actions and data. Without JS, the page is static but still functional.
Progressive enhancement
Progressive enhancement means building from the bottom up: start with working HTML, add CSS to make it look good, then add JavaScript to make it interactive. The page should be usable at every layer.
Tip: A form with <button type="submit"> works without JavaScript — it submits to the server. JavaScript can then enhance this with client-side validation and AJAX submission. This is progressive enhancement: the basic action works with or without JS.
Frequently Asked Questions
React uses JSX which mixes HTML and JavaScript. Does that break the three-layer model?
React moves the separation from files (HTML file, CSS file, JS file) to components (one file per feature). JSX is JavaScript that looks like HTML — it is all compiled to createElement() calls. The browser still processes the three layers. The argument is that separating by feature (UserCard component) is more maintainable than separating by technology (HTML folder, CSS folder, JS folder) for large apps.
Should I use inline styles?
Avoid inline styles. They mix presentation into structure, they cannot be reused, they cannot be overridden with CSS (short of !important), and they are harder to maintain. The exception: dynamically computed values that only make sense as JavaScript expressions, like style={{ width: percentage + '%' }} in React, where the value comes from state.