SuperModal.js

SuperModal.js an image modal that gets out of the way

Galleries, zoom, swipe, a slideshow and a grid view for the images on your page. No dependencies, 10 KB of JavaScript gzipped.

Get v1.1.1
Green and red polar lights Neon light trails in Munich Orange reflective architecture Spiral staircase Desktop purple neon light
Lights on the roof Twisting building facade Coding workstation Swiss Cheese Architecture Water, Light and long shutter speeds

Click any frame. On a phone, swipe the strips sideways.

What it does

You write plain links to your images. SuperModal turns them into a full-screen viewer that works the same with a mouse, a keyboard or a finger.

Try it

Each demo shows the markup or the call that produced it. The event log under the JavaScript demo records every demo on this page.

A gallery in the light theme

Options can travel with the markup: the first link's JSON sets the light theme for the whole gallery. Press G for the grid view.

Boat Ship Boats Ships Cargo Harbor Bridge River Fishingboat Ship Sunset Sea Catalina Harbor
<a href="images/harbour/world-04.webp"
   data-supermodal='{"group":"harbour","theme":"light","title":"Boat Ship"}'>
  <img src="images/harbour/world-04-480x270.webp" alt="Boat Ship">
</a>
<a href="images/harbour/world-09.webp"
   data-supermodal='{"group":"harbour","title":"Boats Ships"}'>
  <img src="images/harbour/world-09-480x270.webp" alt="Boats Ships">
</a>
<!-- ...more links in the "harbour" group -->

A single image

A link without a group opens on its own: no counter, arrows or strip.

Twisting building facade
<a href="tower.webp" data-supermodal
   data-title="Twisting building facade"
   data-caption="Photo by Pavel Fertikh, CC0.">
  <img src="tower-960.webp" alt="Twisting building facade">
</a>

Images without links

A blog post as a CMS writes it: plain images, no links, no extra markup. One call makes them a gallery, with the captions and the sharper copies from srcset.

Cargo Harbor
Cargo Harbor. Photo by Leeroy, CC0.
Bridge River
Bridge River. Photo by Pablo Garcia Saldaña, CC0.
Sunset Sea
Sunset Sea. Photo by Sergei Gussev, CC0.
<!-- the post, as the CMS writes it -->
<figure>
  <img src="bridge-480.webp" alt="Bridge River"
       srcset="bridge-480.webp 480w, bridge.webp 960w">
  <figcaption>Bridge River.</figcaption>
</figure>

<script>
document.addEventListener('DOMContentLoaded', () => {
  SuperModal.bind('#post img'); // or an array of selectors
});
</script>

Loading the script later

When SuperModal loads late (async, on scroll, or through a plugin that delays scripts), queue the code that needs it. This page queues its call before the script tag; it runs once the script has loaded. The images it enhanced are styled through [data-supermodal-bound]: hover one.

Boat Ship
Boat Ship. Photo by Leeroy, CC0.
Fishingboat Ship
Fishingboat Ship. Photo by Leeroy, CC0.
Catalina Harbor
Catalina Harbor. Photo by Jay Mantri, CC0.

Waiting for SuperModal…

<!-- anywhere on the page, before or after the script -->
<script>
window.SuperModalReady = window.SuperModalReady || [];
window.SuperModalReady.push(function (SM) {
  SM.bind('#late img');
});
</script>

<script src="supermodal.min.js" async></script>

<style>
/* only the images SuperModal enhanced */
#late img[data-supermodal-bound]:hover {
  outline: 3px solid #d42a1f;
  outline-offset: 3px;
}
</style>

WordPress galleries

WordPress galleries often link each image to its attachment page, a page of its own, so a click leaves the post. A few lines point the links at the images instead and make each gallery a gallery of its own, captions included. Ctrl or Cmd + click still opens a new tab.

[gallery] shortcode

Gallery block

<!-- as WordPress writes it -->
<figure class="gallery-item">
  <a href="/2026/11/harbour/boat/">
    <img src="boat-480x270.webp" alt="Boat Ship">
  </a>
  <figcaption>Boat Ship.</figcaption>
</figure>

<script>
(window.SuperModalReady =
  window.SuperModalReady || []).push(function () {
  document.querySelectorAll('.gallery, .wp-block-gallery')
    .forEach(function (gallery, i) {
      gallery.querySelectorAll('a > img').forEach(function (img) {
        var a = img.parentNode;
        var item = a.closest('.gallery-item, .wp-block-image');
        var cap = item &&
          item.querySelector('.gallery-caption, figcaption');
        // boat-480x270.webp → boat.webp, the original upload
        a.href = img.src.replace(/-\d+x\d+(\.\w+)$/, '$1');
        a.setAttribute('data-supermodal', 'gallery-' + i);
        if (cap) a.setAttribute('data-caption', cap.innerHTML);
      });
    });
});
</script>

From JavaScript

Open any list of images, with or without links on the page. This one starts the slideshow.

SuperModal.open([
  { src: 'polar-lights.webp', title: 'Green and red polar lights' },
  { src: 'light-trails.webp', title: 'Neon light trails in Munich' },
  { src: 'spiral-stairs.webp', title: 'Spiral staircase' }
], 0, { autostart: true, interval: 3 });

document.addEventListener('supermodal:change', (e) => {
  console.log(e.detail.index, e.detail.item.title);
});

A page in the modal

Frame mode opens a page of your site in an iframe with the same look: a picker, a form, a video.

SuperModal.frame('picker.html', { title: 'Choose an image' });

// in picker.html, when the visitor is done:
parent.SuperModal.close();

Markup written for another lightbox

These links were written for FancyBox. With compat mode on (this page turns it on), SuperModal opens them as they are.

Water, Light and long shutter speeds Desktop purple neon light Coding workstation
<script>window.SuperModalDefaults = { compat: true };</script>

<a href="night.webp" data-fancybox="old"
   data-caption="Written for FancyBox">
  <img src="night-960.webp" alt="">
</a>

Install

Two files, no build step. Every release keeps its own address, so a page that loads dist/1.1.1/ never changes under you; dist/latest/ always has the newest release.

<link rel="stylesheet" href="https://supermodal.nuevvo.com/dist/1.1.1/supermodal.min.css">
<script src="https://supermodal.nuevvo.com/dist/1.1.1/supermodal.min.js" defer></script>

Or download supermodal.min.js and supermodal.min.css from the dist folder on GitHub and host them yourself. The readable sources are next to them.

Then add data-supermodal to the links of your images. Use the same name for the links of one gallery:

<a href="photos/beach.jpg" data-supermodal="holiday"
   data-title="The beach" data-caption="Day one, <b>early</b> morning">
  <img src="photos/beach-small.jpg" alt="The beach">
</a>
<a href="photos/harbour.jpg" data-supermodal="holiday">
  <img src="photos/harbour-small.jpg" alt="The harbour">
</a>

That's all. Links added later, for example by infinite scrolling, work too: SuperModal listens for clicks on the whole page.

If the script loads late, with async, on scroll or through a plugin that delays scripts, queue the code that needs it. It runs as soon as SuperModal has loaded, or at once if it already has:

<script>
(window.SuperModalReady = window.SuperModalReady || []).push(function (SM) {
  SM.bind('.entry-content img');
});
</script>

Reference

Everything SuperModal reads from your markup, the options, the JavaScript API, its events and the CSS variables you can change.

Markup

AttributeOnWhat it does
data-supermodala link

Opens the link's image in the modal. The value is a group name ("holiday"): links with the same name form a gallery. Leave it empty for a single image, or give JSON with any of group, title, caption, srcset, thumb, download, html and the gallery options below.

data-titlea linkTitle shown above the caption.
data-captiona linkCaption; HTML allowed (links, emphasis, lists) and cleaned. Without it, the link's title is used.
data-srcseta linkA srcset for the full-screen image, e.g. "a-960.webp 960w, a.webp 1920w".
data-thumba linkImage for the thumbnail strip and the grid view. Default: the link's <img>, else the image itself.
data-downloada linkShows a download button for this file.
data-supermodal-itemany elementJSON with a src and a group: an image that belongs to a gallery but has no link on the page. These come first in the gallery.
<template class="supermodal-html" data-supermodal-for="holiday">the pageExtra HTML shown under every image of that gallery, such as a credit line. Scripts in it are removed.
data-supermodal-boundset by SuperModalAdded to every element SuperModal.bind() enhanced (the images that open the modal) and removed by its unbind(). Style them with it, e.g. [data-supermodal-bound]:hover. Images added later get it when you call bind() again; style by its presence, not its value.
data-supermodal-gallerya containerCompat mode: groups links that only have another lightbox's class (.swipebox, .highslide...) per container instead of per page.

Options

Set them for the page with SuperModal.setDefaults(), or in window.SuperModalDefaults before the script loads. theme, thumbs, loop, autostart and interval can also be set per gallery, in the JSON of its first link, or per SuperModal.open() call.

OptionDefaultWhat it does
theme'dark''dark' or 'light'.
thumbstrueShows the thumbnail strip under the image.
looptrueGoes from the last image back to the first.
autostartfalseStarts the slideshow when the modal opens.
interval5Seconds per image in the slideshow.
compatfalseAlso opens links written for other lightboxes: data-fancybox, data-lightbox, Fresco, Strip, Lightview, Nivo, rel="prettyPhoto[…]", rel="lightbox[…]", Colorbox, Swipebox, Highslide, Magnific Popup. Only links to image files.
stringsEnglishButton labels and messages: close, prev, next, play, pause, zoom, grid, download, fullscreen, more, counter ('Image {i} of {n}'), loading, error.

JavaScript

MethodWhat it does
SuperModal.open(items, index, options)

Opens a gallery at index. items is a CSS selector, a list of links, or an array of objects with src and optionally srcset, thumb, title, caption, alt, download, html. options takes the options above and trigger, the element that gets the focus back on close. Returns false when there's nothing to show.

SuperModal.bind(selectors, options)

Opens the modal for the elements a selector, or an array of selectors, matches: usually images you can't add markup to, such as the images of a CMS post. All of them form one gallery, in page order, images added later included; options are the options above. An image in a link to an image file opens that file; an image in a link to a page keeps its link, and links with data-supermodal keep their own gallery. The caption comes from the image's <figcaption> or data-caption, and srcset and lazy loaders' data-src are used. Images without a link get keyboard access (Enter or Space). Call it again with the same selectors to refresh it after adding images. Returns a function that unbinds.

SuperModal.close()Closes the modal (and frame mode).
SuperModal.next(), prev(), goTo(index)Moves through the open gallery.
SuperModal.isOpen()Whether the modal is open.
SuperModal.frame(url, { title })Opens a page of your site in an iframe with the modal's look.
SuperModal.setDefaults(options)Changes the options for everything opened afterwards.
window.SuperModalReadyA queue for code that needs SuperModal when the script loads late: (window.SuperModalReady = window.SuperModalReady || []).push(function (SM) { … }). Queued functions run, in order, once the script has loaded; after that, push runs them at once.

Events

Dispatched on document; the details are in event.detail.

EventWhenDetail
supermodal:readyThe script has loaded (queued SuperModalReady code has run).the SuperModal object
supermodal:openThe modal opened.index, item, items
supermodal:changeAnother image is shown.index, item, items
supermodal:closeThe modal closed.index, item

Keyboard and gestures

InputWhat it does
Left and right arrows, swipe sidewaysPrevious and next image.
Home, EndFirst and last image.
SpaceStarts or pauses the slideshow.
Z, double click, double tap, pinch, Ctrl + wheelZooms in and out; drag to pan.
GShows or hides the grid view.
EscLeaves the zoom, the grid view or the phone menu first, then closes.
Swipe down, the Back buttonCloses.

Styling

Change any of these variables on .supermodal, or on .supermodal--light for the light theme only:

.supermodal {
    --sm-accent: #0a7cff;   /* active buttons, focus, slideshow progress */
    --sm-bg: rgba(16, 16, 18, .985);
    --sm-fg: #f2f2f2;
    --sm-muted: #a8a8ad;
    --sm-btn-bg: rgba(255, 255, 255, .08);
    --sm-btn-bg-hover: rgba(255, 255, 255, .18);
    --sm-font: inherit;
    --sm-font-size: 15px;
    --sm-bar-height: 52px;
    --sm-btn-size: 40px;
    --sm-stage-pad: 56px;   /* room for the arrows beside the image */
    --sm-thumb-size: 56px;
    --sm-grid-gap: 8px;
    --sm-radius: 4px;
    --sm-duration: .25s;
    --sm-easing: cubic-bezier(.2, .7, .2, 1);
}

Images enhanced by SuperModal.bind() carry a data-supermodal-bound attribute (with a zoom-in cursor by default), so you can style just those: .entry-content img[data-supermodal-bound]:hover { opacity: .9; }.

SuperModal works in the current versions of Chrome, Edge, Firefox and Safari, on desktops and phones.

What's new

Every release, in short. Each one keeps its own address under dist/, and every change is listed in the full changelog on GitHub.

v1.1.1December 7, 2026
latest

A new home

SuperModal.js is now a Nuevvo project, at supermodal.nuevvo.com. Still MIT licensed, with no changes to the code. Links to the old address keep working.

v1.1.0November 24, 2026

Images without links

One line of JavaScript turns images you can't add markup to, like the images of a WordPress post, into a gallery: SuperModal.bind().

  • One or more selectors: everything they match forms one gallery, in page order, images added later included.
  • Links are respected: an image linked to its full-size file opens that file; an image linked to a page keeps its link.
  • Captions and sharp copies come from the image's <figcaption> and srcset, and from lazy loaders' data-src.
  • Keyboard: images without a link open with Enter or Space, and the full-screen image keeps their alt text.
  • Late loading: code queued in window.SuperModalReady runs once the script loads, so it can load async, on scroll or through a plugin that delays scripts.
v1.0.0November 18, 2026

The first release

Galleries from plain links, zoom and pan, swipe, a slideshow, a grid view, responsive images and a real <dialog>, with no dependencies. Compat mode opens links written for other lightboxes.