molecules
Media figure
One image, picture, or video in a figure with an optional caption and an optional lightbox zoom.
Specimens

{{ Media.render({
loading: "lazy",
styles: {
image: "block w-full",
caption: "mt-2 text-sm text-neutral-400"
},
image: (collections.projectPages | filterByKey("slug", "connecting-a-world-famous-dj-with-his-fans") | first).decisions.0.artifact
}) }}{{ Media.render({
zoom: true,
loading: "lazy",
styles: { image: "block w-full" },
image: (collections.projectPages | filterByKey("slug", "connecting-a-world-famous-dj-with-his-fans") | first).decisions.1.artifact
}) }}{{ Media.render({
alt: "Project screen capture",
styles: { image: "block w-full" },
video: {
src: (collections.projects | filterByKey("slug", "connecting-a-world-famous-dj-with-his-fans") | first).featuredVideo.url
}
}) }}Params
| Param | Type | Description |
|---|---|---|
image | object | Sanity image: asset.url, asset.metadata.dimensions, alt, and caption. The only source that gets width and height. |
picture | string | Pre-rendered <picture> or <img> HTML. Wins over image. Carries its own alt. |
video | object | src and poster. Wins over picture and image. Only used when src is set. |
alt | string | Fallback for image.alt. The only alt for picture and video. |
caption | string | Fallback for image.caption. Renders a <figcaption>. |
classes | string, variant map, or array | Applied to the <figure> through classes. |
styles | object | Slot map. See the slot table. |
zoom | boolean | Wraps the media in the lightbox trigger (data-lightbox-el) and renders the dialog from lightbox-dialog.njk. |
loading | string | loading attribute on the <img> only. Defaults to eager. |
attrs | string | Raw attributes added to the <figure>. |
overlay | string | Pre-rendered decorative HTML (aria-hidden, absolutely positioned) output last inside the <figure>. The caller positions the figure. |
| Slot | Element |
|---|---|
image | The media element: <video>, the <span> around picture, or <img>. |
caption | The <figcaption>. |
Notes
Only an image gets intrinsic width and height. The figure renders nothing when it has no media. No styles are hard-coded, so pass styles.image and styles.caption.