Find a course

Module 1: How the Web WorksLesson 1 of 1111 min

What Happens When You Open a Website

Follow a click from your browser to a server and back, and learn what HTML, CSS and JavaScript each contribute to the page you see.

Step 1 of 13Learn

A page is just files

Maya runs a small online shop selling hand-painted phone cases. Her older cousin built the site, and Maya assumed it was some kind of magic program. Then one day she right-clicked the page and chose View Page Source. What appeared was plain text: words in angle brackets, color names, a few lines of code. That text was the website.

Every web page you visit is built from ordinary text files. Your browser downloads them and turns them into the colorful, clickable thing you see. Three languages do almost all the work:

  • HTML describes the content and its structure: this is a heading, this is a paragraph, this is a link, this is an image.
  • CSS describes how it looks: colors, fonts, spacing, and where things sit on the screen.
  • JavaScript describes behavior: what happens when you click a button, type in a box or scroll.

A useful way to remember it is a house. HTML is the walls and rooms, CSS is the paint and furniture, and JavaScript is the electricity that makes the lights switch on. You can live in a house with bare walls, but you can't paint walls that don't exist. That's why every website starts with HTML.

Step 2 of 13Diagram

Three languages, one page

Three languages, one pageParts diagram: A web page, HTML: structure, CSS: looks, JavaScript: behavior.A web pageHTML:structureCSS: looksJavaScript:behavior

Tap a shape with to see more.

Like a house: HTML is the frame, CSS the paint and furniture, JavaScript the light switches.
A web page
HTML: structure

What is on the page: headings, text, images, links.

CSS: looks

Colors, fonts, spacing and layout.

JavaScript: behavior

What happens when you click, type or scroll.

Step 3 of 13Practice · Sort into groups

Which language would you use for each job?

Tap an item, then tap its group (or drag it there).

Step 4 of 13Learn

From address bar to screen

When you type https://example.com/about.html and press Enter, a quick conversation happens, usually in well under a second.

First, your browser needs to find the computer that holds the site. Computers on the internet find each other with numeric IP addresses, not names, so the browser asks the DNS (Domain Name System), which works like a phone book: "What's the number for example.com?" DNS answers with an IP address.

Next, the browser sends a request to that computer, called a server. A server is just a computer that's always on and connected, waiting to send files. The request says, in effect, "Please send me /about.html."

The server replies with a response: a status code (200 means OK, 404 means not found) and the file itself. The browser reads the HTML, notices it also needs a CSS file, some images and maybe a JavaScript file, and requests each of those too. Finally it puts everything together and paints the page on your screen.

The https part means the conversation is encrypted, so nobody between you and the server can read or change it. That little lock icon in the address bar is your sign that the connection is private.

Step 5 of 13Practice · Put in order

Put these steps in the order they happen when you open a web page.

Drag the items, or use the arrow buttons, to put them in order.

  1. The browser requests the CSS, images and scripts the HTML mentions
  2. DNS translates the domain name into an IP address
  3. You type a web address and press Enter
  4. The browser sends a request to the server
  5. The server sends back the HTML file
  6. The browser displays the finished page

Step 6 of 13Diagram

From address bar to screen

From address bar to screenProcess diagram: Type the URL → DNS lookup → Request to the server → Response → Fetch CSS, images, JS → Browser paints the page.Type the URLDNS lookupRequest to theserverResponseFetch CSS, images,JSBrowser paints thepage

Tap a shape with to see more.

Type the URL
DNS lookup

The name example.com is turned into an IP address.

Request to the server

"Please send me /about.html."

Response

Status code (200 OK or 404 Not Found) plus the file.

Fetch CSS, images, JS

The HTML points to more files, requested one by one.

Browser paints the page

Step 7 of 13Note

Step 8 of 13Practice · Diagram

Parts of a URL

Tap the part that tells the browser which server to contact.

Tap the shape that answers the question, then press Check.

Parts of a URLParts diagram: https://www.example.com/blog/post.html, https, www.example.com, /blog/post.html.https://www.example.c-om/blog/post.htmlhttpswww.exampl-e.com/blog/post.html
https://www.example.com/blog/post.html
https

Protocol: how to talk. The s means encrypted.

www.example.com

Domain: which server to ask.

/blog/post.html

Path: which file on that server.

Step 9 of 13Practice · Match the pairs

Match each part of the web to its job.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Browser
  2. Server
  3. DNS
  4. URL
  5. Status code 404

Step 10 of 13Learn

Static and dynamic sites

Some websites send the same files to everyone. A band's info page, a school club site or your future portfolio can be a static site: a folder of HTML, CSS, JavaScript and image files that the server hands out exactly as they are. Static sites are fast, cheap (often free) to host and hard to break.

Other sites build pages on the fly. When you open a social media feed, the server runs a program that looks up your account, fetches posts from a database and assembles an HTML page just for you. These are dynamic sites, and they need server-side languages and databases.

Here's the key point for this course: even dynamic sites end up sending HTML, CSS and JavaScript to your browser. The browser doesn't care how the files were made. So the skills you learn here are the foundation of every website, simple or huge.

In this course you'll build a static site, because it's the fastest way to go from zero to something real that you can share with friends.

Step 11 of 13Compare

Static vs dynamic sites

AspectStaticDynamic
What the server doesSends the same files to everyoneBuilds pages per visitor, often from a database
ExamplesPortfolio, club page, band infoSocial network, online shop account, email
What the browser getsHTML, CSS, JSStill HTML, CSS, JS
HostingOften free and simpleNeeds a server running code

Step 12 of 13Practice · True or false

A website with a database, like a social network, sends something other than HTML, CSS and JavaScript to your browser.

Step 13 of 13Practice · Choose one

You click a link on a friend's site and see "404 Not Found". What is the most likely cause?