MkDocs GLightbox Plugin
mkdocs-glightbox is an MkDocs plugin that integrates the GLightbox pure JavaScript lightbox library for image zooming and gallery functionality. It automatically applies a lightbox effect to images within your MkDocs documentation. The project is actively maintained with frequent updates, ensuring compatibility and feature enhancements.
Warnings
- breaking Version 0.5.0 replaced the `regex` library with `selectolax` for HTML processing. While this improves performance and maintainability, any projects that previously relied on `regex` as an indirect dependency or had custom logic tied to its behavior might experience breakage.
- gotcha When defining the `plugins` section in `mkdocs.yml`, MkDocs will override its default `search` plugin. To retain the search functionality, you must explicitly add `search` back to the `plugins` list alongside `glightbox`.
- gotcha Between versions 0.5.1 and 0.5.2, the `selectolax` dependency was initially pinned to `0.3.29` (to avoid missing binary wheel issues) and then updated to `>=0.3.29` to support Python 3.14. This indicates potential sensitivity to `selectolax` versions, especially in specific Python environments.
- gotcha The default `width` option for the lightbox changed from `100%` to `auto` in version 0.3.6 to prevent a bug with zooming large images. If you rely on images filling the full width of the lightbox by default, you might need to explicitly set `width: 100%` in your configuration.
- gotcha Version 0.4.0 introduced 'manual mode', allowing users to opt-in to the lightbox effect for specific images or pages. If `manual: true` is configured, images will no longer automatically have the lightbox effect unless they have the `on-glb` class or the page has `glightbox: true` metadata.
Install
-
pip install mkdocs-glightbox
Imports
- glightbox
plugins: - glightbox
Quickstart
mkdocs.yml:
```yaml
site_name: My Docs with Lightbox
theme: material # Or any other MkDocs theme
plugins:
- search # Keep default search if desired
- glightbox:
touchNavigation: true
loop: false
effect: zoom
auto_caption: true
```
docs/index.md:
```markdown
# Welcome
This is an image with a lightbox effect:

This is another image, part of a gallery:
{ data-gallery="my-gallery" }
```