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.