Skip to main content
Login

Sign in to access your account

Image Popup Viewer - National Design System

The image popup viewer opens a thumbnail full screen, with zoom, pan and gallery navigation

Overview

The image popup viewer (IPV) shows the full image of a thumbnail over the page. A click on any image with nds-ipv-thumbnail opens the viewer. The page holds only the thumbnails, each with an optional card and caption. The script builds the viewer: the full image, the zoom and close buttons, the arrows, a counter and a control list.

Pick another component when:

  • the image needs text, a form or buttons next to it: Modal
  • the images slide inside the page: Swiper

Markup

Preview
Mud-brick palace reflected in rainwater
Heritage Palace
Riyadh skyline at night
Riyadh at Night
A man in traditional dress among old stone walls
Foundation Day
<div class="nds-grid" style="--max-col:3;--mid-col:2;--min-col:1;"> <div> <div class="nds-ipv-image-card nds-image"> <img src="../docs-assets/img/home_hero_bg_sm.webp" data-ipv-full="../docs-assets/img/home_hero_bg.webp" alt="Mud-brick palace reflected in rainwater" class="nds-ipv-thumbnail"> </div> <div class="nds-ipv-image-title">Heritage Palace</div> </div> <div> <div class="nds-ipv-image-card nds-image"> <img src="../assets/img/riyadhcenter.webp" data-ipv-full="../assets/img/riyadhcenter.webp" alt="Riyadh skyline at night" class="nds-ipv-thumbnail"> </div> <div class="nds-ipv-image-title">Riyadh at Night</div> </div> <div> <div class="nds-ipv-image-card nds-image"> <img src="../docs-assets/events/foundation_day/Hero_thumb.webp" data-ipv-full="../docs-assets/events/foundation_day/Hero_bg.webp" alt="A man in traditional dress among old stone walls" class="nds-ipv-thumbnail"> </div> <div class="nds-ipv-image-title">Foundation Day</div> </div> </div>

Built-in Features

  • Auto-initialization

    The viewer starts on any page that has an nds-ipv-thumbnail. A thumbnail added later opens on a click with no call, and NDS.Ipv.init() lets Tab reach it. The viewer itself is built on the first open, so a page where nobody opens an image carries none of it.

  • Multi-input Zoom

    The mouse wheel zooms toward the pointer, and a pinch zooms toward the middle of the two fingers. The zoom buttons zoom by 1.5×. Zoom runs from 10% to 1000%, and a label shows the current value.

  • Drag to Pan

    Drag the image with the mouse or one finger to move it. A double-click or the reset button returns it to 100% in the center.

  • Gallery Navigation

    The arrow buttons show the image of the previous or next thumbnail on the page, and a counter shows the position. With one thumbnail on the page, the arrows and the counter are hidden.

  • Keyboard Controls

    The script adds tabindex="0" and role="button" to each thumbnail that has none. Tab reaches a thumbnail, and Enter or Space opens it. The viewer's keys are in the Keyboard table of the API.

  • Distraction-free Mode

    The eye button hides the other buttons, the arrows, the counter, the zoom label and the control list. The eye button stays, to bring them back.

  • Adaptive Image Loading

    The page loads the small thumbnail. The viewer loads the full image from data-ipv-full only when it opens, and shows a spinner until the image arrives.

  • Accessible Dialog

    The viewer is a modal dialog. Focus moves to its close button and stays inside the viewer. On close, focus returns to the thumbnail that opened it.

  • Localized Controls

    The button labels and the control list follow the page language. The English is in the script, and the Arabic in the ipv section of assets/i18n/ar.json.

  • Phone Layout

    On phones the buttons sit closer to the edge, and the control list is hidden.

Best Practices

  • Use the viewer for images people inspect: photos, maps, plans and scans. Do not use it for decorative images.
  • Put data-ipv-full on every thumbnail, with the URL of a large image. Without it, the viewer shows the thumbnail, which blurs when zoomed.
  • Keep thumbnails small, about 400px wide.
  • Put nds-image on each .nds-ipv-image-card, so the tiles share one shape. Leave it off for your own look: nds-ipv-thumbnail adds no style.
  • Write alt on every thumbnail. The viewer copies it to the full image, and it names the thumbnail for screen readers.
  • In a gallery, put a nds-ipv-image-title under each image, so people know what it shows before they open it.
  • For more than one gallery on a page, give each thumbnail a data-ipv-gallery name. The arrows page through the thumbnails with the same name, in page order. Thumbnails without a name form one gallery together.
  • Do not add your own click handler to a thumbnail. The viewer already opens on a click, Enter and Space.
  • Do not open a modal while the viewer is open. The modal opens on top of the viewer.

API

Classes

Class Element Effect
nds-ipv-thumbnail <img> Opens the viewer on a click. It does not size the image: your own styles stay as written. Required
nds-ipv-image-card the thumbnail’s parent Holds the zoom badge. With nds-image, it crops the thumbnail to one shape: see Image. Optional: a thumbnail without it works the same
nds-zoom-badge .nds-ipv-image-card Shows a magnifier in the bottom start corner
nds-ipv-image-title an element after the card A caption under the image. Optional

Data Attributes

Attribute Element Effect
data-ipv-full img.nds-ipv-thumbnail The URL of the image the viewer loads
data-src img.nds-ipv-thumbnail The viewer loads this URL when the image has no data-ipv-full. With neither, it loads the image’s src
data-ipv-gallery img.nds-ipv-thumbnail A gallery name. The arrows and the counter cover only the thumbnails with the same name

Keyboard

Key Effect
Enter, Space Opens the viewer on the focused thumbnail
Escape Closes the viewer
+ or =, - Zooms in or out by 1.5×
0 Resets the zoom and the position
H Does what the eye button does
Left, Right Moves to the image on that side of the screen
Tab Moves between the viewer’s buttons

JavaScript

The NDS.Ipv script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.

One viewer serves the whole page. The methods below drive it. The viewer fires no events.

Method Effect
NDS.Ipv.init() Starts the viewer and gives thumbnails added since the last call tabindex and role. The loader calls it when the page has a thumbnail. Call it after you add thumbnails
NDS.Ipv.open(img) Opens the viewer on that thumbnail
NDS.Ipv.close() Closes the viewer and returns focus to the thumbnail
NDS.Ipv.prev(), NDS.Ipv.next() Moves to the previous or the next thumbnail in its gallery
NDS.Ipv.resetZoom() Resets the zoom and the position
NDS.Ipv.toggleControls() Does what the eye button does
NDS.Ipv.destroy() Removes the viewer and every listener it added. NDS.Ipv.init() starts a new one

The full API is in the banner of _js/nds-ipv.js.

NDS.Ipv.open(document.querySelector('.nds-ipv-thumbnail')); // After you add thumbnails to the page NDS.Ipv.init();
Last Modified Date: 01/11/2026 - 05:15 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks