v147 · origin trial · machine learning api
Web Neural Network API (WebNN)
A W3C API that lets web apps run neural network inference directly on a device's hardware — CPU, GPU, or dedicated NPU — through the browser. Frameworks like TensorFlow.js and ONNX Runtime Web use it under the hood; you can also use it directly to construct and execute computational graphs.
chrome://flags/#web-machine-learning-neural-network.
at a glance
| Origin trial | Chrome 147 – 149 (re-enabled; previous trial ran in Chrome 122-125) |
|---|---|
| Status | Origin trial |
| Standards | W3C Candidate Recommendation |
| Spec | Web Neural Network API — W3C CR |
| Explainer | webmachinelearning/webnn explainer |
| Samples | webmachinelearning/webnn-samples |
| ChromeStatus | 5738583487938560 — Web Neural Network API |
why it exists
Running ML models in the browser today requires either sending data to a server (latency, privacy) or using WebGL/WebGPU compute shaders (complex, not portable across frameworks). Native OS ML runtimes — DirectML on Windows, Core ML on macOS/iOS, NNAPI on Android — can run inference an order of magnitude faster than hand-written shader code, but the web has no standard way to reach them. WebNN is the bridge: it exposes a graph-based operator API that maps cleanly onto these native backends, letting frameworks compile an ONNX model once and run it optimally on whatever hardware the user has.
Source: W3C WebNN spec, webnn.io documentation, April 2026.Standards-status divergence, both sides reported rather than resolved (fetched 2026-10-06): this page calls the specification a W3C Candidate Recommendation, while the linked document at w3.org/TR/webnn/ self-describes as a W3C Candidate Recommendation Draft, one step short of the label used here. The page also carries no declaration grammar of its own: it enumerates the API shape through inline code in a table, so the reference contract’s syntax coverage points at that table and says so plainly rather than dressing the table up as WebIDL.
shape of the API
Core interfaces
| Interface | Description |
|---|---|
navigator.ml | Entry point. Available in Window, Worker, and ServiceWorker contexts. |
navigator.ml.createContext(options?) | Creates an MLContext. options.deviceType can be "cpu", "gpu", or "npu". |
MLContext | Represents the hardware backend. Has a compute() method to synchronously dispatch graph execution. |
MLGraphBuilder | Constructed with an MLContext. Provides methods for every operator (conv2d, relu, matmul, softmax, …). Returns MLOperand nodes forming a DAG. |
MLGraph | Compiled, immutable graph returned by MLGraphBuilder.build(). Execution is via MLContext.compute(graph, inputs, outputs). |
MLTensor | Hardware buffer for sharing data between graph executions and other APIs (WebGPU, WebGL) without round-tripping through JS. |
example
Running a simple 2-layer network
// 1. Pick the best available device
const context = await navigator.ml.createContext({ deviceType: 'gpu' });
const builder = new MLGraphBuilder(context);
// 2. Describe the graph symbolically (values are shapes, not data)
const input = builder.input('x', { dataType: 'float32', shape: [1, 784] });
const w1 = builder.constant({ dataType: 'float32', shape: [784, 128] }, weight1Data);
const b1 = builder.constant({ dataType: 'float32', shape: [128] }, bias1Data);
const fc1 = builder.add(builder.matmul(input, w1), b1);
const relu1 = builder.relu(fc1);
const w2 = builder.constant({ dataType: 'float32', shape: [128, 10] }, weight2Data);
const b2 = builder.constant({ dataType: 'float32', shape: [10] }, bias2Data);
const output = builder.add(builder.matmul(relu1, w2), b2);
// 3. Compile
const graph = await builder.build({ output });
// 4. Run
const inputTensor = new Float32Array(784);
const outputTensor = new Float32Array(10);
// ... fill inputTensor with pixel values ...
await context.compute(graph,
{ x: inputTensor },
{ output: outputTensor }
);
console.log('Class probabilities:', outputTensor);
Source: W3C WebNN explainer and webnn-samples GitHub, April 2026.
Tensor-backed execution using MLTensor hardware buffers (allocated with context.createTensor()):
// 1. Allocate reusable MLTensor hardware buffers
const inputTensor = await context.createTensor({
dataType: 'float32',
shape: [1, 784],
writable: true
});
const outputTensor = await context.createTensor({
dataType: 'float32',
shape: [1, 10],
readable: true
});
// 2. Write input data directly into the MLTensor buffer
context.writeTensor(inputTensor, pixelData);
// 3. Dispatch execution with MLTensor buffers
context.dispatch(graph, { x: inputTensor }, { output: outputTensor });
// 4. Read back inference results from the output MLTensor
const results = new Float32Array(await context.readTensor(outputTensor));
console.log('Class probabilities:', results);
Source: W3C WebNN §8.3.1.1 Executing an MLGraph using MLTensors, April 2026.
browser support
| Browser | Support |
|---|---|
| Chrome 147 – 149 | Origin trial (flag: #web-machine-learning-neural-network) |
| Edge | Supported (Chromium-based, same flag) |
| Firefox | No position |
| Safari | No position |
see also
- W3C WebNN Candidate Recommendation
- webnn.io — docs, quickstart, and samples
- webmachinelearning/webnn-samples — real-world examples
- chromestatus — Web Neural Network API (5738583487938560)
- No Chrome Platform Showcase demo exists for this ChromeStatus feature (5738583487938560). The WebNN showcase demo for a different ChromeStatus feature (5176273954144256) is related, not this page's live demo; the WebNN samples above remain available.