HTML, CSS or JavaScript?
Three languages, three jobs. How to tell them apart at a glance — and which one to open when something breaks.
Three jobs
| Spelled out | Its job | In a house | |
|---|---|---|---|
| HTML | HyperText Markup Language | structure — what each part is | the walls, rooms and doors |
| CSS | Cascading Style Sheets | presentation — what it looks like | paint, furniture, light |
| JavaScript | — no relation to Java | behaviour — what it does | plumbing and electricity |
A house with no paint is still a house. A page with no CSS still works.
How to tell them apart
Look for the shape first. Each language has a shape you can recognise from across the room.
HTML is tags in angle brackets. An opening tag, content, a closing tag.
<a href="about.html" class="action">About me</a>
CSS is a selector, then braces, with property: value; pairs inside.
.quote {
padding: 1.5rem;
border-left: 4px solid #c2410c;
}
JavaScript is instructions. Words like let, const, function and document, round brackets, and arrows =>.
document.getElementById('go')
.addEventListener('click', () => alert('Hello'));
The clues, side by side
| Clue | HTML | CSS | JavaScript |
|---|---|---|---|
| Shape | <tag>…</tag> | selector { … } | statements, ( ), => |
| Typical words | href src alt class id | color margin display font-size | let const function document fetch |
| A comment | <!-- … --> | /* … */ | // … or /* … */ |
| Its own file | .html | .css | .js |
| Written inside a page | — | <style>…</style> or style="…" | <script>…</script> |
| Linked from a page | — | <link rel="stylesheet" href="style.css"> | <script src="nav.js"></script> |
/* … */ is the one comment that belongs to two languages: it works in CSS and in JavaScript. <!-- … --> is only HTML. // is only JavaScript — in CSS it is not a comment at all, and it breaks the rule after it.
Where they meet
One HTML file can hold all three languages. This is where it gets confusing — and where exam questions like to look.
<head>
<link rel="stylesheet" href="style.css"> <!-- HTML that points to a CSS file -->
<style>
p { color: #333; } /* CSS, inside an HTML element */
</style>
</head>
<body>
<p style="color: red;">Warning</p> <!-- HTML, with CSS in its style attribute -->
<script src="nav.js"></script> <!-- HTML that points to a JavaScript file -->
<script>
let likes = 0; // JavaScript, inside an HTML element
</script>
</body>
Look at the comments: each one is written in the language of the place it sits in.
It works the other way round too. JavaScript often carries the other two languages inside its quotes:
document.querySelector('.quote').style.color = 'red';
document.getElementById('site-header').innerHTML = '<nav>…</nav>';
Both lines are JavaScript. '.quote' is a CSS selector and color a CSS property, used from JavaScript. '<nav>…</nav>' is HTML, held as text.
Name the language of the line, not of what sits inside its quotes.
Why they are kept apart
Separation of concerns.
- Change the look of every page by editing one CSS file
- A screen reader reads the HTML and ignores the paint
- When something breaks, you know which of the three to open
And they are built in that order — progressive enhancement:
- It works. Plain HTML, readable by anything — a screen reader, a search engine.
- It looks right. CSS on top. Better, but nothing depends on it.
- It feels good. JavaScript last. If it fails, the page still works.
When it breaks: which one?
The first question when something goes wrong is not how do I fix it, but which layer is it in.
| What you see | Where to look |
|---|---|
| text in the wrong place, tags showing on the page | HTML — an unclosed tag or quote |
| a paragraph suddenly big and bold | HTML — a heading that was never closed |
| no styling at all, plain black on white | the <link> to the stylesheet — the file name or the path |
| one CSS rule ignored, the rest fine | CSS — a typo, a missing ; or a missing unit. DevTools → Styles shows it struck through |
| a button that looks right but does nothing | JavaScript — open the Console and read the red message |
| the nav and the footer are missing | the page was opened with file:// — fetch needs a server. Open it with Live Server |
| an image is missing | the path, almost always. DevTools → Network shows a red 404 |
中文 shows as ��� | HTML — the charset line is missing |
| a tiny page on a phone | HTML — the viewport line is missing |
Practice
1 · Which language?
Name the language of each line. If a line holds two languages, name both. The code is shown without colours, as it will be on paper.
1 <img src="images/hero.webp" alt="The campus at sunrise">
2 main { max-width: 48rem; margin: 0 auto; }
3 let count = 0;
4 <!-- the nav used to be here -->
5 nav a:hover { color: #c2410c; }
6 <p style="font-weight: bold;">Open every day</p>
7 fetch('nav.html').then(r => r.text());
8 /* the content column */
9 <script src="likes.js"></script>
10 document.querySelector('.quote').classList.add('liked');
Show the answers
- HTML — an image element.
- CSS — a rule for
main. - JavaScript — a variable.
- HTML — an HTML comment.
- CSS — a rule for the links inside the nav, while the mouse is over them.
- HTML and CSS — an HTML paragraph, with a CSS declaration in its
styleattribute. - JavaScript — it fetches an HTML file, but the line itself is JavaScript.
- CSS or JavaScript —
/* … */is a comment in both. On its own you cannot tell; look at what surrounds it. - HTML — an element that loads a JavaScript file.
- JavaScript —
'.quote'inside it is a CSS selector, used from JavaScript.
2 · Which layer?
Five things have gone wrong on five different sites. For each one, say which layer you would look at first — and why.
- Every page is styled except
contact.html, which is plain black on white. - On the about page, everything below the first heading is huge and bold.
- The "random quote" button does nothing. The page looks perfect.
- The site looks fine on your laptop, but on the live site every photo is missing.
- You changed the colour in the
.quoterule instyle.css, but the quotes stay the same colour.
Show the answers
- The
<link>in the head ofcontact.html. The other pages are styled, so the CSS file itself is fine — this page is not loading it. Check itshref: spelling, capitals, path. - HTML. The heading was never closed, so everything after it became part of the heading.
- JavaScript. The appearance is fine; the behaviour is not. Open the Console and read the red message.
- The paths. Almost certainly capitals —
Hero.JPGon disk,hero.jpgin the HTML — or a path to your own disk, such asC:\…. Your laptop ignores capitals; the server does not. DevTools → Network shows each image as a 404. - CSS. Check that rule: a misspelled property, a missing
;on the line above, or a selector that does not match the class in the HTML. DevTools → Styles shows a broken declaration struck through.