Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

WebKit 9 min read Deep dive mediumAdept

Wide Gamut 2D Graphics using HTML Canvas

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.

Assumes: HTML canvas 2D APICSS color syntax

Related posts

  • Add wide gamut P3 and alpha transparency to your color picker in HTML

    WebKit mediumAdept

    `<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. With `colorspace="display-p3"` users can pick from the full P3 wide gamut, `limited-srgb` keeps the old 8-bit sRGB behavior, and `alpha` adds an opacity control. The `value` attribute now accepts any CSS color syntax, such as named colors, `oklab()` or `color(display-p3 ...)`, not just hex. Older browsers fall back to an sRGB picker without opacity, and to black for unsupported value syntax, so the attributes can be used today as progressive enhancement.

  • Customizing Color Fonts on the Web

    WebKit mediumAdept

    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. Browsers without support fall back to palette 0, which can be guarded with `@supports`. `font-palette: light`/`dark` pick palettes the font marks for light or dark backgrounds and pair naturally with `prefers-color-scheme`. Because palette rules are scoped per font family, one palette name can map to different palettes across fallback fonts. Foreground-color shapes in some fonts follow the `color` property instead, and authors should keep palette contrast high for legibility.

  • WebKit Features in Safari 18.2

    WebKit mediumAdept

    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. It also brings modern calc() with division by units, ruby-align/ruby-overhang and unprefixed ruby-position, scrollbar-width and scrollbar-gutter (which has no effect with overlay scrollbars), ::target-text styling for text fragment links, spatial video and photo viewing in visionOS, WebXR enabledFeatures, Genmoji support, WASM garbage collection and HTTPS by default. Code samples show how to apply each feature, and Safari is the first browser to ship text-box, which degrades gracefully as a progressive enhancement.

  • WebKit Features for Safari 27.1

    WebKit mediumAdept

    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. Developers can preview the Device Posture API (device-posture media query, navigator.devicePosture) and the Viewport Segments API (horizontal/vertical-viewport-segments media queries, viewport-segment-* env variables, window.viewport.segments) behind feature flags, with code examples for fold-aware grid layouts. Web content does not yet extend behind the side-mounted controls on the outer display, and WebKit is exploring alternatives to viewport-fit=cover because many sites fail to inset all edges correctly.

  • Steganography at scale: Embedding share URLs in Datadog widget screenshots

    Datadog Engineering mediumAdept

    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. A first scheme packing a byte per pixel via RGB offsets broke under display color-profile conversion (e.g., DCI-P3 shifting channels by ±1) and was sometimes visible. The final design uses fuzzy encoding: ±3 offsets on red and green carry 2 bits per pixel, decoded within tolerance ranges, with blue-shifted sentinel pixels marking a 34-pixel watermark. The system also handles device pixel ratios and copy-paste workflows, and renders over a billion watermarks per day with an estimated ~1 in 37 million collision probability.

The quest for software engineering knowledge.

Look:
Layout: