Skip to the workspace
Pebellslearn by building
Introduction  ›  Capstone Project

JavaScript and the Frontend

JavaScript 12 minFrontend development combines HTML for structure, CSS for looks and JavaScript for behaviour, and works best when JavaScript switches classes that CSS styles.

css / JavaScript and the Frontend

Explore each scene at your own pace.

01 · The rule

The rule

JavaScript and the Frontend

Frontend development combines HTML for structure, CSS for looks and JavaScript for behaviour, and works best when JavaScript switches classes that CSS styles.

Change state through JavaScript and let CSS describe that state's appearance.

A visitor taps "Vegetarian only" and the non-vegetarian dishes vanish. Which language did that? The button is HTML, the vanishing is CSS, and noticing the tap is JavaScript. Frontend development is the craft of making those three work together in the browser.

The rule

HTML is the noun, CSS the adjective, JavaScript the verb.

  • HTML names the things on the page: a heading, a button, a dish.
  • CSS describes them: green, large, hidden, in two columns.
  • JavaScript makes things happen: it reacts to clicks, key presses, timers and data arriving from a server, and changes the page in response.

The cleanest way for JavaScript to change how something looks is to switch a class and let CSS own the look:

.dish.is-hidden {
  display: none;
}
button.addEventListener("click", () => {
  omelette.classList.toggle("is-hidden");
});

JavaScript decides when; CSS decides what it looks like. Change the design later and the script does not need to be touched.

Frontend development is all the work that runs on the visitor's device: writing these three languages, making pages usable with a keyboard and a screen reader, keeping them fast, and making them fit any screen. Its partner, backend development, runs on servers: storing orders, checking passwords, sending data to the page.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.