How Websites Work
When you type an address and press Enter, your browser has a short conversation with computers that may be on another continent, and the page appears a moment later. Understanding that conversation makes you a better web developer, because you will know where your HTML lives and how it reaches people.
Clients and servers
The web is built on a simple idea: some computers ask for things and others answer.
- A client is the program that asks. For websites this is your browser: Chrome, Firefox, Safari, Edge or Opera on a phone or laptop.
- A server is a computer that is always switched on and connected to the internet. It stores a website's files (HTML, CSS, images) and sends them to any client that asks.
The internet is the global network of cables, mobile masts and routers that connects them. The web is one service that runs on top of it, alongside others like email.
What happens when you open a page
Imagine you type www.example.com into your phone's browser. Four main steps follow:
- DNS lookup. Computers find each other using numeric IP addresses, not names. The browser asks a DNS (Domain Name System) server which IP address belongs to
www.example.com. DNS works like your phone's contact list: you look up a name and get a number. - The answer. The DNS server replies with an address such as
203.0.113.10. Browsers and your device remember (cache) the answer for a while, so later visits skip this step. - The request. The browser connects to that server and sends an HTTP request, essentially a message saying "please GET me the page at
/". - The response. The server sends back an HTTP response: a status code such as
200 OKfollowed by the HTML file.
The browser then reads the HTML from top to bottom. Every time it finds a reference to another file, such as a stylesheet, an image or a script, it sends another request for that file. A typical page needs dozens of requests. Finally the browser renders (draws) the page on your screen.
203.0.113.10 comes from a range reserved for documentation, so it does not belong to a real website. Real IP addresses look similar: IPv4 uses four numbers from 0 to 255, while newer IPv6 addresses are longer and use hexadecimal, such as 2001:db8::1.
The parts of a URL
The address you type is a URL (Uniform Resource Locator). Each part has a job:
- Protocol:
httpsis HTTP made secure with encryption, so nobody on the same Wi-Fi can read or change what you send. Always look for it before typing passwords or M-Pesa details. - Domain name: the human-friendly name that DNS turns into an IP address. Endings such as
.com,.co.keor.ugare top-level domains. - Path: which file or page on that server you want.
- Query string: extra
name=valuedata after a?, often from search boxes and forms. - Fragment: the part after
#is never sent to the server. The browser uses it to scroll to the element with thatid.
HTTP status codes
Every response starts with a three-digit status code. You will meet these often:
| Code | Meaning | When you see it |
|---|---|---|
200 OK | Success | The page loaded normally |
301 Moved Permanently | Redirect | The page has a new address; the browser follows it automatically |
404 Not Found | Client error | The path does not exist, often a typo or a deleted page |
500 Internal Server Error | Server error | Something broke in the server's own code |
Codes in the 200s mean success, 300s mean redirection, 400s mean the request had a problem and 500s mean the server had a problem.
Static and dynamic sites
A static site sends the same ready-made HTML files to everyone, like a printed menu. A dynamic site builds the HTML on the server for each request, for example showing your name and balance after you log in. Frameworks such as Django build HTML this way. Either way, what arrives in the browser is HTML, which is why learning it well pays off.
Open your browser's developer tools (F12), choose the Network tab and reload any page. You will see every request the browser makes, with its status code, size and time.
Key points
- Browsers are clients that request files; servers store websites and send responses.
- DNS turns domain names into IP addresses before any page is requested.
- A URL has a protocol, domain, path, and optional query string and fragment.
- Status codes report the result: 200 success, 301 redirect, 404 not found, 500 server error.
Tip: use the ← and → keys to move between pages.
