completefrontend

What do HTML, CSS, and JavaScript each do?

HTML gives a web page its structure, CSS gives it its style, and JavaScript makes it respond. Here's what each one does, one small page built in all three, and the order to learn them in.

Three blocks joined by plus signs: HTML for structure with a button tag, CSS for style with a button rule, and JavaScript for behavior with a line that adds one

You open an online shop and find a blue mug, with its name in big blue letters and a green Add to cart button below it. You click the button, and the cart count goes from 0 to 1. Three languages made that happen, and HTML vs CSS vs JavaScript is really a question of which one did which part.

HTML gives a web page its structure, CSS gives it its style, and JavaScript gives it behavior. HTML says what is on the page, like a heading or a button. CSS says how it looks, from colors to where things sit. JavaScript says what happens when someone clicks, types, or scrolls.

What does each one do?

Think of a person. HTML is the skeleton that gives the body its shape. CSS is the clothes and the haircut. JavaScript is the muscles that make it move.

HTML (HyperText Markup Language) describes the content of a page. You wrap each piece in a tag, a label in angle brackets like <h1> for a main heading or <button> for a button. A tag and everything inside it is called an element.

CSS (Cascading Style Sheets) describes how those elements look. You write rules: pick some elements, then set their color, size, spacing, and position. One rule can style every button on a site at once.

JavaScript is a programming language that runs in the browser. It can react to events, like a click or a key press. It can also change the page while you look at it. It does that through the DOM, the browser's live model of the page that code can read and change.

Is HTML a programming language?

No. HTML is a markup language: it labels content, but it can't do math or make decisions. CSS isn't a programming language either. It's a style sheet language, a list of rules about how things look.

JavaScript is the only one of the three that is a full programming language. It can store values, compare them, repeat steps, and make choices. That's why the shop's button needs JavaScript to count.

Building one small page in three steps

Here's that shop page, built one layer at a time.

1. Write the HTML

<h1>Blue mug</h1>
<p>Items in cart: <span id="count">0</span></p>
<button id="add">Add to cart</button>

This gives the page a heading, a line of text, and a button. An id gives an element a unique name, so CSS and JavaScript can find it. Open the file in a browser and you'll see plain black text on white. The button does nothing yet.

2. Style it with CSS

body {
  font-family: sans-serif;
}

h1 {
  color: royalblue;
}

button {
  background: seagreen;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
}

Each rule starts with a selector, which picks the elements to style. The body rule covers the whole page, so everything gets a clean font. The heading turns blue, and the button turns green with rounded corners. Clicking it still does nothing.

3. Add behavior with JavaScript

const button = document.querySelector("#add");
const count = document.querySelector("#count");
let items = 0;

button.addEventListener("click", () => {
  items = items + 1;
  count.textContent = items;
});

The first two lines find the button and the number on the page. items keeps the count. Then addEventListener tells the browser to run a function, a small set of steps, on every click. That function adds one and writes the new number into the page.

Three steps of one page: HTML gives a plain heading, line of text, and gray button; CSS turns the heading blue and the button green; JavaScript makes a click change the count from 0 to 1
The same page after each layer: HTML, then CSS, then JavaScript.

How the three files connect

Each language usually lives in its own file. Two lines in the HTML's <head> section tie them together:

<link rel="stylesheet" href="style.css">
<script src="script.js" defer></script>

The link tag loads the CSS. The script tag loads the JavaScript. defer tells the browser to run the script after it has read all the HTML, so the button exists when the script looks for it. The first script lesson shows other ways to load a script.

HTML, CSS and JavaScript side by side

HTML CSS JavaScript
Its job Structure and meaning Looks and layout Behavior
Kind of language Markup language Style sheet language Programming language
What it looks like <button>Add</button> button { color: white; } items = items + 1;
File type .html .css .js
Without it Nothing to show Plain default styles No counting or live updates
Can it change the others? No No Yes, through the DOM

Which should you learn first?

Learn them in order: HTML, then CSS, then JavaScript. Each one builds on the one before. CSS styles HTML elements, and JavaScript reads and changes them.

You don't need to master HTML and CSS first. Learn enough HTML to write headings, links, images, and a form. Learn enough CSS to set colors, spacing, and a simple layout. Then start JavaScript, and keep growing the other two along the way.

Can you build a website with just HTML and CSS?

Yes. A portfolio, a restaurant's menu page, or a simple blog can work with no JavaScript at all. HTML even has some built-in behavior. Links open other pages, forms send what you type to the website, and the <details> element opens and closes on its own.

You need JavaScript when the page has to think. Counting items, checking a form while you type, and loading new posts without reloading the page are all JavaScript jobs.

What do beginners mix up?

  • Java and JavaScript. They are two different languages that share part of a name. Why JavaScript? clears this up.
  • Picking tags for their looks. Use <h1> because the text is the page's main heading. If you want it bigger or smaller, change that with CSS. Semantic HTML explains why the right tags matter for people using screen readers, apps that read a page aloud.
  • Using JavaScript for things CSS can do. A color change on hover and a simple animation need only CSS. Reach for JavaScript when CSS can't do the job.

Where can you learn each one?

For HTML and CSS, MDN's Learn web development guides go step by step. Our posts cover the CSS questions beginners ask most: how to center a div, flexbox vs grid, and the CSS box model.

For JavaScript, the JavaScript course starts from zero. Begin with Why JavaScript?, set up your tools in your development environment, and write your first script. To change a page with code, read the DOM tree, events, and styles and classes.

Wondering how long it takes? Read how long it takes to learn JavaScript. After that, the React course shows how real apps are built on all three.

Written by Shrikanth PS

Senior Software Engineer at Microsoft, working on Copilot Enterprise, with more than nine years in frontend engineering.