How a web page reaches you
Browsers and servers
Follow the simple request and response exchange between a browser and a web server before the browser renders an HTML page.
A browser is an HTTP client. You give it a URL, and it sends a request on your behalf.
A web server receives that request and decides what to send back. It might read a static HTML file from disk. It might generate HTML from a database. The browser does not need to know which approach the server used. It only needs a valid response.
A simplified request looks like this:
GET /about/ HTTP/1.1
Host: example.com
The server could answer with:
HTTP/1.1 200 OK
Content-Type: text/html
<h1>About us</h1>
The browser reads the Content-Type header and knows the body contains HTML. It parses the markup and builds the page you see on screen.
Keep this distinction in mind:
- the server sends HTML (or generates it)
- the browser interprets HTML and renders it
When you open a local file with a file:// URL, there is no server in the middle. The browser reads the file directly. When you visit a live site, a server sits between you and the file on disk.
Browsers also ship default styles. That is why a heading looks larger than a paragraph even before you write any CSS.
HTML is forgiving. Browsers try hard to display imperfect documents. That keeps old pages working, but it also means a page that looks fine can still contain structural mistakes. Later in this course we use validation tools and DevTools to catch those problems before they spread.
Lesson completed