The frame budget: at 60 frames a second, everything needed for the next picture must finish in 16.7 ms.
This is the layer where everything in the course finally meets a person, and people are strict about time. A screen refreshes sixty times a second. That gives the software sixteen point seven milliseconds to prepare each new picture. A piece of work that takes ten milliseconds fits. The next picture is ready on time and nobody notices anything. A piece of work that takes two hundred milliseconds covers twelve refreshes. For all of them the page cannot scroll, cannot answer a click, cannot move. And at about a hundred milliseconds, a person starts to call it slow. Interface engineering is the work of staying inside this envelope, on a phone and a network you did not choose.
Frame budget · Going deeper
The interface stack
From the user’s input down: framework, browser runtime (HTML parser, CSS engine, JavaScript engine sharing one DOM and one main thread), operating system, GPU, display. Every layer is replaceable and none is optional; a slow choice anywhere shows up as a missed frame at the top.
The main thread
One thread runs the script and draws the page
The event loop: run one task, drain the promises, render, repeat. All on the main thread.
Why would a page freeze at all? Because of how the browser schedules work. Everything that happens, a click, a timer, a reply from the network, joins a queue of tasks. The main thread takes one task and runs it to completion. Nothing interrupts it. Then it runs every waiting microtask, which is what a resolved promise becomes. Only then does it get the chance to render: recompute styles, lay out, paint. And then it loops for the next task. So if one task runs for two hundred milliseconds, the render step waits two hundred milliseconds. There is one thread, and your script shares it with the drawing of the page.
The main thread · Going deeper · 1 of 2
Tasks, microtasks and the render step
requestAnimationFrame runs a callback just before the next paint, the right moment for visual updates. requestIdleCallback runs when the thread is idle. scheduler.yield() lets a long task give way to input. The DOM is a C++ tree behind a binding layer, so each DOM write is a cross-boundary call the engine cannot optimise like plain arithmetic.
The main thread · Going deeper · 2 of 2
The JavaScript engine is a compiler
V8, JavaScriptCore and SpiderMonkey interpret cold code as bytecode and recompile hot functions to machine code using the types they observed. If an object’s shape then changes, the function deoptimises: from about 10 ns a call back to 200 ns. A generational garbage collector frees short-lived objects cheaply; old-generation collections can pause for 30 ms or more.
Rendering pipeline
Which property you change decides how much is redone
The render pipeline: parse, style, layout, paint, composite, raster. A change reruns from its stage onward.
Now the render step itself. To turn a document into pixels the browser walks six stages: parse the HTML, work out each element’s style, lay out every box, paint, composite the layers, and rasterise on the graphics chip. The numbers are from a real article page on a recent laptop: about eighteen milliseconds in all. Here is the part that matters every day. Change an element’s width, and layout runs again, then paint, then composite. Do that in an animation and it happens on every frame. Change only a colour, and layout is skipped. Change transform or opacity, and only the compositor runs, on its own thread. That animation stays smooth even while your script is busy. Same visual effect, very different cost.
Rendering pipeline · Going deeper
Layout thrashing
The browser defers layout to the next frame. Reading a geometry property such as offsetTop or getBoundingClientRect after a style write forces it to lay out immediately. Interleave reads and writes in a loop and each iteration pays a full layout. The fix: batch all reads, then all writes.
Check yourself
A card slides 300 px across the screen. Version A animates left; version B animates transform. The phone is busy running script. Which stays smooth?
Changing left reruns layout and paint on the main thread every frame. Transform is applied by the compositor alone, so it keeps moving while script runs.
CSS cascade
CSS picks one winning rule per property, by a fixed ladder
The cascade resolves competing rules by origin, layer, specificity, then source order.
Style is the stage most people underestimate. Here is one button. It has an identifier and two classes, and four different rules in the stylesheet each try to set its background. Which one applies? The browser scores each rule’s selector with three counts: identifiers, classes, element types. And compares them left to right. One identifier outranks any number of classes, so this rule wins, and the button is green. Specificity is only one rung of a ladder. Above it: where the rule came from and whether it is marked important, and which layer it sits in. Below it: if everything else ties, the rule written later wins. Every case of a style being ignored is explained by one of these rungs.
CSS cascade · Going deeper
Two layout engines: Flexbox and Grid
Flexbox lays children along one axis: toolbars, button rows. Grid places them in two dimensions: page shells, dashboards. Most pages use Grid for the shell and Flexbox inside cells. Container queries let a component respond to its parent’s size, and contain tells the browser a subtree cannot affect the rest of the page, so work can be skipped.
UI state
Where state lives decides how much of the screen re-renders
In a component tree, data flows down and events flow up. A state change re-renders its subscribers.
Past a few hundred elements, nobody edits the page by hand. The interface is split into components, each owning a little state and describing what it looks like. Here is a tree of ten components. Suppose all the state lives in one store at the top and every component listens to it. The user types one letter. All ten re-render. The rule inside any such tree: data flows down from parent to child, and events flow back up. Now the same tree, where only the one component that actually shows the value subscribes to it. One letter, one re-render. With ten components the difference is invisible. With twenty thousand, it is the difference between a smooth dashboard and one that stutters on every keystroke.
UI state · Going deeper · 1 of 2
Three ways to know what to update
Virtual DOM (React) re-runs the component and diffs the new tree against the old: simple to reason about, costs CPU per update. Signals (Solid, Vue 3, Svelte 5) track which DOM nodes read which value and update only those: no diff. Compiled reactivity (Svelte) emits the DOM writes at build time.
UI state · Going deeper · 2 of 2
Three scopes of state
Local state lives and dies with one component. Lifted state moves to a common ancestor so siblings can share it, and re-renders that subtree. Global state survives the tree and needs explicit subscriptions. Choosing the wrong scope is the usual cause of “the whole app re-renders on every keystroke”.
Rendering strategies
Where the HTML is made sets how long the user waits
CSR, SSR, SSG and islands are points on one trade-off. Hydration is the gap between looking ready and being ready.
A page’s HTML can be produced in the browser, on a server, or ahead of time. The choice sets what the user sees in the first seconds. Client rendering sends an empty shell and a script. On a content site the page can still be blank at three seconds while the script downloads, runs and fetches data. Server rendering sends real HTML, so content appears early. But for four to eight hundred milliseconds on a mid-range phone the page looks ready and is not: the script is still attaching itself. That is hydration, and it is what users describe as the site freezing for a second. Static generation does the rendering once at build time and serves from a content network: first byte in ten to thirty milliseconds. Islands keep the page static and hydrate only the small interactive parts: five to twenty kilobytes of script instead of two hundred.
Rendering strategies · Going deeper · 1 of 2
The strategies on one chart
Streaming SSR flushes the shell first and streams content as data resolves, so the user sees pixels at 100 ms even if the slowest query takes 800. Incremental static regeneration serves cached pages and rebuilds stale ones. Edge rendering moves the server to CDN locations: about 50 ms to first byte worldwide, in a constrained runtime.
Rendering strategies · Going deeper · 2 of 2
Hydration, partial hydration, resumability
Partial hydration (Astro) hydrates only marked components. Resumability (Qwik) serialises framework state into the HTML so the client never re-runs setup. React Server Components run only on the server and ship no script for themselves.
The browser platform
The browser has become a small operating system
The web platform exposes networking, storage, threads, media, graphics and compiled code through standard APIs.
The browser began as a document viewer. Look at what it offers a program today. Networking beyond simple requests: streams, two-way sockets. Storage from a five megabyte key-value store up to a real database holding gigabytes. Threads that run off the main thread. Camera, microphone and peer to peer calls. A modern graphics interface. And WebAssembly, which runs code compiled from other languages at close to native speed. One of these changes what a web page is. A Service Worker is installed once and then sits between the page and the network, seeing every request. It can answer from a cache when there is no connection. That one mechanism is what makes a site work offline, install to the home screen, and receive push messages.
The browser platform · Going deeper
Capabilities by domain
Web Workers run script on another OS thread with no DOM access, communicating by postMessage. WebAssembly pays off for CPU-bound work, as in Figma’s vector engine or in-browser SQLite, but calls across the JS boundary are not free. WebGPU exposes the explicit model of Vulkan and Metal and is used for in-browser ML inference.
Core Web Vitals
Perceived speed is three numbers you can measure
Core Web Vitals: LCP under 2.5 s, INP under 200 ms, CLS under 0.1, at the 75th percentile of real users.
Fast is not a feeling. It is three measurements. Largest Contentful Paint: when does the main content become visible? Good is within two and a half seconds. Beyond four is poor. Interaction to Next Paint: across the whole visit, how long did the slowest tap take to show a response? Good is within two hundred milliseconds. Cumulative Layout Shift: how much does the page jump around while loading? This is the one behind tapping the wrong thing because an advert pushed the button down. Good is under zero point one. All three are judged at the seventy-fifth percentile of real visits, which means the score is set by ordinary phones on ordinary networks, not by the machine on your desk.
Core Web Vitals · Going deeper
The thresholds and how they are measured
INP replaced First Input Delay in 2024. For CLS, give every image and embed explicit width and height, reserve slots for ads, and match fallback font metrics so the font swap is invisible. Field data comes from real users through the web-vitals library or the Chrome UX Report; lab tools only approximate it.
Page load
Most of a page load is spent before your code runs
A worked performance budget: network and image dominate; on slow phones, script does.
Let us spend the two and a half second budget on a real page: a landing page on a mid-range phone over a mobile connection. Finding the server: thirty milliseconds. Opening a secure connection: two hundred. The server thinking: two hundred. The HTML arriving: fifty. The main image: one hundred and thirty, then thirty to decode. Notice that four hundred and thirty milliseconds pass on the network before the first byte of HTML exists. The main content is painted at six hundred and forty milliseconds, comfortably inside the budget. No framework appeared in that list. Now the other half of the story. On a five-year-old phone, the same page with five hundred kilobytes of script takes nine seconds instead of two, because script must be parsed and run on that slow processor. Performance work is mostly shipping less code, later.
Page load · Going deeper · 1 of 2
The worked budget, step by step
Levers in order of effect: AVIF or WebP for the main image, preload with fetchpriority="high" (50 to 100 ms), inline critical CSS, route-level code splitting, lazy loading below the fold, font subsetting (a Latin subset can drop 400 KB to 30 KB), and 103 Early Hints.
Page load · Going deeper · 2 of 2
INP and the long task
A long task is anything over 50 ms on the main thread. A 250 KB compressed bundle parses in roughly 100 ms on a mid-range phone. INP records the worst interaction of the session, so one pathological tap on an old phone defines the score. Break work up with scheduler.yield() and move hashing or large JSON parsing to a Worker.
Check yourself
The main thread is 50 ms into a 300 ms task when the user taps a button. Roughly when can the screen first show a response?
The tap waits in the queue until the running task finishes; only then does its handler run and a frame paint. That is already over the 200 ms target for INP.
Accessibility and native elements
A native element is a contract. A div is a rectangle
Semantic HTML gives keyboard, focus and screen-reader behaviour for free. ARIA only patches the gaps.
About one person in six lives with a disability. Many use a keyboard only, or a screen reader, or voice. One interface has to serve all of them, and most of that work is a single habit. Compare a real button element with a div that has a click handler. They can look identical. The button can be reached with the Tab key. Enter and Space activate it. A screen reader announces it as a button. It can submit a form. The div does none of these. Here is why. From your HTML, the browser builds a second tree, the accessibility tree, holding each element’s role and name. That tree is what a screen reader reads aloud. A label tied to an input becomes: Email, edit text. A div becomes nothing at all. So the first rule is: if a native element exists, use it.
Accessibility and native elements · Going deeper · 1 of 2
The accessibility layer
ARIA supplies role, name and state when HTML cannot: role="tab", aria-expanded, aria-live. “No ARIA is better than bad ARIA”: a stale state misleads. For errors: aria-invalid on the input, aria-describedby pointing at the message, a live region for the summary, and focus moved to the first invalid field. Body text needs 4.5:1 contrast; #999 on white is about 2.8:1.
Accessibility and native elements · Going deeper · 2 of 2
Focus order on a real form
Tab should follow reading order. Positive tabindex values break it and are almost always wrong. A placeholder is not a label: it vanishes on the first keystroke. Dialogs trap focus and close on Esc; a skip link lets keyboard users pass the navigation; the focus ring must stay visible.
Check yourself
In this form, “Sign up” is a styled <div> with a click handler. A keyboard user fills both fields and presses Tab. What happens?
A div is not focusable and has no keyboard activation. The user reaches the end of the form with no way to submit it. A <button> fixes all of it.
Mobile and cross-platform
Three routes reach a phone; one source keeps them consistent
Native, cross-platform and installed web apps trade cost for device access. Design tokens keep them aligned.
The web is not the only surface. The phone is the main computer for most people, and there are three ways onto it. Native: write the app in each platform’s own language and toolkit. You get every feature of the operating system the day it ships, and the best speed and battery life. You also get two codebases and two teams. Cross-platform toolkits: one codebase, one team, both phones. The price is that new operating system features reach you months late. An installed web app: your website plus a Service Worker. No app store, updates the moment you deploy, and limited access to the device. Whichever routes you take, keep the design decisions in one place. Colour, spacing and type live in a single source of tokens that feeds every surface. A rebrand becomes one change, not a six month migration.
Mobile and cross-platform · Going deeper · 1 of 2
Mobile delivery paths
React Native runs JavaScript and drives native views; its new architecture shrinks the bridge cost. Flutter draws every pixel itself with its own engine: consistent visuals, less platform feel. iOS constrains installed web apps more than Android does.
Mobile and cross-platform · Going deeper · 2 of 2
Design tokens
Tokens are named primitives such as --space-4 or --radius-md, kept in one file and exported to web, iOS and Android. Above them sit accessible components, then patterns such as sign-up or empty state. A type ramp of about seven sizes, line height 1.5 for body text and 45 to 75 characters a line carry most screens.
Target size
Bigger and closer is faster to hit, and it is measurable
Fitts’s law: pointing time grows with distance and shrinks with target size.
Design has constants too, and this one is seventy years old. A finger starts on the left and must hit a target four hundred units away that is twenty wide. The law gives that movement a difficulty of four point four bits. Make the target eighty wide at the same distance and the difficulty falls to two point six bits. It is hit faster and missed less, every time, by everyone. That is where the platform rules come from. Apple asks for touch targets of at least forty-four points, Google for forty-eight. They are drawn here at actual size, next to a twenty pixel icon, the kind that people miss. When a button is important, make it bigger and bring it closer to where the thumb already is.
Summary
An interface: a budget of milliseconds, a contract with every user
One thread, one pipeline, 16.7 ms a frame, for every kind of user. Next: engineering craft, how teams build all this.
The whole lesson in one picture. A person acts. The main thread takes the event, one task at a time. The pipeline turns the result into a frame, every sixteen point seven milliseconds. Where the HTML was produced decides how soon that first frame arrives. Three numbers tell you whether real people experienced it as fast. Native elements and keyboard access make it work for everyone. And shared tokens carry the same decisions to every surface. That completes the systems themselves. The next lesson turns to the people who build them: engineering craft.
Summary · Going deeper
The interface stack, top to bottom
The web platform is the most heavily specified surface in software: living standards from WHATWG, W3C Recommendations, and WCAG for accessibility. HTML and CSS are declarations the browser can optimise heavily; JavaScript is the escape hatch that costs main-thread time.
Lesson complete
You finished “Interfaces”
Answer the questions along the way to see your score here.