A lightweight, responsive image gallery shortcode for Hugo with integrated lightbox functionality. No external dependencies required.
- Responsive grid layout (2-5 images per row)
- Supports different file types (.jpg, jpeg, .png, .gif, .webp)
- Built-in lightbox
- Keyboard navigation (←, →, ESC)
- No external dependencies
- Hover effect
- Simple installation
- Light/Dark mode support
- Create a
shortcodes
directory in your Hugo project'slayouts
folder if it doesn't exist: - Copy
image-gallery.html
into thelayouts/shortcodes
directory
- Place your images in any directory you want, e.g.:
static/
└── images/
└── my-gallery/
├── image1.jpg
├── image2.jpg
└── image3.jpg
- Use the shortcode in your markdown files:
{{< image-gallery gallery_dir="/images/my-gallery" >}}
- Click on any image to open the lightbox
- Use arrow keys (← →) to navigate between images
- Press ESC or click the X to close the lightbox
- Click outside the image to close the lightbox
The gallery uses CSS Grid for layout and comes with default styling. You can customize the appearance by modifying the CSS in the shortcode file.
Tested with:
- Hugo Extended Version
- PaperMod Theme
- Other Hugo themes should work as well
This gallery shortcode is under active development. The following features are planned for future releases:
- Check for file types (.jpg, jpeg, .png, .gif, .webp)
- Custom image captions in lightbox view
- Vertical gallery layout option (images stacked)
- Configurable grid layout (adjust number of images per row)
- More gallery customization options
- Separated files (CSS/JS)
gallery.css
for stylinggallery.js
for lightbox functionalityimage-gallery.html
for structure
- Markdown-style image syntax support
Feel free to:
- Open issues for bug reports or feature requests
- Submit pull requests for improvements
- Share your ideas in the discussions
Your contributions to make this gallery shortcode even better are welcome!
MIT
Based on the idea from hugocodex.org
Inspired by nicokaiser - hugo theme gallery