Code Bytes · "Web Fundamentals" · Episode 2 · How the web works
Front end vs back end
Every website has two sides. The front end is everything in your browser, the layout, the text and the buttons you tap, built with HTML, CSS and JavaScript and running on your own device. The back end runs on the server, where it stores data, checks passwords and works things out, then sends the results back to the front end.
A restaurant has two sides
Think of a restaurant. The dining room is where you sit, read the menu and get your food. The kitchen is behind a door: the cooking, the stock of ingredients and the orders all happen there, out of sight.
A website works the same way. The dining room is the front end. The kitchen is the back end.
The front end: what you see and tap
The front end is everything in your browser: the layout of the page, the text, the pictures and the buttons you tap. It's also called the client side.
It's built with three languages:
- HTML says what is on the page: headings, paragraphs, buttons.
- CSS says how it looks: colours, fonts, sizes, where things sit.
- JavaScript makes it react: what happens when you tap, type or scroll.
All three are sent to your browser and run on your own device, your phone, tablet or laptop.
The back end: what you don't see
The back end runs on the server (the computer that answers your browser's requests, from the last lesson). It's also called the server side. Its jobs include:
- storing data, such as accounts, orders and messages (usually in a database),
- checking passwords when someone logs in,
- working things out, such as the price of everything in your basket.
Then it sends the results back to the front end.
Both sides working together
Tap add to cart in an online shop:
- The front end sends a request to the server.
- The back end saves your cart.
- An answer comes back, and the front end shows your cart with 1 item.
You only ever see steps 1 and 3. Step 2 happens in the kitchen.
Try it yourself
On a laptop or desktop, open any website in Chrome, Edge or Firefox, right-click the page and choose View page source. Everything in that tab (the HTML, plus links to CSS and JavaScript files) is front-end code your browser was sent.
Now think about what is not in there: you won't find the site's list of users, their passwords or the code that works out prices. That all stays on the server, in the back end.
Good to know
- No code is run in this episode. The web course's code starts in the next lesson, with HTML.
- This is the beginner rule, and it's simplified. JavaScript can also run on servers (for example with Node.js), and servers can build a page's HTML before sending it (called server-side rendering), so the line between the two sides is sometimes blurry.
- The request and the answer are messages in a format called HTTP, from the last lesson.
- Some shops keep your cart in the browser until you check out, and only send it to the server then.
- A developer who works on both sides is often called a full-stack developer.
- The restaurant comparison is ours, not an official definition.
Answer to the comment question
Button colors, saving your order, page layout, checking your password. How many of these are back-end jobs?
2. Saving your order and checking your password are back-end jobs: they happen on the server. Button colors and page layout are front-end jobs: they are what you see in your browser, set by HTML and CSS.
Test your knowledge
Quick quiz: Front end vs back end
4 multiple-choice questions. Pick one answer for each, then check how you did.
Sources
- MDN Web Docs, "Front-end": the front end is the part of a site that runs in the browser and that people see and use, built with HTML, CSS and JavaScript
- MDN Web Docs, "Back-end": the back end is the part of a site that runs on the server and isn't seen by the user
- MDN Web Docs, "Introduction to the server side": server-side code stores and reads data, checks who a user is, and sends results back to the browser
Video transcript
Front end or back end? It's what you see, versus what you don't.
Think of a restaurant: the dining room is the front end, the kitchen is the back end.
On a website, the front end is everything in your browser: the layout, the text, the buttons you tap.
It's built with HTML, CSS and JavaScript, which run on your own device.
The back end runs on the server. It stores data, checks passwords and works things out.
Tap add to cart: the front end sends a request, the back end saves your cart, and the front end shows one item.
Button colors, saving your order, page layout, checking your password. How many of these are back-end jobs? Comment your answer below!
That's your byte.