Usage

Standard Images And Figures

The recommended API is ordinary Sphinx image and figure markup. The extension transforms eligible images only for HTML output.

Configure the transform policy in conf.py:

lightbox_images = "explicit"   # "explicit", "all", or "none"
lightbox_figures = "all"       # "explicit", "all", or "none"
lightbox_default_class = "with-shadow"

With lightbox_images = "explicit", opt a normal image into lightbox handling with :class: lightbox:

.. image:: /images/example-screenshot.png
   :alt: Standard image with lightbox behavior.
   :class: lightbox

Plain images do not have built-in Sphinx captions, so the overlay shows only the image:

With lightbox_figures = "all", figures are transformed by default. The normal figure caption and legend remain in the page and are copied into the lightbox overlay:

.. figure:: /images/example-screenshot.png
   :alt: Figure with lightbox behavior.

   This caption appears in the page and in the lightbox overlay.

   This legend is longer explanatory text attached to the figure.

This caption appears in the page and in the lightbox overlay.

This legend is longer explanatory text attached to the figure.

Add :class: no-lightbox to an individual image or figure to opt out when its policy is "all".

Captions And Legends

Plain image directives do not have Sphinx-native captions, so their overlays show only the image. Use figure when an image needs caption or legend text:

.. figure:: /images/example-screenshot.png
   :alt: Detail screenshot.
   :width: 55%

   The caption is copied into the lightbox overlay.

   The legend is copied too.

Sizing And Styling

Use standard Sphinx image options for thumbnails:

.. image:: /images/example-screenshot.png
   :alt: Smaller thumbnail.
   :width: 40%
   :align: center
   :class: lightbox with-border

Classes other than lightbox and no-lightbox are preserved on the thumbnail and overlay image. lightbox_default_class adds a default CSS class to transformed images; set it to an empty string to disable the default styling.

Image Paths

The extension supports two path styles:

Absolute paths (from the source root):

.. image:: /images/topic/screenshot.png
   :alt: Topic screenshot.
   :class: lightbox

Document-relative paths:

.. image:: ../images/topic/screenshot.png
   :alt: Topic screenshot.
   :class: lightbox

Both styles are resolved through Sphinx’s standard image pipeline. If the image file does not exist, a clear warning is emitted at build time with the resolved absolute path.

LaTeX / PDF Output

In LaTeX builds, each lightbox renders as a figure environment with \includegraphics and \caption. By default, the second :percentage: value controls the width as a fraction of \linewidth (e.g. 95 becomes 0.95\linewidth). The thumbnail is skipped — only the full-size image appears.

To control PDF sizing independently of HTML, use the optional :latex-width: option:

.. lightbox:: /images/diagram.png
   :alt: Architecture diagram.
   :percentage: 60 90
   :latex-width: 0.8

This sets the HTML overlay to 90% of the viewport while the PDF figure uses 80% of \linewidth. When :latex-width: is omitted, the second :percentage: value is used as before.

Other Builders

For the class-based image and figure transform, non-HTML builders keep the original Sphinx nodes. For the .. lightbox:: directive, builders that are neither HTML nor LaTeX (epub, man, texinfo, text) receive a plain image node with the alt text, ensuring content is never silently dropped.

JavaScript Disabled

The CSS checkbox-toggle mechanism still supports pointer-based opening and closing when JavaScript is disabled. Keyboard activation, Escape-to-close, focus movement, focus trapping, and arrow-key gallery navigation require the external lightbox.js enhancement.

Content Security Policy (CSP)

The lightbox extension uses an external JavaScript file for keyboard activation, Escape-to-close, focus management, and gallery navigation. It does not inject inline JavaScript.

The generated HTML does use inline styles for thumbnail width and overlay sizing. If your documentation is hosted with a strict Content Security Policy, ensure your policy permits inline styles:

Content-Security-Policy: style-src 'self' 'unsafe-inline';