Web Platform Interview Questions: Browser APIs, HTML, CSS and JavaScript

Reviewed by Mark Dickie · Last updated

4 questions on this page you can answer and see marked on the spot. Go to the first one

The web platform is the set of browser-implemented standards, APIs and languages that HTML, CSS and JavaScript run on. Interviewers use it to test how a page is parsed and styled, and how scripts and network requests behave inside the browser. Expect questions on the event loop, the DOM, CORS, storage and accessibility, and expect to explain what the browser does at each step.

What does a web platform interview test?

Each row pairs an area with a typical question and the detail a strong answer includes.

AreaTypical questionDetail a strong answer includes
Event loopOrder of output from setTimeout, promises and queueMicrotaskMicrotasks drain after each task, while setTimeout callbacks run in a later task
DOM and eventsBubbling vs capture, and event delegationThe third argument of addEventListener, and why { passive: true } matters for scroll listeners
Layout and CSSFlexbox vs grid, specificity, stackingWhy z-index has no effect across a parent with its own stacking context
NetworkingCORS and cachingWhy a PUT with a custom header triggers a preflight OPTIONS request
SecuritySame-origin policy, cookies, CSPWhat SameSite=Lax blocks on cross-site POST requests
StoragelocalStorage, sessionStorage, IndexedDB, cookiesWhich of these JavaScript can read, and which the server receives
RenderingReflow, repaint, layout thrashingReading offsetHeight right after a style write forces a synchronous layout
AccessibilitySemantic HTML, ARIA, focus managementWhy a div with a click handler does not give keyboard users a button

How do I practise web platform questions by hand?

Work through these tasks in a browser console or a small local page before you take the quiz.

  1. Predict the output of a script that mixes setTimeout, a resolved Promise and queueMicrotask, then run it to check.
  2. Build a dialog with a focus trap, Escape to close, and focus returned to the trigger on close.
  3. Make a cross-origin fetch fail against a local server, then fix it by adding Access-Control-Allow-Origin to the response.
  4. Use the DevTools Performance panel to find a forced synchronous layout caused by reading a layout property inside a loop.
  5. Replace per-row click handlers on a 200-item list with one delegated listener on the parent.

Key facts

  • Tarmac has 158 Web Platform interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 748 job postings asking for Web Platform in November 2026.
  • Roles asking for Web Platform advertise a median base salary of US$187,116, across 152 job postings as of November 2026.
  • Tarmac last reviewed these Web Platform interview questions on 2 November 2026.

At a glance

Questions10 shown · 158 in the bank
Difficulty1–5 of 5
FormatsTrue / false, Multiple choice, Fill in the blank, Find the bug, Multiple answer, Short answer, Ordering, Code output, Flashcard, Coding exercise
Interactive1 run your code against tests, in the app

What you'll review

  1. core web vitals
  2. event bubbling
  3. web workers
  4. cors

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

Largest Contentful Paint (LCP) measures the time from when the user first navigates to a page to when the largest image or text block in the viewport is fully rendered. A 'Good' LCP score is 2.5 seconds or less.#

Options

Show answer

True. Largest Contentful Paint (LCP) measures how long it takes for the largest visible image or text block to render in the viewport from the start of page navigation. Google classifies an LCP of 2.5 seconds or less as 'Good', making this the target threshold for a positive user experience.

Why:

LCP does measure the render time of the largest content element visible in the viewport from the moment the user begins navigation. Google's thresholds classify LCP ≤ 2.5 s as 'Good', 2.5–4.0 s as 'Needs Improvement', and > 4.0 s as 'Poor'. Both parts of the statement are correct.

Which of the following metrics is not one of Google's three Core Web Vitals (as of 2024)?#

Options

Show answer

First Contentful Paint (FCP) is not a Core Web Vital. The three Core Web Vitals are Largest Contentful Paint (LCP), Interaction to Next Paint (INP), and Cumulative Layout Shift (CLS). FCP is a useful diagnostic metric in Lighthouse and PageSpeed Insights, but it does not count as an official Core Web Vital and does not directly influence Google Search ranking signals.

Why:

The three Core Web Vitals are LCP (loading), INP (interactivity — which replaced FID in March 2024), and CLS (visual stability). First Contentful Paint (FCP) is a diagnostic metric reported in Lighthouse and PageSpeed Insights, but it is NOT one of the three Core Web Vitals. LCP, INP, and CLS are the metrics that feed directly into Google Search ranking signals.

Complete the following Core Web Vitals thresholds:#

Show answer

Complete the following Core Web Vitals thresholds:

  • LCP should occur within 2.5 seconds for a "Good" score.
  • CLS should be less than 0.1 for a "Good" score.
  • INP should be less than 200 milliseconds for a "Good" score.
Why:

Google defines "Good" thresholds for the three Core Web Vitals as: LCP ≤ 2.5 s (measures when the largest above-the-fold content element becomes visible); CLS < 0.1 (a unitless score measuring unexpected layout shifts); and INP < 200 ms (measures end-to-end latency of user interactions). Values between the Good and Poor thresholds are rated "Needs Improvement".

Clicking the dim backdrop should close the modal, but clicking inside the modal content closes it too. The listener is on the backdrop element. Which line is wrong?#

backdrop.addEventListener('click', (e) => {
  closeModal();
});
// modalContent is a child of backdrop
Show answer

The bug is on line 2.

Why:

A click inside modalContent bubbles up to the backdrop, firing this listener. The handler closes unconditionally, so inner clicks close the modal too. Guard it with the originating element, e.g. if (e.target === e.currentTarget) closeModal();, so only clicks directly on the backdrop close it.

A product team is trying to improve their page's Interaction to Next Paint (INP) score. Which of the following interventions reduce INP by shortening one of its three sub-parts (input delay, processing time, or presentation delay) for the measured interaction? Select all that apply.#

Options

Pick every one that applies.

Show answer

Two interventions reduce INP by shortening one of its sub-parts: (1) breaking up long JavaScript tasks with scheduler.yield() or setTimeout so the main thread is free when the user interacts (shrinks input delay), and (2) minimizing DOM size and expensive style recalculations triggered by handlers so layout and paint complete faster (shrinks presentation delay). Image format changes, HTTP/2 stream limits, and blanket requestAnimationFrame wrapping do not.

Why:

INP measures the latency of discrete interactions from input until the next frame is painted, and is decomposed into input delay, processing time, and presentation delay. Yielding long tasks with scheduler.yield() or setTimeout keeps the main thread from being blocked when the user interacts, which reduces the input delay portion of INP for subsequent interactions — a well-established optimization in Google's INP guidance. Reducing DOM size and expensive style recalculations triggered by handlers shortens the layout/paint work the browser must do after the event callback, directly reducing presentation delay. Switching image formats to WebP reduces page weight and affects LCP/transfer cost, but does not change how quickly the main thread responds to an interaction. HTTP/2 concurrent-stream limits are a network-multiplexing concern unrelated to main-thread interaction latency. Unconditionally wrapping interaction-driven DOM updates in requestAnimationFrame defers the visual update to a later frame, which generally increases presentation delay for the measured interaction; Google's INP guidance specifically warns against using rAF as a blanket wrapper for interaction visual updates for this reason.

Explain what Cumulative Layout Shift (CLS) measures under the current Core Web Vitals definition, and describe two specific, distinct root causes that commonly produce a high CLS score on a production web page. For each cause, state the recommended fix.#

Show answer

CLS measures visual stability: how much visible content unexpectedly moves while the page is being viewed. Each unexpected layout shift has a score equal to the impact fraction (the fraction of the viewport affected) multiplied by the distance fraction (how far elements moved, relative to the viewport). Shifts are grouped into session windows, where consecutive shifts are less than 1 second apart and each window lasts at most 5 seconds; the reported CLS is the largest session window's total, not the sum of all shifts on the page. Shifts that occur within 500 ms of a user input such as a click or keypress are excluded. Two common causes: (1) Images or media without explicit width/height attributes. The browser does not reserve space for them, so when they load they push content down. Fix: set width and height attributes or use aspect-ratio in CSS so the space is reserved before the resource loads. (2) Dynamically injected content, such as ad banners, cookie consent bars, or lazy-loaded components, inserted above or within already-visible content, which shifts the content below it. Fix: reserve the space up front with a placeholder of the same dimensions (for example a min-height container), or insert the content in a location that does not push visible content, such as below existing content or outside the viewport.

Why:

Current CLS (the Core Web Vitals definition since 2021) reports the largest session window of unexpected layout shifts, where shifts are grouped with gaps under 1 second and windows capped at 5 seconds. It does not sum every shift on the page. Each shift's score is impact fraction times distance fraction, and shifts right after user input are excluded. The two causes are distinct: unsized images and media, which leave no reserved space, and dynamically injected content that pushes visible content down. The fixes reserve layout space before the resource or content appears, or place injected content where it does not displace visible elements, such as below existing content or outside the viewport.

A browser navigates to a page whose LCP element is an <img>. Consider the following five milestones, where each milestone is defined as the first moment the described condition becomes true. Arrange them in the order in which they must occur.#

Put these in order

Show answer

The correct order is: TTFB → image request dispatched → first image byte received → first paint of the image → LCP entry recorded. Each milestone is a strict data-dependency of the next: the browser needs HTML bytes to discover the <img>, needs to send the request before bytes come back, needs some image bytes to paint any pixels, and per the Web Vitals spec the largest-contentful-paint renderTime corresponds to that first paint.

Why:

Each milestone is a strict data-dependency prerequisite of the next, giving a single uncontested total order. (s1) TTFB precedes everything — no HTML bytes means no parsing and no discovered <img>. (s2) The request for the image can only be dispatched after enough HTML has arrived to expose the tag or its preload hint, so s2 follows s1. (s3) The first image byte cannot arrive before the request has been sent, so s3 follows s2. (s4) The first paint of the image requires at least some image bytes to have been received and decoded (even progressive/streaming codecs need some bytes on hand), so s4 follows s3. (s5) The Web Vitals spec ties the LCP renderTime to the moment the element was first painted, so the entry cannot be recorded before that paint occurred; s5 follows s4. Note this version deliberately uses first-occurrence milestones (first byte, first paint) rather than completion gates, which sidesteps progressive-decode and tiled-rendering concerns — decode may overlap download and paint may overlap decode, but the first occurrence of each still respects this ordering.

#child is inside #parent. The user clicks #child. What is logged, in order?#

const parent = document.getElementById('parent');
const child = document.getElementById('child');
parent.addEventListener('click', () => console.log('parent capture'), true);
parent.addEventListener('click', () => console.log('parent bubble'));
child.addEventListener('click', () => console.log('child'));
// user clicks #child
Show answer
parent capture
child
parent bubble
Why:

An event runs in three phases: capture (root → target), target, then bubble (target → root). The parent's capturing listener (third arg true) fires first on the way down, then the listener on the clicked target #child, then the parent's default (bubbling) listener on the way back up.

How does a dedicated Web Worker communicate with the page, and how is the data passed?#

Show answer

Both sides use postMessage(data) to send and listen for the message event to receive. By default the data is deep-copied via the structured clone algorithm (functions and DOM nodes can't be sent); large ArrayBuffers can instead be transferred (zero-copy, but unusable on the sender afterwards).

Why:

Workers share no memory with the main thread, so all communication is message-passing. Structured clone copies most data; the transferable-objects optimization hands ownership of a buffer to the other side without copying.

Implement needsPreflight(method, headers). It returns true when a cross-origin fetch() in mode: 'cors' with these author-set request headers would make the browser send a CORS preflight, and false otherwise. Follow the WHATWG Fetch rules for CORS-safelisted methods and request-headers:#

Starter code

function needsPreflight(method, headers) {
  // TODO: check method and each header against the CORS safelist
  return false;
}

Your solution must pass

  • plain GET
  • PUT method
  • JSON content-type

This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See web-platform salaries and hiring demand from live job postings.

The other 148 questions

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 148 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.