HTML5 interview questions and answers: media, canvas, workers and APIs

HTML5 interview questions are really about the browser platform that arrived with it: native audio and video, the canvas drawing surface, web workers for background work, safe cross-window messaging, the History API behind single-page apps, and device features such as geolocation that only run in secure contexts. Interviewers ask what each API is for, where it fails, and how you would combine them in a real feature. Lead with the API name, then the constraint that shapes how you use it.

By Published 9 min read

How HTML5 is asked in interviews

The word HTML5 shows up in job posts for frontend, web, hybrid mobile and game developer roles, and in campus interviews where it often means "what is new compared with older HTML". Element basics, accessibility, forms and loading attributes belong to HTML interview questions; expect them as warm-ups. The HTML5 part of the conversation is about APIs: a custom video player, a drawing tool, a heavy computation that freezes the page, a widget embedded from another origin, or a single-page app whose back button misbehaves.

  1. What changedShort questions on the standard itself, new elements and input types, and what was dropped.
  2. API knowledgeMedia, canvas, workers, messaging, history and device APIs, each with one limit you must know.
  3. Build or debugSketch a feature in plain JavaScript, or explain why a given snippet freezes, leaks or is blocked by the browser.

Fundamentals: what HTML5 changed

Opening questions for freshers and early screens
QuestionWhat it testsWhat a strong answer shows
Is HTML5 a finished version?The standardHTML is maintained by WHATWG as a living standard that changes continuously. HTML5 survives as a label for the generation of features that came with it, and job posts still use it.
What did HTML5 add that older HTML lacked?OverviewNative audio and video, canvas, new semantic and form features, a defined parsing algorithm, and many scripting APIs: workers, messaging, history, drag and drop and more.
Why does every browser now build the same DOM from broken markup?ParsingThe standard specifies error handling in the parser, so unclosed tags or misnested elements are repaired the same way everywhere, instead of each browser guessing.
Which input types arrived with HTML5?Formsemail, url, tel, number, range, date, time, datetime-local, month, week, color and search. Browsers show suitable keyboards and pickers, and fall back to a text box for a type they do not support.
Which old elements were dropped or made obsolete?HistoryPresentational ones such as font, center and big, plus frameset and frame. Their jobs moved to CSS or to iframe.
What does the contenteditable attribute do?EditingIt makes an element's content editable by the user. It powers rich-text editors, but the markup it produces varies, so production editors keep their own model of the document.
What does the hidden attribute do?DisplayIt marks content as not currently relevant, and browsers hide it by default. A CSS display rule on the same element can override it, which is a classic bug.
What is the draggable attribute?Drag and dropIt marks an element as a drag source for the native drag-and-drop API; links and images are draggable by default.
What is a secure context, and why does it matter here?Security modelA page served over HTTPS or from localhost. Geolocation, service workers, the clipboard API and many newer features only work in secure contexts.
What does the output element do?FormsIt shows the result of a calculation, such as a total from two range inputs, and it can name the inputs it depends on with the for attribute.
Opening questions for freshers and early screens. Scroll sideways on a small screen.

Audio and video questions

  • Why list several source elements inside a video? The browser picks the first source whose type and codec it can play, so you can offer more than one format. Text inside the element is shown only by browsers with no media support at all.
  • How do you add captions? A track element with kind="captions" or "subtitles", srclang and a label, pointing at a WebVTT file. If the file comes from another origin, the video needs a crossorigin attribute and the file a CORS header.
  • Why does autoplay sometimes fail? Browsers block autoplay with sound until the user interacts with the site. Muted autoplay is generally allowed, and the promise returned by play() rejects when playback is blocked, so handle it.
  • What does the preload attribute hint? none, metadata or auto. It is only a hint, and many mobile browsers load less than you ask for to save data.
  • Which media events matter for a custom player? loadedmetadata for duration and size, canplay and waiting for buffering state, timeupdate for the progress bar, ended, and error for failures.
  • How do streaming sites deliver adaptive video in a video element? Through Media Source Extensions: script fetches segments in the right quality and appends them to a source buffer, since a plain src points at a single file.

Canvas questions

Drawing, performance and security
QuestionWhat it testsWhat a strong answer shows
What is immediate mode, and why does it matter for canvas?ModelCanvas keeps pixels, not objects. To move a shape you clear and redraw, and hit testing, focus and screen-reader support are yours to build.
Why does my canvas look blurry on a laptop screen?High-density displaysThe backing store is in CSS pixels by default. Multiply the width and height attributes by devicePixelRatio, keep the CSS size, and scale the context to match.
Why use requestAnimationFrame instead of setInterval?AnimationIt runs before the next repaint, matches the display's refresh, and pauses in background tabs, so animations are smoother and cheaper.
What is a tainted canvas?Cross-origin imagesDrawing an image from another origin without CORS approval taints the canvas, after which getImageData and toDataURL throw. Fix it with crossorigin on the image and the right header from its server.
How do you keep canvas content accessible?AccessibilityPut meaningful fallback content inside the canvas element, label it, and offer the same data elsewhere in the page, such as a table beside a chart.
What is OffscreenCanvas?ThreadsA canvas that can be drawn from a worker, which keeps heavy rendering off the main thread where input is handled.
Drawing, performance and security. Scroll sideways on a small screen.

Workers, messaging and structured clone

  • What problem do web workers solve? Long computation on the main thread blocks input and painting. A dedicated worker runs the script on another thread and talks to the page through messages.
  • What can a worker not do? Touch the DOM or window. It has its own global scope with fetch, timers, IndexedDB and messaging, which is why rendering work must come back to the page or move to OffscreenCanvas.
  • Dedicated versus shared worker? A dedicated worker belongs to one page. A shared worker can be reached from several tabs of the same origin, useful for one connection or cache shared by all of them.
  • What does postMessage copy, and what can it transfer? It copies data with the structured clone algorithm. Transferable objects such as an ArrayBuffer can be moved instead, which is fast for large binary data but leaves the sender's copy unusable.
  • How do you use window.postMessage safely across origins? Name the exact target origin when sending, and in the receiver check event.origin against an allow list before trusting event.data. Never use the wildcard origin for anything sensitive.
  • What is BroadcastChannel for? Simple messages between tabs and workers of the same origin, such as telling every open tab that the user has signed out.
const original = {
  when: new Date("2026-01-15T09:30:00Z"),
  tags: new Set(["draft", "shared"]),
  sizes: new Map([["thumb", 120], ["full", 1920]]),
};
original.self = original; // cycles survive structured clone

const copy = structuredClone(original);
console.log(copy.when instanceof Date, copy.tags.has("shared"), copy.sizes.get("full")); // true true 1920
console.log(copy.self === copy, copy === original); // true false

try {
  structuredClone({ onSave() {} });
} catch (err) {
  console.log(err.name); // DataCloneError
}

// postMessage between two ports uses the same algorithm.
const { port1, port2 } = new MessageChannel();
port2.onmessage = ({ data }) => {
  console.log(data.sizes instanceof Map, data.when.getUTCHours()); // true 9
  port1.close();
};
port1.postMessage(original);
Structured clone and MessageChannel come from the HTML standard and also exist in Node, so this runs with `node file.js`. Comments show the output.

A good follow-up answer contrasts this with JSON: a JSON round trip turns the Date into a string, loses the Map and Set, and throws on the cycle, while structured clone keeps all three but refuses functions and DOM nodes.

History, device and real-time APIs

  • How does a single-page app change the URL without reloading? history.pushState adds an entry and replaceState swaps the current one. Neither fires popstate; that event fires on back and forward, where the router must render the matching view.
  • Why does a refreshed SPA route return 404? The browser asks the server for that path, which has no such file. The server must answer unknown app paths with the app's index page.
  • How does the Geolocation API ask for permission? The first call to getCurrentPosition or watchPosition triggers a browser prompt, and only in a secure context. Handle denial and timeouts in the error callback, and stop watching when you no longer need updates.
  • What are the main events in native drag and drop? dragstart sets data on dataTransfer, dragover must call preventDefault to allow a drop, and drop reads the data. Touch devices often need a different approach.
  • Server-sent events or WebSockets? EventSource receives a one-way text stream over ordinary HTTP and reconnects on its own, resuming with Last-Event-ID. A WebSocket is a two-way channel, better for chat or collaborative editing, but you write reconnection yourself.
  • What does the Page Visibility API offer? document.visibilityState and the visibilitychange event, so you can pause polling, video or animation when the tab is hidden.

Senior and scenario questions

  • A page freezes while parsing a large CSV the user drops in. What do you change? Read the file with the File API, hand the parsing to a worker, transfer the buffer instead of copying it, and stream progress messages back to update the UI.
  • An embedded payment widget talks to its parent page. How do you secure that channel? Fixed target origins on both sides, origin checks on every message, a small message schema, and no secrets in messages that a compromised page could read.
  • How would you make a web app keep working offline? A service worker caches the app shell and chosen data, with a strategy per request type, and IndexedDB stores user changes for later sync. The old application cache feature was removed from browsers, so it should not appear in a modern answer.
  • A video plays on desktop but not on some phones. Where do you start? Codec and container support on that device, the server's support for range requests, autoplay rules, and whether the playsinline attribute is needed on mobile Safari.
  • A chart drawn on canvas must be usable with a screen reader. What is your plan? Provide the data as a table or text summary, label the canvas, keep keyboard focus on real controls, and consider SVG if each point must be interactive.
  • How do you decide between canvas, SVG and DOM elements for a game board? DOM or SVG for tens of interactive pieces with accessibility needs; canvas, perhaps in a worker, for thousands of moving sprites.

Fictional example

Answering "Our image editor lags when users apply a filter"
Interviewer
Users load a photo onto a canvas and click a blur filter. The page freezes for two seconds. How would you fix it?
Candidate
The pixel loop is running on the main thread, so clicks and painting wait for it. I would read the pixels once with getImageData, send the underlying buffer to a worker as a transferable so it moves instead of being copied, run the filter there, and send the result back to putImageData. If the browsers we support allow it, OffscreenCanvas lets the worker draw directly. I would add a progress message every few rows so the UI can show something, and check that the source image is same-origin or served with CORS, because a tainted canvas would block getImageData entirely. Then I would measure the long task in the performance panel before and after.

HTML5 practice plan

  • Day 1: build a custom video player with play, seek, captions from a WebVTT file and a buffering indicator driven by media events.
  • Day 2: draw a small chart on canvas, make it sharp on a high-density screen, and add a text alternative.
  • Day 3: move an expensive loop into a worker, transfer an ArrayBuffer, and compare the main thread before and after in the performance panel.
  • Day 4: wire two windows with postMessage and write the origin checks first. Then add pushState routing to a tiny page and fix the refresh case.
  • Day 5: explain each API out loud in one minute: what it is for, the limit that bites, and one bug you have seen or caused.

For the requests underneath these APIs, read HTTP interview questions. For JavaScript itself, see JavaScript interview questions, and for building a mobile app on the same web stack, see Ionic interview questions.

API questions reward a calm order: purpose, constraint, then code. Natively, an AI interview assistant for Mac and Windows, can transcribe a practice frontend round on your machine, so you can check afterward whether you mentioned origin checks or devicePixelRatio before the interviewer had to prompt you. While you practice it can read a snippet or a console error from a screenshot and suggest what to explain, and with Pro or the free trial it can take your résumé and the job description into account. The session transcript and notes are kept for later review.

Questions people ask

What HTML5 questions are asked in interviews?

What HTML5 added, new input types, audio and video with captions and autoplay rules, canvas drawing and tainting, web workers, postMessage and structured clone, the History API, geolocation and server-sent events.

What is the difference between HTML and HTML5?

HTML5 is the name for the generation of HTML that added native media, canvas, a defined parsing algorithm and many scripting APIs. Today HTML is one living standard maintained by WHATWG, and HTML5 is mostly a label.

Can a web worker access the DOM?

No. A worker has its own global scope with fetch, timers and messaging, but no document or window. It sends results back to the page with postMessage, or draws through OffscreenCanvas.

How should freshers prepare for HTML5 interview questions?

Build one small feature with each major API: a video player with captions, a canvas chart, a worker that does heavy math, and pushState routing. Then explain each in a minute, including its main limit.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP