Figures & Galleries


Image display with PhotoSwipe lightbox integration

Beautiful Hugo provides powerful image handling through the beautifulfigure shortcode and gallery shortcode, both integrated with PhotoSwipe 5 for full-screen lightbox viewing.

The figure / beautifulfigure Distinction

The figure shortcode is a router:

  • When disableFigureOverride = false (default): {{< figure >}} delegates to beautifulfigure (PhotoSwipe-enhanced)
  • When disableFigureOverride = true: {{< figure >}} uses Hugo’s standard figure shortcode, and {{< beautifulfigure >}} remains available for PhotoSwipe

The example site uses disableFigureOverride = true, so figure gives a plain image and beautifulfigure gives the enhanced version.

Standard Figure

With disableFigureOverride = true, the standard figure shortcode produces a basic <figure> element:

A simple figure with a caption

{{< figure src="/img/global-ike.png "width="25%" caption="A simple figure with a caption" >}}

beautifulfigure

The beautifulfigure shortcode adds PhotoSwipe lightbox support — click the image to open it full-screen.

Basic usage

Click this image to open the lightbox

Click this image to open the lightbox

{{< beautifulfigure src="/img/global-ike.png" caption="Click this image to open the lightbox" width="25%" class="center" >}}

With title and attribution

A globe with transparency

Global Ike

A globe with transparency

PurePNG

{{< beautifulfigure src="/img/global-ike.png"
  title="Global Ike"
  caption="A globe with transparency"
  attr="PurePNG"
  attrlink="https://purepng.com/photo/30733/clipart-cartoon-globe"
  width="25%"
  class="center" >}}

With caption effects

Hover to see the caption slide in

Hover to see the caption slide in

{{< beautifulfigure src="/img/global-ike.png" caption="Hover to see the caption slide in" caption-effect="slide" width="25%" class="center" >}}
Hover to see the caption fade in

Hover to see the caption fade in

{{< beautifulfigure src="/img/global-ike.png" caption="Hover to see the caption fade in" caption-effect="fade" width="25%" class="center" >}}

With white background (for dark mode)

Add class="white" to give the figure a white background, which helps images with transparent backgrounds look clean in dark mode:

White background for dark mode

White background for dark mode

{{< beautifulfigure src="/img/global-ike.png" caption="White background for dark mode" class="white center" width="25%" >}}

All parameters

ParameterTypeDefaultDescription
srcstringURL of the image
linkstringvalue of srcURL of the full-size image (for lightbox)
thumbstringThumbnail URL
altstringcaption or srcAlt text for the <img>
captionstringCaption text below the image
titlestringTitle heading in the figcaption
attrstringAttribution text
attrlinkstringURL for the attribution
classstringCSS class on the <figure> element
sizestringPhotoSwipe dimensions: WIDTHxHEIGHT (e.g. 1024x768)
widthstringCSS max-width on the wrapper div
caption-positionstringPosition class for the caption
caption-effectstringEffect class: slide, fade, appear

Place beautifulfigure shortcodes inside a gallery shortcode to create a responsive grid:

{{< gallery caption-effect="fade" hover-effect="grow" >}}
{{< beautifulfigure src="/img/gallery/sunset.jpg" caption="Sunset" >}}
{{< beautifulfigure src="/img/gallery/forest.jpg" caption="Forest" >}}
{{< beautifulfigure src="/img/gallery/mountain.jpg" caption="Mountain" >}}
{{< /gallery >}}

Point the gallery shortcode at a directory under /static/ and it will auto-populate from all images found there. Filenames are humanized into captions (e.g. sunset.jpg becomes “Sunset”).

Thumbnail detection works by convention: if an image file contains the thumb suffix (default -thumb), it is used as the thumbnail for the matching full-size image. For example:

  • lake.jpg → full-size image, caption “Lake”
  • lake-thumb.jpg → thumbnail for lake.jpg
{{< gallery dir="/img/gallery/" caption-effect="fade" >}}
ParameterTypeDefaultDescription
dirstringPath relative to /static/ to auto-populate images
thumbstring-thumbSuffix that identifies thumbnail files
caption-positionstringbottombottom, center, or none
caption-effectstringslideslide, fade, or appear
hover-effectstringzoomzoom, grow, shrink, slidedown, or slideup
hover-transitionstringSet to none to disable hover transition

PhotoSwipe Lightbox

All images rendered through beautifulfigure or gallery are automatically integrated with PhotoSwipe 5. Clicking any image opens a full-screen lightbox with:

  • Pinch-to-zoom on touch devices
  • Swipe/keyboard navigation between images in a gallery
  • Automatic image dimension detection

Opting out

Add the no-photoswipe class to any <figure> element to exclude it from the lightbox:

<figure class="no-photoswipe">
  <img src="/img/global-ike.png" alt="No lightbox" />
</figure>

Specifying dimensions

For best performance, provide the size parameter with the image dimensions:

{{< beautifulfigure src="/img/global-ike.png" size="1920x1080" >}}

If size is not provided, PhotoSwipe will attempt to auto-detect the image dimensions.