---
title: "Wide Gamut 2D Graphics using HTML Canvas"
description: "WebKit now supports Display P3 color spaces for 2D canvas via getContext(\"2d\", { colorSpace: \"display-p3\" }), so fills, strokes, gradients, shadows and text can use wide gamut CSS colors."
url: "https://swe.quest/articles/wide-gamut-2d-graphics-using-html-canvas-c32c74a661ded0f9"
canonical: "https://webkit.org/blog/12058/wide-gamut-2d-graphics-using-html-canvas/"
source: "WebKit"
published: "2021-12-14"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 9
tags: ["browsers","frontend","javascript"]
---

# Wide Gamut 2D Graphics using HTML Canvas

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2021-12-14, 9 min read, Deep dive. Original: [https://webkit.org/blog/12058/wide-gamut-2d-graphics-using-html-canvas/](https://webkit.org/blog/12058/wide-gamut-2d-graphics-using-html-canvas/)

## Summary

WebKit now supports Display P3 color spaces for 2D canvas via getContext("2d", { colorSpace: "display-p3" }), so fills, strokes, gradients, shadows and text can use wide gamut CSS colors. Out-of-gamut colors are clamped to the canvas color space. getImageData, putImageData, the ImageData constructor and drawImage convert between color spaces, and toDataURL/toBlob embed color profiles. Code is included for detecting display, canvas and CSS Color 4 support. Remaining gaps include 8-bit-only ImageData, no HDR color spaces, and WebGL/WebGPU support.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- HTML canvas 2D API
- CSS color syntax ([easy posts on CSS](https://swe.quest/tags/css.md?difficulty=easy))

## Keywords

Display P3, HTML Canvas, WebKit, Safari, CSS Color Module Level 4, ImageData, sRGB

## Related posts

- [Add wide gamut P3 and alpha transparency to your color picker in HTML](https://swe.quest/articles/add-wide-gamut-p3-and-alpha-transparency-to-your-color-picker-in-html-2bf169620936554b.md): WebKit · 2025-05-07 · Medium · 4 min read · Browsers, Frontend, CSS
  \`\<input type="color"\>\` now supports two new optional attributes, \`alpha\` and \`colorspace\`, added to the HTML standard with WHATWG and first shipped in Safari 18.4.
- [Customizing Color Fonts on the Web](https://swe.quest/articles/customizing-color-fonts-on-the-web-74940ba780f012e8.md): WebKit · 2022-05-25 · Medium · 7 min read · CSS, Browsers, Frontend
  WebKit (Safari 15.4+) supports the CSS \`@font-palette-values\` at-rule, which lets authors select a color font's predefined CPAL palettes by index and override individual palette colors, then apply them with the \`font-palette\` property.
- [WebKit Features in Safari 18.2](https://swe.quest/articles/webkit-features-in-safari-18-2-9cf887b031bc5207.md): WebKit · 2024-12-09 · Medium · 22 min read · Browsers, CSS, Frontend, WebAssembly
  Safari 18.2 ships 61 new WebKit features and 111 fixes, headlined by cross-document View Transitions (with view-transition-name: auto, transition classes and types, and pageswap/pagereveal events), CSS text-box trimming for optical alignment to cap height, and background-clip: border-area.
- [WebKit Features for Safari 27.1](https://swe.quest/articles/webkit-features-for-safari-27-1-aa9f32f307e48f19.md): WebKit · 2026-10-23 · Medium · 6 min read · Browsers, CSS, Frontend, Mobile
  Safari 27.1 ships with iPhone Duo, a folding phone, using the same WebKit engine as other iPhones, so responsive sites work unchanged; viewport widths range from 382 to 951 CSS pixels and heights from 368 to 902 across the outer and inner displays and split windows.
- [Steganography at scale: Embedding share URLs in Datadog widget screenshots](https://swe.quest/articles/steganography-at-scale-embedding-share-urls-in-datadog-widget-screenshots-c180eafbb38c64ee.md): Datadog Engineering · 2026-04-21 · Medium · 20 min read · Frontend, Caching, Observability, Algorithms
  Datadog embeds an 8-byte snapshot ID invisibly into the 1 px border of every dashboard widget so screenshots can be resolved back to the full widget context (queries, time range, template variables), with definitions cached in Redis for one hour keyed by org ID plus widget ID.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
