Skip to content

A look at the spatial CSS developer preview WebKit published on November 16. Safari on visionOS 27.3 opens five features for gathering, placing and moving 3D models in CSS. The post covers the block-puzzle example, how to turn it on, and why it is still only a preview.

Published

WebKit is the team behind Safari's browser engine. On November 16 it published a developer preview of spatial CSS on its blog. Safari on visionOS 27.3 now has a limited preview of the proposed spatial CSS API, aimed first at 3D objects shown through the <model> element. The author, Brandel Zachernuk, calls it a big conceptual jump that is made of many small tweaks to existing syntax.

  • Several 3D models are gathered inside a spatial: portal so they share one space.
  • Models move independently with transform and snap together with position-anchor.
  • Lighting comes from @environment-map, looking around from portal-action: orbit, and launching the scene out of the window from requestVolumetricScene().

Image: WebKit blog

The 3D <model> element is now available in Safari 27 on all platforms. WebKit's starting point is that the web works best when content adapts to display capability, window size and color theme, and that spatial content should not be designed only for headsets. Phones, tablets and computers show 3D content too.

So the features are routed through declarative CSS. A page can use media queries for aspect ratio, color theme and reduced motion to adapt a spatial layout, with less JavaScript and no complicated state to track. Numeric parameters can be animated and transitioned like any other value, WebKit says.

Web pageholds the 3D model elements
Media queriesaspect ratio, color theme, reduced motion
Spatial CSSportal, transform, position-anchor
3D scenemodels placed in one space
  • Web page → Media queries
  • Media queries → Spatial CSS (depending on conditions)
  • Spatial CSS → 3D scene
Source: summarized from the WebKit blog post.

The original walks through five features with a children's shape-sorter board and a few blocks.

데이터 표
spatial: portalMakes an element such as a figure or div a space its children sharespatial: portal
transformMoves, rotates and scales each model independently inside the shared spacetransform: translateX(-50cm)
position-anchorAttaches a model to a named spot on another modelposition-anchor: --board#octagon-position
@environment-mapNames a 360-degree HDR image as lighting that can be reusedenvironment-map: spooky
portal-action: orbitLets the viewer rotate the scene in placeportal-action: orbit
requestVolumetricScene()Pulls the scene out of the browser window into the user's spaceworld.requestVolumetricScene()

Source: WebKit blog post. Examples are shortened from its code.

spatial: portal goes on an element that can contain other elements, such as a figure or div. The preview focuses on model elements, but the specification is written so the approach should work for all content. Models inside a portal receive a true 3D transform from the same matrix class that already builds 2D and pseudo-3D transforms.

The model element is a void element, so models cannot nest inside each other. WebKit borrowed the CSS idea of position-anchor instead. In the example, the board file in a 3D editor carries reference points, often called null objects or empties, for each block's correct position. Rather than copying values out of the editor, the page names those anchor points and places a block exactly there. The anchor points can be animated, too.

Image: WebKit blog

The code below is shortened from the original. First, moving the blocks off to the sides of the board.

Source codecss
#octagon { transform: translateX(-50cm); }
#star    { transform: translateX(50cm); }

Next, naming the board and snapping the octagon block to its reference point. The star block is hidden in this scene.

Source codecss
#board   { anchor-name: --board; }
#octagon {
  position-anchor: --board#octagon-position;
  position-context: anchor;
}
#star    { display: none; }

Lighting is declared with a name, like @keyframes, and then referenced from an element. The preview supports 360-degree HDR images.

Source codecss
@environment-map {
  name: "spooky";
  format: equirectangular;
  src: url("night.hdr");
}

.world.spooky { environment-map: "spooky"; }

The request to move the scene out of the window comes from a user action. The user can place the Connected Volumetric Scene anywhere in their space, and the live link between page and scene lets the page add, remove or move objects.

Source codejs
launchSpaceButton.addEventListener("click", event => {
  const world = document.querySelector(".world");
  world.requestVolumetricScene();
});

Image: WebKit blog

On Vision Pro or in the visionOS Simulator, go to Settings > Apps > Safari > Advanced > Feature flags > CSS Portals. Simulators are installed through Xcode, and Apple's developer documentation explains how. The block-puzzle scene is on WebKit's demo page.

The scope is clear. This preview is limited to Safari on visionOS 27.3 and targets the 3D <model> element. WebKit adds that there is a long journey ahead and much more in the proposed specification to cover. It released the preview together with the full specification as an indication of how to bring spatial concepts to the web.

For web developers, the point of this post is less a new API to memorize than the fact that 3D is handled with tools they already know. Media queries, named rules, anchors and animation all work the way CSS works today. When a 3D scene needs conditional behavior, the most noticeable thing is that it does not have to move into JavaScript state management.

The distance is just as clear. This is a proposed specification and a limited preview on one platform. How other browsers will take it, and when the specification will settle into its final shape, cannot be read from this post. What can be done now is turn the preview on and send WebKit feedback.