Home / Getting Started / Photo Galleries
Photo Galleries
Turn a set of photos on a page into a gallery: a grid of thumbnails that
opens a full-screen viewer on the published site. It takes a few lines of
_config.yml and plain HTML in the page. New in 0.15.0.
What it is and when to use it
The gallery is a web component, a custom HTML tag (<wikidown-gallery>)
that a small script brings to life in the browser. Wikidown has one built
into its starter theme. Use it for photo sets on a venue, event, product or
project page.
The page keeps ordinary HTML, so nothing is lost where scripts don't run. On github.com, in the web editor's preview, and with JavaScript off, readers see the photos with their alt text, and each one links to the full image.
1. Turn it on
Add this to the wiki's _config.yml under wikidown: (run
wikidown pages first if the wiki has no _config.yml):
wikidown:
web_components:
modules:
- /assets/components/wikidown-gallery.js
styles:
- /assets/components/wikidown-gallery.css
tags:
- wikidown-gallery
You don't need to copy any files: both come with the starter theme.
2. Add the gallery to a page
Each photo is a <figure>: a link to the full-size image around a
thumbnail, and an optional caption. With one size of each photo, use the
same file for both.
<wikidown-gallery label="Photos from the opening" columns="2">
<figure>
<a href="../.attachments/opening/rabbits.jpg" data-width="1000" data-height="894">
<img src="../.attachments/opening/rabbits.jpg" alt="Two copper rabbit sculptures" width="1000" height="894" loading="lazy">
</a>
<figcaption>Copper rabbits by Jud Turner</figcaption>
</figure>
<figure>
<a href="../.attachments/opening/highland-cow.jpg" data-width="1000" data-height="750">
<img src="../.attachments/opening/highland-cow.jpg" alt="A shaggy Highland cow sculpture" width="1000" height="750" loading="lazy">
</a>
</figure>
</wikidown-gallery>
Write the page with the CLI as usual (wikidown edit or write-section),
or ask your agent: "Turn the photos on the Oblivion Gallery page into a
wikidown-gallery." The agent skill knows the markup.
3. Check and preview
wikidown check-links
wikidown export-html --output _site --clean
check-links checks every href and src in the gallery. Preview the
site through a local web server, such as npx serve _site or
dotnet serve -d _site. Opening the .html file straight from disk
doesn't run the gallery's script.
What readers get
- A grid of thumbnails, cropped to the same shape,
columnswide on large screens and two or more across on phones. - Click or tap a thumbnail to open the full image, with the caption (or the alt text) and a "3 / 11" counter.
- Previous and next buttons, the arrow keys, and Escape or a click outside the photo to close. Focus goes back to the photo you were viewing.
Tips
- Alt text on every image. Screen readers use it, and the viewer shows it when a photo has no caption.
data-widthanddata-heighton the link give the viewer the full image's size, so the layout doesn't jump while it loads.- Smaller thumbnails load faster. If your photos are large, add a
smaller copy for each
<img>and keep the link on the full-size file. - Blank lines. With
wikidown-galleryundertags:, blank lines inside the block are fine on the published site. GitHub still splits the block at a blank line, so leave them out if the page should read well there too. - Markdown doesn't work inside the block; it is raw HTML. Put text before or after it.
Want swipe and zoom?
Point the config at another implementation. Web
Components shows how to load Web
Awesome's <wa-lightbox> from a CDN, which adds swipe, pinch zoom and a
thumbnail strip, and how to load any other component library.