Shared element
The picture you tap grows out of its own thumbnail into the full view and shrinks back into the same spot when closed (a FLIP transition). Because the object never disappears, people keep their place: the large view is visibly the same thing, not a new page.
Usage
Use it when
- Opening a photo, diagram or scan from a grid or an article into a lightbox.
- Any thumbnail whose large version is the same picture: campus photos, lab results, a scanned answer sheet.
Use something else when
- Opening details that are not the same picture (a course card to its page): use Nav progress. There is no generic shared-element transition for arbitrary elements yet; navigate normally.
- A form or a question over the page: use Dialog.
- Browsing a row of pictures in place: use Carousel.
- Content opening below its trigger: use Height expand.
- Showing a small picture in a list or a card: use Thumbnail.
Where it goes. On a .thumb link (<a class="thumb" href="large.jpg" data-lds-lightbox>) around an <img>, anywhere: an auto-grid of photos, a figure inside prose, a card. The lightbox is appended to <body> as a fixed layer.
Examples
<div class="auto-grid" style="--min: 150px;">
<a class="thumb" href="library-large.jpg" data-lds-lightbox data-caption="Central library, east entrance">
<img src="library-small.jpg" alt="The central library with its tall windows">
</a>
…
</div><div class="prose"> <p>Plant cells keep their shape because the cell wall pushes back when water flows in. The photo below shows the lab building where you will run the experiment in week 6.</p> <div style="max-width: 280px;"><a class="thumb" href="data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%20800%20600'%3E%3Crect%20width%3D'800'%20height%3D'600'%20fill%3D'%23DCFCE7'%2F%3E%3Ccircle%20cx%3D'640'%20cy%3D'130'%20r%3D'56'%20fill%3D'%23FDE68A'%2F%3E%3Crect%20x%3D'170'%20y%3D'210'%20width%3D'460'%20height%3D'270'%20rx%3D'8'%20fill%3D'%2315803D'%2F%3E%3Cpath%20d%3D'M150%20220%20L400%20110%20L650%20220%20Z'%20fill%3D'%2315803D'%2F%3E%3Cg%20fill%3D'%23DCFCE7'%20opacity%3D'0.85'%3E%3Crect%20x%3D'220'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'320'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'420'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'520'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'360'%20y%3D'380'%20width%3D'80'%20height%3D'100'%2F%3E%3C%2Fg%3E%3Crect%20y%3D'480'%20width%3D'800'%20height%3D'120'%20fill%3D'%23166534'%2F%3E%3C%2Fsvg%3E" data-lds-lightbox data-caption="Biology lab, building C, room 2.14"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%20800%20600'%3E%3Crect%20width%3D'800'%20height%3D'600'%20fill%3D'%23DCFCE7'%2F%3E%3Ccircle%20cx%3D'640'%20cy%3D'130'%20r%3D'56'%20fill%3D'%23FDE68A'%2F%3E%3Crect%20x%3D'170'%20y%3D'210'%20width%3D'460'%20height%3D'270'%20rx%3D'8'%20fill%3D'%2315803D'%2F%3E%3Cpath%20d%3D'M150%20220%20L400%20110%20L650%20220%20Z'%20fill%3D'%2315803D'%2F%3E%3Cg%20fill%3D'%23DCFCE7'%20opacity%3D'0.85'%3E%3Crect%20x%3D'220'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'320'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'420'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'520'%20y%3D'270'%20width%3D'60'%20height%3D'80'%2F%3E%3Crect%20x%3D'360'%20y%3D'380'%20width%3D'80'%20height%3D'100'%2F%3E%3C%2Fg%3E%3Crect%20y%3D'480'%20width%3D'800'%20height%3D'120'%20fill%3D'%23166534'%2F%3E%3C%2Fsvg%3E" alt="The biology lab building among trees"></a></div> <p>Bring a lab coat and your printed worksheet. The room opens 15 minutes before the session.</p> </div>
Motion and microinteractions
- FLIP: the large image is placed at its final position, then animated from the thumbnail rectangle (
translateplusscalefrom the measured boxes) tonone. Open: 420 ms on the enter curve (cubic-bezier(0.16, 1, 0.3, 1), the--ease-entervalues). Close: the same path reversed in 220 ms, back into the thumbnail. - Backdrop:
.lightboxfades in over--d-standardon--ease-enterand out over--d-exiton--ease-exit. - Only
transformanimates (origin at the top left corner), so the flight stays smooth with large images. - Interruption: closing during the opening flight starts the return from the current frame; nothing has to finish first.
- Reduced motion: no flight. The lightbox fades in and out (120 ms) and the image appears in place.
Accessibility
- The thumbnail is a real link to the large image, so it works without JS and opens in a new tab on middle click. Give the
<img>a realalt. - The lightbox is
role="dialog"witharia-modal="true", labelled bydata-caption(or the alt). Focus goes to the close button; Tab stays on it; Escape closes; focus returns to the thumbnail. - Put the caption in
data-caption; it is shown under the picture and used as the dialog label.
Do and don't
Do
- Use
data-lds-lightboxon a.thumblink with an<img>inside. - Keep the thumbnail at the same aspect ratio as the large image when you can; the flight then has no distortion.
- Write a caption that says what and where.
Don't
- Fade a lightbox in from the center when it was opened from a thumbnail.
- Animate
width,heightortopto fake the growth. - Use it for a picture the person has to compare with text side by side; open it in place instead.
Behavior and code
Plain HTML. init() wires a[data-lds-lightbox] (with an <img> inside): on click it builds the .lightbox dialog with .lightbox__close and .lightbox__caption from data-caption (close label from data-close), runs the FLIP flight, and on close runs it backwards and returns focus. The FLIP is specific to the lightbox; there is no general shared-element helper.