Blog / How the internet works /
HTML, CSS and JavaScript: the three layers of the web
Open any website, right-click, choose “View source”, and you’ll see a wall of text. Strange tags, curly brackets, symbols. It looks like a different language.
It is, kind of. Three of them, in fact. They each do a different job, and once you see the split, websites become much less mysterious.
The house analogy
Think of a house.
- HTML is the structure: walls, floors, doors, rooms. It says what’s on the page.
- CSS is the decoration: paint colours, furniture layout, window sizes. It says how things look.
- JavaScript is the electricity and plumbing: lights that switch on, doors that open, taps that run. It says what things do.
A page can exist with just the structure (plain, but readable). Add the decoration and it looks designed. Add the wiring and it becomes interactive.
HTML: what’s on the page
HTML (HyperText Markup Language) labels content. A heading is marked as a heading, a paragraph as a paragraph, a link as a link, an image as an image.
<h1>Welcome to my bakery</h1>
<p>Fresh bread every morning.</p>
<a href="/menu/">See the menu</a>
<img src="loaf.jpg" alt="A golden loaf of bread">
These labels are called tags. They give meaning, not looks. Browsers, screen readers and search engines all depend on that meaning to understand a page: which text is the main heading, where the navigation is, what an image shows.
That’s why good HTML matters for accessibility and search. A heading that is only a big bold paragraph looks right to a human but says nothing to a machine.
CSS: how it looks
CSS (Cascading Style Sheets) tells the browser how to display the HTML: colours, fonts, spacing, positions, and how the layout should change on a phone versus a desktop.
h1 {
color: #1a1a1a;
font-size: 2rem;
}
Because the style lives separately from the content, you can redesign an entire site by changing the CSS without rewriting a single page. This is the idea behind themes: the content stays, the look swaps.
“Cascading” means rules can stack and override each other. A general rule applies to all headings, a more specific rule changes just one. Understanding that order explains many “why won’t this change?” moments.
JavaScript: what it does
JavaScript is a programming language that runs in the browser. It reacts to things you do and changes the page without reloading it:
- Opening a menu on a phone.
- Validating a form before you submit it.
- Loading more products as you scroll.
- Showing a cookie banner.
- Running a live chat widget.
- Updating a cart count instantly.
document.querySelector("button").addEventListener("click", function () {
alert("Added to cart");
});
This is the one that can go wrong in the most ways, because it’s code that runs on every visitor’s device.
How they work together
When your browser loads a page, roughly this happens:
- It downloads the HTML and starts building the page’s structure.
- It finds linked CSS files, downloads them and applies the styling.
- It finds JavaScript files, downloads and runs them, which may change the page further.
- It fetches images, fonts and everything else.
Because of the order, a few heavy CSS or JavaScript files at the top of a page can delay what the visitor sees. Browsers have to download and process them before painting, which is why speed advice often says “defer” or “reduce” scripts.
Why this matters for speed
Each layer has its own costs:
- HTML is usually light. Bloated page builders can make it heavy, though.
- CSS blocks display until it loads, so large unused stylesheets slow the first paint.
- JavaScript takes the most time: downloading, parsing, running. Too much of it makes pages feel sluggish when tapped. I covered the effects in reducing JavaScript on WordPress for better INP.
When you add a plugin, app or widget, you usually add all three layers. That’s why the number of add-ons affects performance, a point I made in auditing your WordPress plugins before they slow you down.
Why this matters for search
Search engines read HTML first. Content that exists in the HTML is easy to see. Content that only appears after JavaScript runs can be slower to process, or missed if something fails. For most sites, Google does render JavaScript, but it’s an extra step. If you want the details, JavaScript SEO basics for site owners explains when it matters.
A simple test: view the page source and check whether your main text, headings and links are visible there. Or try reviewing important pages with JavaScript disabled.
What this means if you don’t write code
You don’t need to be a developer to benefit. Knowing the layers helps you:
- Brief designers and developers: “the HTML heading order is wrong” and “the CSS is loading too much” are different problems.
- Debug: a broken layout points to CSS, a broken button to JavaScript, missing text to HTML or content.
- Judge plugins: ask what scripts and styles a plugin adds to every page.
- Understand AI builders: tools that generate sites are generating all three; I touched on that in HTML, CSS and JavaScript explained for AI builders.
Common myths
- “HTML is a programming language.” It’s a markup language: it describes, it doesn’t compute.
- “JavaScript is the same as Java.” They’re unrelated apart from the name.
- “More JavaScript means a better site.” Often the opposite.
- “CSS is just for looks.” It also controls layout on every screen size, so it affects usability.
Key takeaways
- HTML is structure, CSS is appearance, JavaScript is behaviour.
- Browsers load them in a sequence, and heavy files can delay what you see.
- Good HTML helps accessibility and search; too much JavaScript hurts speed.
- Knowing which layer is at fault makes debugging faster.
Related reading
Next time a page looks wrong or acts oddly, ask: is this a structure problem, a style problem or a behaviour problem?