Skip to content

What Happens When You Type a URL in the Browser? (Interview Answer)

An interview-ready walkthrough from URL to pixels: DNS, TCP and TLS 1.3, HTTP, redirects, caching, DOM/CSSOM, render-blocking resources, layout, paint and JS.

Rajesh DhimanDecember 01, 2026~12 min
On this page

"What happens when you type a URL into the browser and press Enter?" is one of the oldest frontend interview questions. It's still asked because there's no single right depth. A good answer shows you know the whole path, from network to pixels, and can go deeper on whichever step the interviewer picks.

30‑second interview answer

The browser parses what I typed, decides whether it's a URL or a search, and upgrades to HTTPS if the site is on the HSTS list. It checks its caches, and if it needs the network it resolves the hostname to an IP address with DNS. It opens a connection: a TCP handshake plus a TLS 1.3 handshake, or a single QUIC handshake for HTTP/3. It sends an HTTP request and follows any redirects. Then it reads the response, using a cached copy where the caching headers allow. The browser parses the HTML into the DOM and the CSS into the CSSOM, fetching subresources as it finds them. CSS and synchronous scripts can block rendering. Then it computes styles and layout, paints, and composites layers to the screen. JavaScript runs along the way and can change any of it.

Key points

  • Most of the time before the first byte is network round trips: DNS, connection setup and the request itself.
  • Caches at every layer (HSTS, DNS, HTTP cache, service worker) can skip whole steps.
  • Rendering can't start until the browser has the HTML and the render-blocking CSS.
  • Layout, paint and composite are separate stages, and each costs a different amount when the page changes.

The address bar first decides what you typed. example.com/jobs looks like a host plus a path, so it's treated as a URL. react interview questions doesn't, so it goes to the default search engine.

For a URL, the browser parses it into parts:

https://www.example.com:443/jobs?team=web#open-roles
scheme  host            port path  query    fragment

If you leave out the scheme, the browser fills it in. Hostnames with non-ASCII characters are converted to their ASCII ("punycode") form before lookup. The fragment (#open-roles) is never sent to the server. The browser uses it after the page loads to scroll to an element.

2) HSTS and the scheme

If the site has sent a Strict-Transport-Security header before, or is on the browser's built-in HSTS preload list, the browser rewrites http:// to https:// before any request goes out. The plain-HTTP request never happens, so there's no window for a network attacker to intercept it.

Without HSTS, typing example.com may first make an HTTP request, and the server redirects it to HTTPS. That costs an extra round trip and leaves the first request unprotected.

3) Check the caches before the network

Before opening any connection, the browser checks whether it can avoid one:

  • Service worker: if one controls this origin, it receives the navigation request first and can answer from Cache Storage, which is how offline pages work. See service workers and offline caching.
  • HTTP cache: if a fresh cached response exists, the browser can use it without contacting the server. Most sites send HTML with no-cache or a short lifetime, so a navigation usually still goes to the network, at least to revalidate. More on this in step 7.

4) DNS resolution

The browser needs an IP address for www.example.com. It checks, roughly in order:

  1. Browser DNS cache, for names resolved recently.
  2. Operating system resolver, which has its own cache and the hosts file.
  3. Recursive resolver, usually run by your ISP, your company or a public provider such as 1.1.1.1 or 8.8.8.8. On a cache miss it asks a root server, which points it to the .com TLD servers, which point it to the domain's authoritative nameservers. Those return the actual records (A for IPv4, AAAA for IPv6, often after following a CNAME).

Every answer has a TTL, so later lookups in that window come from cache. The lookup itself may be encrypted with DNS over HTTPS. A site can also publish an HTTPS DNS record that tells the browser up front that the server supports HTTP/3.

DNS cost is per hostname. A page that loads fonts, scripts and images from five different domains may need five lookups. That's why <link rel="preconnect"> and dns-prefetch exist.

5) Connection: TCP, then TLS (or QUIC)

TCP sets up a reliable connection with a three-way handshake: SYN, SYN-ACK, ACK. That costs one round trip before the client can send data.

TLS then encrypts the connection. In the handshake, the client and server agree on a cipher and exchange keys, and the server sends its certificate. The browser checks the certificate: it must chain to a trusted root, be in date, and cover the hostname.

  • TLS 1.3 needs one round trip for a full handshake. The client sends its key share in the first message (ClientHello), so the server can reply with everything needed to start encrypting.
  • TLS 1.2 needed two round trips.
  • TLS 1.3 resumption can send data in the very first flight ("0-RTT early data") to a server it has talked to before. That data can be replayed by an attacker, so servers should only accept it for safe, idempotent requests.

So a new HTTPS connection over TCP with TLS 1.3 costs two round trips before the request is sent: one for TCP, one for TLS.

HTTP/3 runs over QUIC, which uses UDP. QUIC builds the TLS 1.3 handshake into its own, so transport and encryption are set up together in a single round trip. Browsers usually learn a server supports HTTP/3 from an Alt-Svc response header or an HTTPS DNS record. Until then they connect with HTTP/2 or HTTP/1.1 over TCP.

The browser keeps connections open and reuses them. With HTTP/2 and HTTP/3, many requests to the same origin share one connection.

6) HTTP request and response

Now the browser sends the request:

GET /jobs?team=web HTTP/1.1
Host: www.example.com
Accept: text/html,application/xhtml+xml
Accept-Encoding: gzip, br
Cookie: session=...

This is the HTTP/1.1 text form. HTTP/2 and HTTP/3 send the same fields in a binary format. The browser attaches any cookies for that site, subject to their Domain, Path, Secure and SameSite rules. Cookies and cross-origin rules are covered in CORS, cookies and SameSite.

The server (often a CDN edge first, then the origin) responds with a status line, headers and a body:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Encoding: br
Cache-Control: no-cache

The browser decompresses the body as it arrives and hands it to the HTML parser in chunks. It doesn't wait for the whole document. Time to First Byte (TTFB) is the time until that first chunk arrives.

7) Redirects

A 3xx response with a Location header sends the browser to another URL, and it repeats the steps above for the new one. Each hop can mean another DNS lookup and connection.

Status Meaning Method on the next request
301 Moved permanently May change POST to GET
308 Moved permanently Same method and body
302 Found (temporary) May change POST to GET
307 Temporary redirect Same method and body
303 See other Always GET

Permanent redirects can be cached by the browser. Chains such as http:// → https:// → www. → /en/ each add a round trip, so collapse them into one hop where you can.

8) Caching: fresh, revalidate or refetch

HTTP caching decides whether the browser needs the network at all for a resource:

  • Fresh (Cache-Control: max-age=31536000, immutable on a fingerprinted app.3f9a.js): served from cache with no request.
  • Stale or no-cache: the browser revalidates with If-None-Match (the ETag) or If-Modified-Since. If nothing changed, the server answers 304 Not Modified with no body.
  • no-store: never stored, always fetched again.

A common setup is short-lived or no-cache HTML with long-lived, content-hashed assets. CDNs add a shared cache between the browser and the origin. For the full set of headers, read HTTP caching for frontend and HTTP caching and CDNs.

9) Parsing HTML into the DOM, CSS into the CSSOM

The HTML parser turns bytes into characters, characters into tokens, and tokens into nodes in the DOM tree. It's built incrementally as data arrives.

When the parser finds a stylesheet, the browser fetches it and builds the CSSOM, a tree of the style rules (including the browser's default styles).

While the main parser works, a preload scanner reads ahead in the raw HTML and starts downloading the stylesheets, scripts, fonts and images it finds. That's why resources referenced directly in the HTML are discovered much earlier than ones injected by JavaScript.

10) Render-blocking and parser-blocking resources

Not everything the parser finds is equal:

  • CSS is render-blocking. The browser won't paint until it has the CSSOM for the stylesheets in the <head>. Otherwise you'd see unstyled content that then jumps. CSS doesn't stop the HTML parser, but it blocks scripts that come after it, because those scripts might read styles.
  • Classic <script> without async or defer is parser-blocking. The parser stops, the script is downloaded (if external) and executed, and only then does parsing continue. The script might call document.write or read the DOM so far.
  • defer downloads in parallel and runs after parsing finishes, in document order, before DOMContentLoaded. async downloads in parallel and runs as soon as it arrives, in any order. type="module" scripts are deferred by default.
<head>
  <link rel="stylesheet" href="/app.css" />          <!-- render-blocking -->
  <script src="/analytics.js" async></script>        <!-- runs whenever ready -->
  <script src="/app.js" defer></script>              <!-- runs after parsing -->
</head>

Images don't block rendering. Web fonts can delay text painting, depending on font-display.

11) Style, layout, paint, composite

Once the browser has DOM and CSSOM, it renders:

  1. Style: match CSS rules to elements and compute final values. Elements with display: none are left out of what gets rendered.
  2. Layout: compute the size and position of every box. Later recalculations are called reflow.
  3. Paint: record how to draw each box (text, colors, borders, images) and rasterize it into pixels, often on separate layers.
  4. Composite: combine the layers in the right order, usually on the GPU, and show the frame.

The first frame with content is First Contentful Paint. The largest visible element finishing is Largest Contentful Paint (LCP).

Later changes re-enter the pipeline at different points. Changing width re-runs layout, paint and composite. Changing color skips layout. Changing transform or opacity on a layer of its own can often be handled by the compositor alone. The details are in the browser rendering pipeline and layout, paint and composite for performance.

12) JavaScript execution and interactivity

JavaScript runs on the main thread, the same thread that does style, layout and paint. While a long script runs, the page can be painted but not respond to clicks or typing.

Key moments:

  • DOMContentLoaded: the HTML is fully parsed and deferred scripts have run.
  • load: all subresources, including images and iframes, have finished.
  • Hydration (in server-rendered React or Next.js apps): the client JavaScript attaches event handlers to the server-rendered HTML. Until it finishes, buttons may look ready but do nothing.

After that, every interaction runs the event loop: handle the event, run JavaScript, then update style, layout and paint as needed. How quickly that next frame appears is what Interaction to Next Paint (INP) measures.


Common follow-up questions

Q: Why is the first visit to a site slower than the second?

  • The first visit pays for DNS, a new TCP and TLS connection, and every resource download. On the second, DNS answers and HSTS are cached, TLS can resume, and fresh assets come from the HTTP cache or a service worker.

Q: What's the difference between TLS 1.2 and 1.3 here?

  • A full TLS 1.3 handshake takes one round trip instead of two, because the client sends its key share in the first message. 1.3 also dropped older, weaker ciphers, and it can resume with 0-RTT early data (with replay risk).

Q: How does HTTP/3 change the steps?

  • It replaces TCP with QUIC over UDP. The transport and TLS 1.3 handshakes are combined into one round trip. A lost packet only stalls the stream it belongs to, not every request on the connection, which happens with HTTP/2 over TCP.

Q: What makes a page render slowly even when the server is fast?

  • Render-blocking CSS, parser-blocking scripts in the <head>, late-discovered resources (an LCP image loaded by JavaScript), redirect chains, and long JavaScript tasks after the HTML arrives.

Q: Where does CORS fit in?

  • Not on a normal navigation. CORS applies when a page's scripts read cross-origin responses with fetch or XHR. The browser enforces it, based on headers the server sends.

Q: What do preconnect and preload do?

  • preconnect does the DNS, TCP and TLS work for another origin early. preload tells the browser to fetch a specific resource now because it'll be needed soon, which helps resources the preload scanner can't see.

Summary checklist

  • I can give the 30-second answer from URL to pixels without notes.
  • I can explain HSTS and why it skips the HTTP request.
  • I can describe the DNS lookup chain and where caching happens.
  • I can count the round trips for TCP + TLS 1.3, and for QUIC.
  • I know which redirects preserve the request method.
  • I can explain fresh vs revalidated vs no-store responses.
  • I can say why CSS is render-blocking and how async, defer and modules differ.
  • I can name the rendering stages and what re-runs each one.
  • I can explain why a painted page might not respond to input yet.

Summary

  • Network first: URL parsing, HSTS, caches, DNS, connection, request, redirects.
  • Then rendering: DOM and CSSOM, render-blocking resources, style, layout, paint, composite.
  • JavaScript shares the main thread with rendering, so heavy scripts delay interactivity.
  • In an interview, give the short version first, then go deep on whichever step they ask about.
Companion Book

Looking for structured, offline interview prep?

Free online lessons • Portable Amazon Kindle / Paperback

Frontend Interview Guide (2025 Edition) cover
Kindle edition

Frontend Interview Guide (2025 Edition)

By Rajesh Dhiman

Comprehensive preparation covering React internals, Web Performance, CSS architecture, and system design questions.

View on Amazon ↗Kindle & Paperback
Frontend Interview Guide (2025 Edition) cover
Paperback edition

Frontend Interview Guide (2025 Edition)

By Rajesh Dhiman

Comprehensive preparation covering React internals, Web Performance, CSS architecture, and system design questions.

View on Amazon.com ↗Not available on Amazon.in. Readers in India: choose Kindle.

Note: All lessons on Frontend Interview remain completely free to read online. As an Amazon Associate I earn from qualifying purchases.

RD

Written by Rajesh Dhiman

Authored by Rajesh Dhiman and engineered at Eunix Tech. Focused on deep-dive frontend engineering, JavaScript runtime internals, React architecture, and web performance.