← Chrome 160 reference · All APIs
v160 · graphics · enabled by default
Canvas2D tone mapping
Adds the toneMapping option to CanvasRenderingContext2DSettings (using the shared CanvasToneMapping dictionary and CanvasToneMappingMode enum: "standard" or "extended") and reflects it from getContextAttributes(). Authors can opt 2D and offscreen canvases into displaying high dynamic range (HDR) pixel values — such as floating-point srgb-linear or display-p3-linear buffers — or keep output constrained to standard dynamic range (SDR), matching WebGPU’s tone mapping model.
at a glance
| Shipped in | Chrome 160 (desktop, Android, Android WebView), enabled by default — listed under “Enabled by default” in the milestone=160 listing and confirmed in the ChromeStatus API record |
|---|---|
| Runtime flag | Blink runtime feature CanvasToneMapping (listed in runtime_enabled_features.json5; no origin trial, no standalone chrome://flags toggle; tested behind --enable-blink-features=CanvasToneMapping prior to Chrome 160 ship) |
| Specification | HTML Living Standard — CanvasToneMapping & CanvasToneMappingMode (merged via whatwg/html#11734); CSS Color HDR Module — dynamic-range-limit |
| Explainers | W3C ColorWeb-CG — Tone mapping for 2D Canvas · HDR on the web: the big picture |
| TAG review | w3ctag/design-reviews#1194 (Issues addressed) |
| Tracking bug | issues.chromium.org/448552449 |
| Web platform tests | element getContextAttributes.html, offscreen getContextAttributes.html, wide-gamut-canvas/encode-hdr.html |
| ChromeStatus | 5077164932333568 — Canvas2D tone mapping |
why it exists
By default, HTML <canvas> elements clamp their rendered output to the standard dynamic range (SDR) color volume of the target display, even when backed by a colorType: "float16" buffer with linear color spaces (srgb-linear or display-p3-linear) holding luminance values above 1.0. WebGPU previously defined GPUCanvasToneMapping to opt canvases into extended dynamic range, but 2D canvases lacked an equivalent mechanism. Moving CanvasToneMapping and CanvasToneMappingMode into the HTML Living Standard unifies HDR tone mapping across 2D Canvas, WebGL, and WebGPU while keeping "standard" as the backwards-compatible default.
Syntax
HTML defines one enum, one dictionary, and one new member on CanvasRenderingContext2DSettings (shared by both HTMLCanvasElement.getContext("2d", options) and OffscreenCanvas.getContext("2d", options), and returned by getContextAttributes()):
enum CanvasToneMappingMode {
"standard",
"extended"
};
dictionary CanvasToneMapping {
CanvasToneMappingMode mode = "standard";
};
partial dictionary CanvasRenderingContext2DSettings {
CanvasToneMapping toneMapping = {};
};
This reference covers the four parts of the Chrome 160 contract: CanvasToneMappingMode, CanvasToneMapping, CanvasRenderingContext2DSettings.toneMapping and getContextAttributes(), and output rendering, dynamic-range-limit, ImageBitmap, and HDR encoding.
CanvasToneMappingMode; CanvasToneMapping; Blink canvas_tone_mapping.idl; Blink canvas_rendering_context_2d_settings.idl.
CanvasToneMappingMode enum
Inputs & allowed values. CanvasToneMappingMode accepts exactly two case-sensitive strings: "standard" (default) and "extended".
Outputs & color-volume behavior. The enum selects how the canvas output bitmap’s HDR headroom is bounded before color space conversion to the display:
| Value | Bitmap HDR headroom | Rendering & encoding effect |
|---|---|---|
"standard" (default) | 0 stops (SDR) | Restricts content to the standard dynamic range of the target display. Values above 1.0 in linear float16 buffers are tone mapped / clamped to SDR on display and when encoded to PNG, JPEG, or WebP. |
"extended" | Unlimited | Does not restrict the bitmap’s HDR headroom during tone mapping; pixel values above 1.0 remain intact up to the display’s effective HDR headroom (further limited by CSS dynamic-range-limit) and are preserved when encoded to HDR-capable image outputs. |
CanvasToneMappingMode; WHATWG HTML PR #11734.
CanvasToneMapping dictionary
Inputs. CanvasToneMapping is a WebIDL dictionary with one optional member: mode of type CanvasToneMappingMode, defaulting to "standard". Passing an empty object {} or omitting mode resolves to { mode: "standard" }. Future specifications may add additional tone-mapping parameters to this dictionary without changing the call shape.
Outputs. When HTML’s get a canvas tone mapping algorithm processes a CanvasToneMapping value, it constructs an internal canvas tone mapping record storing mode. When reflected back through getContextAttributes(), the returned CanvasToneMapping object always populates mode with either "standard" or "extended".
CanvasToneMapping; WPT getContextAttributes.html.
CanvasRenderingContext2DSettings.toneMapping & getContextAttributes()
Inputs. Pass toneMapping in the second argument to HTMLCanvasElement.getContext("2d", settings) or OffscreenCanvas.getContext("2d", settings) alongside colorSpace (for example "srgb-linear" or "display-p3-linear") and colorType: "float16". When toneMapping is omitted or {}, the context defaults to { mode: "standard" }.
Outputs. ctx.getContextAttributes() returns a new CanvasRenderingContext2DSettings dictionary whose toneMapping member is { mode: "standard" } or { mode: "extended" } reflecting the context’s active tone mapping mode. In browsers that do not implement Canvas2D tone mapping, getContextAttributes().toneMapping is undefined.
getContextAttributes.html; Blink canvas_context_creation_attributes_module.idl.
Output rendering, dynamic-range-limit, ImageBitmap, and HDR encoding
Inputs & rendering pipeline. When a canvas backing store bitmap is presented to an output device — directly from <canvas>, through a placeholder <canvas> bound to an OffscreenCanvas, or via ImageBitmapRenderingContext — the browser first tone maps the bitmap according to its toneMapping mode to the output device’s HDR headroom as limited by the element’s CSS dynamic-range-limit property, and then converts to the output device’s color space. The resulting HDR headroom is min(bitmap HDR headroom, target headroom), and out-of-gamut colors at that headroom are projected into gamut in an implementation-defined manner.
Outputs & metadata preservation.
dynamic-range-limitinteraction: A canvas configured withtoneMapping: { mode: "extended" }on an element styled withdynamic-range-limit: standardis clamped to 0 stops of headroom (SDR), matching"standard"output.ImageBitmappreservation: Creating anImageBitmapviacreateImageBitmap(canvas)oroffscreenCanvas.transferToImageBitmap()preserves the source canvas’stoneMappingbehavior when transferred to anImageBitmapRenderingContextor drawn onto another 2D canvas.- Image serialization (
toDataURL(),toBlob(),convertToBlob()): Verified in WPTencode-hdr.htmlacrossimage/png,image/jpeg, andimage/webp: drawing linearcolor(srgb-linear 16 16 16)into afloat16canvas encodes to SDR white (~1.0) undertoneMapping: { mode: "standard" }and preserves the extended ~16.0HDR signal undertoneMapping: { mode: "extended" }when decoded back into an HDR float16 destination canvas.
encode-hdr.html; ColorWeb-CG canvas-tone-map.md.
Errors, validation, and feature detection
- Invalid
CanvasToneMappingModestring: Passing an unrecognized value such as{ toneMapping: { mode: "hdr" } }throws a WebIDLTypeErrorduring dictionary conversion when the browser supportstoneMapping. - Non-object
toneMappingmember: Passing a primitive such as{ toneMapping: "extended" }throws a WebIDLTypeErrorbecausetoneMappingexpects aCanvasToneMappingdictionary (orundefined/null, which default to{ mode: "standard" }). Note that Blink applies[PermissiveDictionaryConversion]to the outergetContext()options bag itself, not to nested invalid enum strings. - Unsupported browsers: Engines that do not recognize
toneMappingsilently ignore the unknown dictionary key duringgetContext("2d", options)and omittoneMappingfromgetContextAttributes(). - Reliable feature detection: Inspect
ctx.getContextAttributes()?.toneMapping?.modeafter creating a probe canvas with{ toneMapping: { mode: "extended" } }; it equals"extended"only when Canvas2D tone mapping is supported and active.
CanvasToneMapping; Blink canvas_context_creation_attributes_module.idl; WPT encode-hdr.html.
Context, exposure, and lifecycle
Exposure & prerequisites. CanvasToneMapping, CanvasToneMappingMode, and CanvasRenderingContext2DSettings.toneMapping are exposed on both Window (via HTMLCanvasElement.getContext("2d", options)) and Worker contexts (via OffscreenCanvas.getContext("2d", options)). No secure context, permission prompt, or user activation is required. Rendering pixel values brighter than SDR white additionally requires an HDR-capable display, a compatible pixel format (colorType: "float16") and wide/linear color space (such as srgb-linear or display-p3-linear), and an ancestor/element dynamic-range-limit that permits HDR headroom.
Lifecycle & immutability. toneMapping is fixed when the 2D rendering context is first created. Calling canvas.getContext("2d", { toneMapping: { mode: "extended" } }) on a canvas that already initialized a 2D context returns the existing context unchanged and ignores the new options; to switch modes dynamically at presentation time without recreating the canvas, keep toneMapping: { mode: "extended" } and modulate CSS dynamic-range-limit on the <canvas> element, or create a fresh canvas element.
getContextAttributes.html; CSS Color HDR dynamic-range-limit.
Examples
dynamic-range-limit interplay, encode & ImageBitmap round-trip, feature detection kit, one dictionary, three contexts). Source: chrome-platform-showcase.Creating an extended HDR 2D canvas and feature-detecting toneMapping
function supportsCanvas2DToneMapping() {
const probe = new OffscreenCanvas(1, 1);
const ctx = probe.getContext("2d", {
toneMapping: { mode: "extended" },
});
return ctx?.getContextAttributes()?.toneMapping?.mode === "extended";
}
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d", {
colorSpace: "srgb-linear",
colorType: "float16",
toneMapping: { mode: "extended" }, // CanvasToneMappingMode: "standard" | "extended"
});
// Reflects { mode: "extended" } in Chrome 160+; undefined in older browsers.
const attrs = ctx.getContextAttributes();
console.log("Active CanvasToneMapping:", attrs.toneMapping);
// Draw SDR white on the left and 4x HDR highlight on the right.
ctx.fillStyle = "color(srgb-linear 1 1 1)";
ctx.fillRect(0, 0, canvas.width / 2, canvas.height);
ctx.fillStyle = "color(srgb-linear 4 4 4)";
ctx.fillRect(canvas.width / 2, 0, canvas.width / 2, canvas.height);
Source: HTML Living Standard — CanvasToneMapping; WPT getContextAttributes.html.
Preserving toneMapping across ImageBitmap, OffscreenCanvas, and dynamic-range-limit
// Encode HDR pixels from an OffscreenCanvas with extended toneMapping
const offscreen = new OffscreenCanvas(64, 64);
const offCtx = offscreen.getContext("2d", {
colorSpace: "srgb-linear",
colorType: "float16",
toneMapping: { mode: "extended" },
});
offCtx.fillStyle = "color(srgb-linear 8 8 8)";
offCtx.fillRect(0, 0, 64, 64);
// ImageBitmap preserves the source canvas's toneMapping behavior.
const bitmap = offscreen.transferToImageBitmap();
// Alternatively, encode to PNG/WebP/JPEG while retaining HDR metadata:
const hdrBlob = await offscreen.convertToBlob({ type: "image/png" });
// Constrain presentation headroom declaratively via CSS dynamic-range-limit:
// canvas.style.dynamicRangeLimit = "standard"; // caps output to SDR
Source: WPT encode-hdr.html; ColorWeb-CG canvas-tone-map.md.
Browser compatibility
| Browser | toneMapping support | Evidence / notes | Base getContextAttributes() (BCD) |
|---|---|---|---|
| Chrome (desktop, Android, WebView) | 160 | Enabled by default in Chrome 160 across desktop, Android, and WebView per ChromeStatus API record (CanvasToneMapping Blink runtime feature) | 73 |
| Edge | 160 (mirror) | Chromium-based; mirrors Chromium’s CanvasToneMapping implementation | 79 (mirror) |
| Firefox | No release | Mozilla standards-positions#1359 (No signal yet) | 117 |
| Safari | No release | Positive / supportive signal on WHATWG HTML PR #11734; no shipped Safari version yet | 15 |
api/CanvasRenderingContext2D.json; mozilla/standards-positions#1359; WebKit comment on PR #11734.
Security and privacy
Configuring CanvasToneMapping ("standard" or "extended") only governs how the canvas’s own pixel values are mapped to the display’s dynamic range and how encoded image metadata is tagged. According to ChromeStatus and the HTML specification, toneMapping does not expose the output device’s HDR headroom, display peak luminance, or gamut projection algorithm to JavaScript, introducing no new cross-origin data channel or fingerprinting surface beyond existing canvas capabilities. Security and privacy reviews are listed as Pending in the ChromeStatus API record (checked 2026-11-24).
Specifications
| Specification | Section |
|---|---|
| HTML Living Standard (WHATWG) | CanvasToneMapping & CanvasToneMappingMode · The canvas settings · Colour spaces and colour correction |
| CSS Color HDR Module Level 1 (W3C Editor’s Draft) | dynamic-range-limit property · HDR headroom |
| WebGPU (W3C Candidate Recommendation) | GPUCanvasToneMapping (unified into HTML’s CanvasToneMapping) |
see also
- Chrome Platform Showcase — Canvas2D tone mapping demos
- W3C ColorWeb-CG explainer — Tone mapping for 2D Canvas
- W3C ColorWeb-CG — HDR on the web: the big picture
- WHATWG HTML PR #11734 — Add tone mapping to canvas
- MDN —
CanvasRenderingContext2D.getContextAttributes() - ChromeStatus — Canvas2D tone mapping (5077164932333568)