What WebNN can actually do in a browser today
WebNN is the only web API that can reach an NPU, and outside Chromium it has not landed yet. It takes existing ONNX weights with no conversion.
Running neural networks in a browser used to mean one of two things: compile a C++ engine to WebAssembly and grind on the CPU, or write WebGPU compute shaders for the GPU. Most laptops bought in the last couple of years also have an NPU. The OS and native apps use it constantly, and the browser had no way to reach it. WebNN is the W3C API for exactly that: hand the whole model graph to the operating system ML stack, and let it schedule onto NPU, GPU or CPU.
An inference-only API
The W3C Machine Learning working group built this for inference only. There is no backpropagation or gradient descent; training stays in PyTorch and the browser runs forward passes. The spec reached an updated Candidate Recommendation in January 2026, with the operator set and graph model stable enough that vendors were formally invited to implement and test. It is still the only web API that exposes the NPU.
Usage looks like the inference engines you already know. MLGraphBuilder describes the graph, with inputs, constant weights, convolutions and activations; the browser compiles the whole graph at build time, where operator fusion and memory layout get decided, and then you execute repeatedly with different inputs. NPU drivers want that whole-graph view. An imperative, op-by-op API cannot target this hardware well.
The tasks it covers today, roughly:
- Image classification, object detection, segmentation, super-resolution, face and pose landmarks
- Speech recognition, VAD, denoising and audio classification, which covers most audio tasks in this catalogue
- Text classification, embeddings and small language models; the spec authors mention hardware-accelerating 7 to 13B parameter models
- Not generative LLM inference with custom shaders. The WebNN spec has no shader authoring, so that stays with WebGPU
Three routes to three different chips
These three point at different hardware layers. WebGPU gives shader-level control, the highest throughput and the highest power draw. WebNN only does inference and hands the graph to the OS ML stack, which is how it gets the NPU efficiency. WebAssembly is a compilation target every browser supports; onnxruntime-web and transformers.js run on it at near-native CPU speed. As of 2026 WebNN still has no footing outside Chromium, so WASM remains the compatibility floor.
| Aspect | WebNN | WebGPU | WebAssembly |
|---|---|---|---|
| Role | Dedicated neural inference API | General-purpose GPU compute API | Universal CPU execution format |
| Target hardware | NPU / GPU / CPU (OS ML stack schedules) | GPU | CPU (SIMD vectorised) |
| Abstraction | Whole-graph compilation, declarative ops | Shader level, hand-written kernels | Compilation target, kernels ship with the engine |
| Browser support | Chrome/Edge (flag or Origin Trial); Firefox/Safari not yet | Default in Chrome/Edge/Firefox, Safari following | Every browser |
| Power | INT8 inference on NPU is far more efficient than GPU | Highest parallel throughput, highest power draw | No acceleration, pure CPU |
| Best at | Low-power always-on inference | Large generative models, custom operators | Maximum-compatibility fallback |
In practice, probe NPU, then GPU, then CPU, and use whichever answers:
async function pickBackend() {
if ('ml' in navigator) {
for (const deviceType of ['npu', 'gpu']) {
try {
await navigator.ml.createContext({ deviceType });
return `webnn:${deviceType}`;
} catch {
// that device class is unavailable (no NPU / driver), keep falling back
}
}
}
if ('gpu' in navigator) return 'webgpu';
return 'wasm';
}Turning it on today
As of late 2026, Chrome and Edge enable WebNN through the #web-machine-learning-neural-network entry in chrome://flags, currently slated through Milestone 150. Both have also run several rounds of Origin Trials, so with a registered token you can turn it on for real users on a production origin. Firefox and Safari have not implemented it, so fall back when navigator.ml is missing. On the backend side Windows has moved from DirectML to Windows ML, which can load OpenVINO and other providers; macOS maps to Core ML, Android to the platform NN stack. WebNN describes the graph, the platform picks the accelerator.
Three steps: create a context, assemble the graph with the builder, compile once and execute repeatedly.
const context = await navigator.ml.createContext({ deviceType: 'npu' });
const builder = new MLGraphBuilder(context);
const input = builder.input('input', {
dataType: 'float32',
shape: [1, 3, 224, 224],
});
const weights = builder.constant(
{ dataType: 'float32', shape: [32, 3, 3, 3] },
new Float32Array(weightData),
);
const graph = await builder.build({
output: builder.relu(builder.conv2d(input, weights, { padding: [1, 1, 1, 1] })),
});
// then, on every inference:
const { outputs } = await context.compute(graph, { input }, { output });Hand-writing a graph is fine for a demo and miserable for a real model with hundreds of operators. The practical entry point is a runtime: ONNX Runtime Web exposes WebNN as an execution provider, so switching backends is just a change to a config array.
const session = await ort.InferenceSession.create('./model.onnx', {
executionProviders: [
{ name: 'webnn', deviceType: 'npu', powerPreference: 'default' },
'webgpu',
'wasm',
],
});
// ORT partitions the graph: subgraphs WebNN can run go to it, the rest fall backHow it relates to ONNX
ONNX defines what a model looks like: the .onnx file, the operator set, the serialisation. WebNN defines where it runs: graph construction and execution inside the browser, with no model format of its own. They fit together for two reasons. WebNN operators were designed from the start to cover ONNX operators, so convolutions, matmuls and activations have direct counterparts. And the common engineering path is ONNX Runtime Web: load the .onnx, partition the graph, send accelerator-friendly subgraphs to the WebNN provider and fall back to WebGPU or WASM for the rest. If your weights are already ONNX, there is no format conversion to do. Just add one entry to the execution-provider list.
Workloads that actually benefit
- Always-on tasks that run for a whole meeting or a whole shift: live captions, VAD, wake-word spotting. On an NPU they barely touch the GPU or the battery; community tests on Snapdragon X report Whisper at up to 30x realtime with the GPU asleep
- Documents, audio and images that cannot leave the device
- Offline and poor networks, where a PWA should be doing inference locally anyway
- Small and mid-sized models with many users: classification, embeddings and detection at a few milliseconds per call
Two cases are out for now. Multi-billion-parameter generative LLMs, where WebLLM and MLC are firmly on WebGPU and operator coverage is more mature. And Safari or Firefox users, who still need the WebGPU/WASM fallback, which is why pickBackend degrades in that order.
Every demo on this site already downloads ONNX weights and runs them through onnxruntime-web, so the WASM and WebGPU substrate is in place. Once WebNN ships broadly, the same weights need no conversion: add webnn to the execution-provider list and inference moves onto the NPU.