Skip to content

[css-spatial] Add CSS depth property #147

Open

Description

@khufu-dev

Similar to width and height, it would be beneficial to provide a CSS depth property that allows developers to set the depth of 3D content. For example, if a website loads a 3D model, there's no way to specify how deep the model goes into the portal. Currently, it is derived by the 3D asset and the width and height of the portal. The depth property would also be helpful in defining a 3D model in spatial: page mode.

Related

Spec: https://webkit.github.io/explainers/css-spatial/explainer.html

Activity

  1. fantasai commented on Oct 27, 2026

    @fantasai
    Contributor

    For example, if a website loads a 3D model, there's no way to specify how deep the model goes into the portal.

    You can do this with the inset-front and/or inset-back properties.

  2. khufu-dev commented on Oct 28, 2026

    @khufu-dev
    Author

    You can do this with the inset-front and/or inset-back properties.

    My understanding of inset-front and inset-back is that it allows positioning along the z-axis. But I want to control the thickness of the 3D model content. Based on my reading portal-stage cannot be used for this purpose.

    Image
  3. khufu-dev commented on Oct 29, 2026

    @khufu-dev
    Author

    Discussed this issue at TPAC 2027 and agreed that there are good use cases for this feature. Further thought and analysis is required.

  4. danielcamposramos commented on Nov 4, 2026

    @danielcamposramos

    The thickness of a 3D model is a measure of the scene in front of the camera, so a length in centimetres fits it, as width and height fit a box.
    Our desktop splits it the same way: real 3D content is drawn by two cameras in the scene's own units, while flat elements that only sit at a depth are drawn once per eye, shifted by pixels of disparity within the person's comfort limits (Declared planes and user limits).
    For that second case, positions of page elements rather than the thickness of a model, I opened #163.

  5. fantasai commented on Nov 5, 2026

    @fantasai
    Contributor

    Currently the width and height properties have no effect on model content, thus neither would depth. We could make them have an effect (and add a depth property) similar to how we size images, though; that likely makes sense.

    The trouble with introducing depth, though, is that we'd probably also want it to work on regular elements; and that's a fairly complex new feature that would need to be defined....

    So I think for Level 1, it might make sense to define only the effects of width and height (leaving depth to a future level). Note that the effective size of an object can be controlled with portal-transform and portal-stage as well, in the meantime.

  6. danielcamposramos commented on Nov 6, 2026

    @danielcamposramos

    The size a model takes on the page and the resolution it is rendered at are two different things.
    width and height set the box on the display.
    The rendering resolution, per eye on a stereo display, depends on the display and the person's quality setting, and the UA scales it once into that box.

    Neither says at what depth the model is painted.
    An author may want one model sunk behind the screen, another at screen level and a third popped in front of it, on the same page.
    Today that depth follows from the asset and the box, and the <model> UA style (front-limit: 0 !important) keeps its content behind its own glass.
    That is a position, not a thickness, and regular elements need the same one: the three levels in #163 (sunk, screen, popped), resolved against the person's limits on each display, would place models and regular elements alike.

  7. khufu-dev commented on Nov 9, 2026

    @khufu-dev
    Author

    @fantasai My understanding of the model spec and explainer is that the width and height is used to fit the 3D model within it's content box. I assume Spatial CSS would also include this object fit behaviour. Adding a depth property would extend that to the z-axis. I agree that more thought is required on how it would affect regular elements and the complexities associated with that.

    @danielcamposramos Agree, there's also a desire to have 3D models be rendered outside the portal. In that case portal-transform and portal-stage would be insufficient and a depth property would be required.

  8. fantasai commented on Nov 10, 2026

    @fantasai
    Contributor

    Currently how we've integrated the two is that width and height set the size of the <model> element's portal, and given portal-transform: auto (the initial value) and portal-stage: auto (the initial value), the effect is that they control the size of <model>. They don't act directly on the model, just as they don't act directly on shapes in an SVG but rather on its viewport.

  9. danielcamposramos commented on Nov 10, 2026

    @danielcamposramos

    The SVG comparison shows the gap, I think.
    An SVG viewport has two axes, and width and height size both; with preserveAspectRatio the shapes keep their proportions inside it.
    The portal has a third axis, and nothing in the box sizes or places content along it.
    So how deep a model is, and where it is painted (sunk behind the screen, at the screen, or popped in front of it), cannot follow from width and height, for <model> or for a regular element (#163).
    That is also the case khufu-dev raised: a model drawn outside the portal has no box at all to take its depth from.

  10. fantasai commented on Nov 10, 2026

    @fantasai
    Contributor

    That is also the case khufu-dev raised: a model drawn outside the portal has no box at all to take its depth from.

    What do you mean by "outside the portal"?

  11. danielcamposramos commented on Nov 10, 2026

    @danielcamposramos

    I meant khufu-dev's case in immersive-web/model-element#172: a <model> with spatial: page and a front-limit above 0, its content raised off the page in front of it instead of shown through the portal behind its box.
    Take the page as drawn at the screen: content can sit behind the screen, at the screen, or in front of it.
    How far in front it can go depends on the display, not on the box.
    On a 3D TV the screen's frame is always in view, so content in front of the screen has to stay close to it: an object that comes far forward and is cut by the frame stops reading as 3D.
    On a headset there is no screen corner to see, so the same page can bring content much further forward, and the two eyes' views can be further apart for the same object.
    The box gives the model's footprint, and front-limit caps how far it may come forward, but neither says how deep the model is or where it sits between the screen and that cap.
    A depth property, resolved against each display's limits as informed by the OS and the display type, like the three levels in #163 (sunk, screen, popped), would.

  12. fantasai commented on Nov 10, 2026

    @fantasai
    Contributor

    So currently we define spatial: page to create a containing volume in front of the page to contain position: spatial-absolute elements. If the model is given inset-front: 0 that will place its front plane flush with the front limit. If it's given inset-back: 0, that will place its back plane flush with the page (or inset into it, if necessary to keep the object below the front limit). I think that does what you want, while also giving more control to the author (e.g. inset-back: 5mm floats it 5mm above the page)?

  13. danielcamposramos commented on Nov 10, 2026

    @danielcamposramos

    The model does what I want, I think; it is the wording that needs adjusting, and the reference should be the physical screen.
    inset-back reads as "inside the box", but here it moves the object out of the screen, toward the viewer: it is popped, relative to the physical screen, whether that screen is a headset's display or a 3D TV.
    I made the same point in #163 (#163 (comment)): the name says where the distance is measured from, not where the object goes.

    Read from the screen, for spatial: page:

    model { position: spatial-absolute; inset-back: 0; }   /* its back on the screen, its body popped in front of it */
    model { position: spatial-absolute; inset-front: 0; }  /* popped as far as this display allows */
    model { position: spatial-absolute; inset-back: 5mm; } /* popped 5mm off the screen */

    The page plane is the screen: zero parallax, both eyes see the page in the same place.
    The front limit is the display's own popped limit, and it differs between displays: on a 3D TV the frame is always in view, so the limit stays close to the screen; on a headset there is no frame, so it can be much further out.
    So the same inset-front: 0 is a little out of a 3D TV and much further out on a headset, and that is right, as long as the limit comes from the display, informed by the OS and the display type, and not from the page.
    The other half is behind the screen: an object can also sit sunk, inside the display as if seen through a window, which is where a framed 3D screen shows depth most comfortably.
    Named from the screen, these are the three levels of #163:

    model { depth: screen; } /* inset-back: 0 */
    model { depth: popped; } /* inset-front: 0 */
    model { depth: sunk; }   /* behind the page plane, at the display's sunk limit */

    That is the wording I would like to see: distances measured from the physical screen, toward the viewer (popped) or away from them (sunk), each capped by the display's own limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions