Skip to content
SkillCodex
Menu

Lightbox

Lightbox

A modal viewer that enlarges one media item and may let the user move through a related collection.

Try the component
Context, sources and actions
Sources and revision
Updated
Version
v1.0.26 · r2
Sources
5 sources
Status
Published
Read the sources

You may have searched for: open this photo bigger over the pageview gallery images without leavinga full overlay for one product image

All phrasings
Save and share

Recognize

Modal surfaces

Try it

Is the task about acting, confirming a consequential decision, or viewing media?

Lightbox

Shared trial context

A project item opens a focused overlay while the underlying workspace remains unavailable until the user finishes or closes it.

Lightbox

Mission

Lightbox

Open the second image, move to the next one with the keyboard, then close and return to the same thumbnail.

Live result

The gallery is available in the page.

Step 1 of 3

Try

Try the component. Your live result appears just above. Move on at your own pace.

Behavior and edge case
What to observe
The selected photograph is enlarged with its caption, position in the set, and navigation controls.
Edge case
A failed image load preserves the caption and navigation, reports the failure in text, and never leaves an empty modal.

What this example shows

Lightbox is a media-specific modal composition; a general Modal dialog handles tasks and an Alert dialog handles a consequential decision.

Which fits your need?

Lightbox

Inspecting product photography at a larger size

Modal dialog

Editing a compact record without losing page context

Which component will you use here?
Difference and sources

Lightbox is a media-specific modal composition; a general Modal dialog handles tasks and an Alert dialog handles a consequential decision.

Read the sources

    Parts of the specimen

    Select a numbered marker on the schematic, or use the list below, to see its role. The schematic shows the concept's representative state.

    Backdrop

    The layer that separates a modal surface from inactive page content.

    Position in the atlas

    Relationship map

    Locate the chapter, neighboring concepts, and the next useful decision.

    • Chapter

      Modal surfaces

      Lightbox belongs to this comparison group.

    • Do not confuse

      Modal dialog

      Choose Lightbox if viewing or browsing images or videos is the primary task. Choose Modal dialog if the user fills in a form or completes another contained task.

      Compare this pair
    • Do not confuse

      Alert dialog

      Choose Lightbox if viewing media at a larger size is the task, with no consequential decision. Choose Alert dialog if the user must decide before a consequential action.

      Compare this pair
    • Next step

      Compare the concepts in the chapter before choosing an implementation.

      Open the chapter

    In your own words

    Understand

    What people describe

    Documented aliases: image viewer, media viewer, photo overlay

    • open this photo bigger over the page
    • view gallery images without leaving
    • a full overlay for one product image
    • click a thumbnail to inspect the picture
    • previous and next photos in a popup
    • zoom an image with a caption and close button

    Choose

    Use it when

    • Inspecting product photography at a larger size
    • Moving through a small related image collection

    Avoid it when

    • The media must be compared side by side
    • The content is a form or consequential decision

    Compare

    Compare similar concepts

    Verification checklist

    Try these actions in the lab, then check the same behaviours in your agent’s result. Adapt the example names to your interface.

    1. 1. Do this

      Open the second image in the gallery and read its caption.

      Expected result

      The viewer opens the chosen image, with enough context to identify it and its place in the gallery.

    2. 2. Do this

      Reach the previous, next and close controls with the keyboard, and move to another image.

      Expected result

      The controls remain reachable inside the viewer, and the caption changes to describe the newly shown image.

    3. 3. Do this

      Close the viewer with Escape, then reopen it in a narrow window.

      Expected result

      Focus returns to the thumbnail that opened it; the image, caption and close control remain usable in the narrow layout.

    Full contract
    1. 1The selected media and its caption are clearly identified
    2. 2Keyboard users can reach navigation and close controls
    3. 3Focus returns to the originating thumbnail
    4. 4Loading and media errors have a textual fallback

    Understand → Recognize → Choose → Compare

    Pack for your agent

    Pre-written instructions to paste into your agent. Copying executes nothing.

    Implement correctly

    Build Lightbox without breaking its behavior

    # Implement Lightbox in your agent
    
    ## Objective
    Implement Lightbox for this verified behavior: A modal viewer that enlarges one media item and may let the user move through a related collection.
    
    ## Prerequisites
    - Inspect the repository, design system, and existing tests first.
    - Preserve unrelated changes and keep the file scope bounded.
    - Confirm that Lightbox matches the need before writing code.
    
    ## Required behavior
    - While modal, keyboard focus stays inside the surface until it closes.
    - Previous and next controls move through the collection without leaving the viewer.
    - Escape closes the temporary surface and returns focus to a sensible control.
    
    ## States to cover
    - Gallery view
    - Media expanded
    
    ## Accessibility
    - ARIA role: dialog[aria-modal=true]
    - The primary control or named region for Lightbox has a stable accessible name from visible text or an explicit programmatic label; placeholder text and tooltips are not names.
    - Opening moves focus to the viewer or close control, contains it, and closing returns it to the originating thumbnail.
    - The named close control and Escape always dismiss; outside press is optional and never the only path.
    - The viewer title, current item position, caption, image alternative text, and loading failures are available to assistive technology.
    - Tab reaches viewer controls
    - Left and Right move between media when documented
    - Escape closes the viewer
    
    ## When not to use
    - The media must be compared side by side
    - The content is a form or consequential decision
    
    ## Acceptance criteria
    - The selected media and its caption are clearly identified
    - Keyboard users can reach navigation and close controls
    - Focus returns to the originating thumbnail
    - Loading and media errors have a textual fallback
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    
    • @radix-ui/react-dialog
    • Requires · Access to the repository, design system, and tests
    Why it works
    • The need is tied to canonical behavior before any technical choice.
    • States, accessibility, and non-goals prevent a merely visual implementation.
    • Acceptance criteria and the output format make verification observable.

    Try next

    Verify Lightbox on a real journey

    # Verify Lightbox after implementation
    
    ## Objective
    Audit the Lightbox implementation against its behavior, states, and accessibility requirements without changing it automatically.
    
    ## Checks
    - Replay the smallest representative journey.
    - Check keyboard behavior, focus, accessible name, and announcements.
    - Tie each gap to a specific acceptance criterion.
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    

    sha256:8583d38014118d215f3c5852f3f571b5bcf9963a54ee358e460c82c1be214657

    Diagnose a problem

    Find and fix the Lightbox defect

    # Debug Lightbox in your agent
    
    ## Observed symptom
    [DESCRIBE THE SYMPTOM HERE]
    
    ## Observable checks
    - Reproduce the issue with the smallest relevant journey.
    - Compare behavior with the documented states and transitions for Lightbox.
    - Verify keyboard behavior, focus, accessible name, and announcements.
    
    ## Possible causes
    - The chosen primitive does not match the expected behavior.
    - A state, transition, or focus return is missing.
    - A neighboring component captures an event or hides an accessible signal.
    
    ## Bounded corrections
    - Fix the reproduced cause without recreating neighboring components.
    - Preserve the public contract and add a focused regression test.
    - Do not install dependencies or change remote state without authorization.
    
    ## Final verification
    - The selected media and its caption are clearly identified
    - Keyboard users can reach navigation and close controls
    - Focus returns to the originating thumbnail
    - Loading and media errors have a textual fallback
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    
    • @radix-ui/react-dialog
    • Requires · Access to the repository, design system, and tests
    Why it works
    • The explicit symptom prevents starting from an assumed fix.
    • Checks separate behavior, accessibility, and neighboring interference.
    • The fix stays bounded and must produce regression evidence.

    Try next

    Lock in the Lightbox fix

    # Prevent the Lightbox regression
    
    ## Objective
    Turn the reproduced cause into a focused regression test and compare Lightbox with neighboring concepts before widening the fix.
    
    ## Checks
    - Prove that the test fails before the fix.
    - Prove that it passes after the bounded fix.
    - Verify that no neighboring component changed behavior.
    
    ## Guardrails
    - Show the proposed changes before any external action.
    - Do not publish, send, delete, pay for, or change remote state without explicit authorization.
    - Preserve unrelated changes and stop if the scope becomes ambiguous.
    
    ## Output format
    - Outcome or verdict.
    - Files or actions involved.
    - Checks run and observable evidence.
    - Remaining blockers or limitations.
    

    sha256:c4e201ae14f403023718bd3404c65cef302a8426ebb91805c525b1847346428c

    Full entry, saving and provenance

    Pre-written instruction by SkillCodex — your request is neither sent nor used to adapt this text; no content is generated, and copying executes nothing.

    Pack digest: sha256:0830dc649f066b58bd8cfa8f79f53a65b07b25436f56887e75bfc4941810d594

    In code

    TechnologyPrimitiveVersionCaveat
    @radix-ui/react-dialog

    Dialog.Root

    @radix-ui/react-dialog@1.1.19Dialog supplies modal containment only; media navigation, captions, loading, zoom, and gestures are an explicit composition.

    Technical details

    Behaviors

    • Contain focus

      While modal, keyboard focus stays inside the surface until it closes.

    • Navigate media

      Previous and next controls move through the collection without leaving the viewer.

    • Dismiss with Escape

      Escape closes the temporary surface and returns focus to a sensible control.

    States

    • Gallery view

      Gallery view

    • Media expanded

      Media expanded

    State transitions

    • Gallery view → Media expanded

      A thumbnail is activated and its media opens with caption and navigation context.

    • Media expanded → Gallery view

      Close or Escape dismisses the lightbox and restores focus to the originating thumbnail.

    Test scenarios

    Context
    A product gallery contains four detailed photographs with meaningful alternative text and captions.
    Mission
    Open the second image, move to the next one with the keyboard, then close and return to the same thumbnail.
    Primary state
    The selected photograph is enlarged with its caption, position in the set, and navigation controls.
    Edge case
    A failed image load preserves the caption and navigation, reports the failure in text, and never leaves an empty modal.

    Visual signals

    • Large media centered over the page
    • Caption or item count near the media
    • Previous, next, and close controls

    Behavioral signals

    • Thumbnail activation opens the corresponding item
    • Arrow controls navigate related media
    • Focus remains within the modal viewer

    Accessibility

    Role
    dialog[aria-modal=true]
    Accessible name
    The primary control or named region for Lightbox has a stable accessible name from visible text or an explicit programmatic label; placeholder text and tooltips are not names.
    Focus
    Opening moves focus to the viewer or close control, contains it, and closing returns it to the originating thumbnail.
    Dismissal
    The named close control and Escape always dismiss; outside press is optional and never the only path.
    Scroll
    Background scrolling is locked while the modal is open. Overflow scrolls inside the surface and the focused control remains visible.
    Announcement
    The viewer title, current item position, caption, image alternative text, and loading failures are available to assistive technology.
    Keyboard
    • Tab reaches viewer controls
    • Left and Right move between media when documented
    • Escape closes the viewer

    Bindings

    Open the HTML, ARIA, Radix, and shadcn matrix
    • Dialog.Root

      implementationKind
      shadcn-radix
      nativeElement
      Not applicable
      ariaPattern
      dialog
      radixPrimitive
      Dialog
      shadcnRecipe
      Dialog with figure viewer
      runtimeDependency
      @radix-ui/react-dialog@1.1.19
      packageName
      @radix-ui/react-dialog
      exportName
      Dialog.Root
      exactVersion
      1.1.19
      status
      verified
      sourceId
      source-ui-radix-dialog
      deprecationStatus
      active
      replacement
      Not applicable
      validFrom
      Not applicable
      validUntil
      Not applicable

      Equivalence caveat: Dialog supplies modal containment only; media navigation, captions, loading, zoom, and gestures are an explicit composition.

      Verify binding source

    Sources

    • WAI-ARIA APG: Dialog Modal Pattern
      sourceId
      source-ui-aria-dialog-modal
      kind
      documentation
      canonicalUrl
      https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/
      publisher
      W3C WAI
      sourceRevision
      http-last-modified:2026-07-09T07:07:35Z
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:4282d2eeb383c717ba41f52f0db1643fb3eb9acc33fa3879ef817e27c162453e
      status
      verified

      Claim covered: Lightbox: informative APG guidance for the modal dialog pattern: roles, states, relationships, and keyboard interaction.

    • Radix Primitives: Dialog
      sourceId
      source-ui-radix-dialog
      kind
      documentation
      canonicalUrl
      https://www.radix-ui.com/primitives/docs/components/dialog
      publisher
      Radix Primitives
      sourceRevision
      http-etag:W/"df76fcc1be71ddeff0677a09beda6d7e"
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:068577fa4c5cf2ccc711b9e97e2473ed516e4840e220f2b2f03c552d346fc92f
      status
      verified

      Claim covered: Lightbox: documented parts, state APIs, interaction behavior, and implementation limits for Radix Dialog.

    • WHATWG HTML: The img element
      sourceId
      source-ui-html-image
      kind
      standard
      canonicalUrl
      https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element
      publisher
      WHATWG
      sourceRevision
      http-last-modified:2026-07-19T13:52:46Z
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:2a8bf4a2ae6c69ee0215e3bd1293a6a963271e014876cf729a3c25afe51d9de6
      status
      verified

      Claim covered: Lightbox: normative native semantics, states, attributes, and browser behavior for img.

    • WAI-ARIA 1.2: Roles Model
      sourceId
      source-ui-wai-aria-roles
      kind
      standard
      canonicalUrl
      https://www.w3.org/TR/wai-aria-1.2/#roles
      publisher
      W3C WAI
      sourceRevision
      W3C-REC-wai-aria-1.2-20230606
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:c0fea16fc747779569ab754d2d25bca3e2b7e8a673b8ef5362aeb9ebc73a4849
      status
      verified

      Claim covered: Lightbox: normative ARIA role definitions and constraints for the stated accessible role.

    • WCAG 2.2: Focus Appearance
      sourceId
      source-ui-wcag-understanding-focus-appearance
      kind
      documentation
      canonicalUrl
      https://www.w3.org/WAI/WCAG22/Understanding/focus-appearance.html
      publisher
      W3C WAI
      sourceRevision
      http-last-modified:2026-07-02T10:07:49Z
      consultedAt
      2026-07-19
      license
      Not stated
      contentDigest
      sha256:fdcf316a1f0e3cc758eda9618322d132862124ff0a3f3b1a3acbf20daf804ff0
      status
      verified

      Claim covered: Lightbox: informative WCAG guidance for evaluating visible keyboard focus appearance.