Find a course

Module 1: How Web Pages WorkLesson 1 of 1210 min

How Websites Work

Learn how browsers and servers deliver a page, what HTML, CSS and JavaScript each do, and how to view and inspect the code behind any website.

Step 1 of 14Learn

A page is just a text file

Open any website, right-click on the page and choose View Page Source. You'll see a wall of text full of angle brackets: <div>, <p>, <a href="...">. That text is HTML, and it's what the website actually sent to your browser. Everything you see, the headings, images, buttons and layout, was built by your browser from text files like that one.

That's the most encouraging fact for a beginner: a web page is a plain text file. You can write one in any text editor, save it as index.html, double-click it, and your browser will display it. No special software, no compiling, no account needed.

Here is a complete, working page:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My first page</title>
  </head>
  <body>
    <h1>Hello, web!</h1>
    <p>I made this page myself.</p>
  </body>
</html>

In this course you'll learn what every line does, and then how to make pages like it look good on any screen.

Step 2 of 14Timeline

Milestones of the web you are about to build for

  1. 1990
    HTML and the first browser at CERN

    Tim Berners-Lee writes the first web server, browser and pages.

  2. 1991
    The web opens to the public
  3. 1995
    JavaScript appears

    Created in about ten days for the Netscape browser.

  4. 1996
    CSS level 1 published

    Styling finally moves out of the HTML.

  5. 2014
    HTML5 becomes a W3C Recommendation

    Native video, audio, semantic elements and better forms.

  6. 2017
    CSS Grid ships in major browsers

    Two-dimensional page layout without hacks.

Step 3 of 14Learn

Three languages, three jobs

Modern web pages are built from three languages that work together, each with a clear job.

HTML (HyperText Markup Language) handles structure and meaning. It says "this is the main heading," "this is a paragraph," "this is a link to another page," "this is a form field for an email address." It's the skeleton and the content.

CSS (Cascading Style Sheets) handles presentation. It says "headings are dark blue and 2.5 times larger than normal text," "these three cards sit side by side on wide screens and stack on phones," "buttons have rounded corners."

JavaScript handles behavior. It responds to clicks, validates forms before sending, loads new content without reloading the page and powers interactive features like maps and games.

Think of a house: HTML is the walls and rooms, CSS is the paint, furniture and layout, and JavaScript is the electricity that makes things respond when you flip a switch.

Keeping these jobs separate is a core principle of web development. You could make text big and bold using only HTML elements, but if you choose elements for their meaning and leave appearance to CSS, you can restyle an entire site by editing one CSS file, and screen readers and search engines understand your content correctly. This course covers HTML and CSS; JavaScript is the natural next step.

Step 4 of 14Note

Step 5 of 14Practice · Sort into groups

Which language would you use for each job?

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

Step 6 of 14Diagram

Three layers of every web page

Like a house: HTML is the frame, CSS the paint and furniture, JavaScript the wiring and switches.

Three layers of every web pageLayer diagram: JavaScript: behavior, CSS: presentation, HTML: structure and meaning.JavaScript: behaviorCSS: presentationHTML: structure and meaning

Tap a shape with to see more.

JavaScript: behavior

Responds to clicks, fetches data, updates the page without reloading.

CSS: presentation

Colors, fonts, spacing and layout.

HTML: structure and meaning

Headings, paragraphs, links, images, forms. The page still works if CSS and JavaScript fail.

Step 7 of 14Learn

From address bar to screen

What happens when you type www.example.com/about.html and press Enter?

  1. Finding the server. Your browser looks up the domain name (example.com) to get the numeric address of the web server, a computer that stores the site's files and is always connected to the internet.
  2. The request. The browser sends a request: "Please send me /about.html."
  3. The response. The server sends back the HTML file.
  4. Parsing. The browser reads the HTML from top to bottom and builds an internal model of the page, a tree of elements called the DOM (Document Object Model).
  5. More requests. While reading, it finds references to other files: a CSS file, images, fonts, scripts. It requests each one.
  6. Rendering. It applies the CSS to the DOM, calculates where every box goes, and paints the result on screen.

The parts of a URL matter when you write links:

  • https:// is the protocol (the secure version of HTTP).
  • www.example.com is the domain.
  • /about.html is the path to a file on that server.

When the path ends in a folder, like example.com/blog/, servers usually send that folder's index.html file. That's why the home page of almost every site is a file named index.html.

Step 8 of 14Practice · Put in order

Put the steps of loading a web page in order.

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

  1. The browser looks up the server's address from the domain name
  2. The browser reads the HTML and requests linked CSS and images
  3. The browser applies CSS and paints the page
  4. The browser requests the HTML file
  5. The server sends back the HTML

Step 9 of 14Diagram

What happens after you press Enter

What happens after you press EnterProcess diagram: DNS lookup → HTTP request → Server sends HTML → Browser fetches CSS, images, scripts → Page is drawn.DNS lookupHTTP requestServer sends HTMLBrowser fetchesCSS, images, scriptsPage is drawn

Tap a shape with to see more.

DNS lookup

The domain name is turned into the server's IP address.

HTTP request

The browser asks that server for the page, over an encrypted HTTPS connection.

Server sends HTML

For a folder address, usually its index.html file.

Browser fetches CSS, images, scripts

Every file referenced in the HTML is a separate request.

Page is drawn

The browser builds the element tree, applies styles and paints pixels.

Step 10 of 14Note

Step 11 of 14Practice · Choose one

A visitor goes to https://bakery.example/menu/. Which file will the server usually send?

Step 12 of 14Tap to reveal

Your first page in four steps

  1. 1. Create a folder

    Make a folder called my-site anywhere on your computer. Everything for this site will live inside it.

  2. 2. Write the file

    Open a plain text editor (not a word processor, which adds hidden formatting), paste the example page from the start of this lesson and save it as index.html inside the folder.

  3. 3. Open it

    Double-click index.html. It opens in your default browser, and the address bar shows a file path instead of a web address, because the file is on your own computer.

  4. 4. Edit and refresh

    Change the heading text, save, and press refresh in the browser. This edit-save-refresh loop is how you will work through the rest of the course.

Step 13 of 14Practice · True or false

To build a basic web page, you need to buy special software.

Step 14 of 14Practice · Match the pairs

Match each part of the URL https://shop.example.com/products/shoes.html to its name.

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

  1. https://
  2. shop.example.com
  3. /products/shoes.html
  4. shoes.html