Lesson 3 of 296
What a browser does with a web page
What you will learn
- Which files make a web page
- The job of HTML, CSS and JavaScript
- The steps a browser takes to show a page
- Why the order of loading matters
On this page
A web page is made of files
When the server sends a response, it sends files. The three main types are:
| File type | Job | Without it |
|---|---|---|
| HTML | Content and structure | There is no page at all |
| CSS | Look and layout | The page is plain black text on white |
| JavaScript | Behaviour | Nothing reacts when you click |
Pages also load images, fonts and videos.
A very small example
This is a complete web page with all three languages in one file.
<!DOCTYPE html>
<html>
<head>
<title>My first page</title>
<style>
h1 { color: blue; }
</style>
</head>
<body>
<h1>Hello</h1>
<button onclick="alert('You clicked')">Click me</button>
</body>
</html>- The
<h1>and<button>lines are HTML. They say what is on the page. - The
h1 { color: blue; }line is CSS. It makes the heading blue. - The
alert('You clicked')part is JavaScript. It runs when the button is clicked.
You do not need to understand every word yet. Parts 2, 3 and 4 teach each language from zero.
What the browser does: step by step
- Downloads the HTML file from the server.
- Reads the HTML from top to bottom and builds a list of everything on the page. This list has a tree shape and is called the DOM (Document Object Model).
- Finds links to other files (CSS, JavaScript, images) inside the HTML and downloads them too. Each one is a new request to a server.
- Reads the CSS and works out the style of every item.
- Works out the layout: the size and position of every item on the screen.
- Paints the pixels on the screen. Now you see the page.
- Runs the JavaScript, which can change the page after it is shown.
Showing a page on the screen is called rendering.
What is the DOM?
The DOM is the browser's own copy of the page, held in memory. For the example above it looks like this:
html
head
title
style
body
h1
buttonJavaScript changes the page by changing the DOM. When the DOM changes, the browser updates the screen. You will use the DOM a lot in Part 7.
Why this matters
- If a CSS or JavaScript file is very large, the page appears slowly, because the browser must download and read it first.
- One page can cause many requests. A page with 30 images sends at least 31 requests: one for the HTML and one for each image.
- Knowing these steps helps you explain why a site is slow, which is a common interview topic.
Common mistakes
- "The server sends a finished picture of the page." It sends text files. The browser builds the page from them on your device.
- "HTML is a programming language." HTML is a markup language. It describes content. It cannot make decisions or do calculations. JavaScript is the programming language.
How to say it in an interview
"The browser downloads the HTML and parses it into the DOM. It downloads the CSS and other resources, works out the styles and layout, then paints the page. JavaScript can then change the DOM, which makes the browser update the screen."
Key words
| Word | Meaning |
|---|---|
| HTML | The language for the content and structure of a page |
| CSS | The language for the look of a page |
| JavaScript | The programming language that makes pages interactive |
| DOM | The browser's tree-shaped copy of the page in memory |
| Rendering | Turning the files into what you see on screen |
| Parse | To read text and understand its structure |
Now prove it
This lesson is complete when you pass the quiz and all three practice levels.