Image zoom

Image Zoom is a web component that provides a zoom experience. Click an image to expand it to fill the viewport with a smooth scale and fade animation. Clicking the zoomed image, the overlay, or the close button dismisses the view.

Examples Default

Click the image to zoom in.

<dap-ds-image-zoom>
<img
  src="/img/components/apples.webp"
  alt="Apples in a bowl"
  style={{width: 280, height: 180, objectFit: 'cover', display: 'block', borderRadius: 8}} />
</dap-ds-image-zoom>
Disabled

When isDisabled is set, the expand icon is hidden and clicking the image does nothing.

<dap-ds-image-zoom isDisabled>
<img
  src="/img/components/apples.webp"
  alt="Apples in a bowl"
  style={{width: 280, height: 180, objectFit: 'cover', display: 'block', borderRadius: 8}} />
</dap-ds-image-zoom>
Zoom Margin

Use zoomMargin to keep a pixel gap between the zoomed image and the viewport edges.

<dap-ds-image-zoom zoomMargin="48">
<img
  src="/img/components/apples.webp"
  alt="Apples in a bowl"
  style={{width: 280, height: 180, objectFit: 'cover', display: 'block', borderRadius: 8}} />
</dap-ds-image-zoom>
High-Quality Zoom Source

Provide a zoomSrc to display a higher-resolution image when zoomed, while keeping a smaller thumbnail in the page.

<dap-ds-image-zoom zoomSrc="/img/components/apples.webp">
<img
  src="/img/components/apples.webp"
  alt="Apples in a bowl"
  style={{width: 140, height: 100, objectFit: 'cover', display: 'block', borderRadius: 6}} />
</dap-ds-image-zoom>
Custom Accessibility Labels

Override the default accessible labels with expandButtonAriaLabel and unzoomButtonAriaLabel.

<dap-ds-image-zoom
expandButtonAriaLabel="Kép nagyítása"
unzoomButtonAriaLabel="Kép kicsinyítése">
<img
  src="/img/components/apples.webp"
  alt="Almák egy tálban"
  style={{width: 280, height: 180, objectFit: 'cover', display: 'block', borderRadius: 8}} />
</dap-ds-image-zoom>
Accessibility
  • The trigger wrapper has role="button" and tabindex="0", so it is reachable by keyboard.
  • Press Enter or Space to zoom; press Escape to close.
  • Focus moves to the close button when the dialog opens and returns to the trigger when it closes.
  • The expand and close buttons have configurable aria-label values via expandButtonAriaLabel and unzoomButtonAriaLabel.
  • The component uses a native <dialog> element, which is automatically exposed to assistive technologies as a modal.
Importing
import { DapDSImageZoom } from 'dap-design-system'
Importing React
import { DapDSImageZoomReact } from 'dap-design-system/react'
Tree-Shakeable Imports

For optimal bundle sizes, use the tree-shakeable import syntax:

import { DapDSImageZoom } from 'dap-design-system/components'
Attributes
PropertyTypeDefaultDescription
openbooleanfalseThe open/zoomed state. Can be used for controlled mode.
isDisabledbooleanfalseDisables zoom functionality.
zoomMarginnumber0Margin in pixels from viewport edges when zoomed. Default is 0.
expandButtonAriaLabelstringnullAccessible label for the zoom trigger. Default is 'Expand image'.
unzoomButtonAriaLabelstringnullAccessible label for the unzoom button. Default is 'Minimize image'.
canSwipeToUnzoombooleantrueEnables swipe gesture to close when zoomed. Default is true.
swipeToUnzoomThresholdnumber10Swipe distance in pixels required to trigger unzoom. Default is 10.
zoomSrcstringURL of a higher quality image to display when zoomed. Falls back to the slotted image src.
hideButtonsbooleanfalseHides the expand and unzoom buttons. Default is false.
zoomButtonVariantButtonVariant'primary'
Slots
NameDescription
(default)The image or content element to zoom. Should contain an <img> element.
Events
Event NameDescriptionType
dds-zoomFires when the image is about to zoom. Cancelable via event.preventDefault().CustomEvent
dds-unzoomFires after the image has unzoomed.CustomEvent
CSS Parts
Part NameDescription
triggerThe zoom trigger wrapper element.
dialogThe zoom dialog element.
overlayThe backdrop overlay element.
zoomed-imageThe zoomed image element.
unzoom-buttonThe button to close the zoomed view.
expand-buttonThe button to expand the image.
expand-button-baseThe base of the expand button.
expand-button-contentThe content of the expand button.
unzoom-button-baseThe base of the unzoom button.
unzoom-button-contentThe content of the unzoom button.
expand-button-iconThe icon of the expand button.
unzoom-button-iconThe icon of the unzoom button.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-image-zoom::part(trigger) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-image-zoom::part(trigger),
.my-custom-dap-ds-image-zoom::part(dialog) {
  /* Shared styles */
}

Example usage:

<dap-ds-image-zoom class="my-custom-dap-ds-image-zoom">
  Image zoom
</dap-ds-image-zoom>
.my-custom-dap-ds-image-zoom::part(trigger) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-image-zoom-overlay-bgOverlay background color (default: rgba(0, 0, 0, 0.8)).
--dds-image-zoom-transition-speedAnimation duration (default: 300ms).
--dds-image-zoom-transition-timingAnimation timing function (default: var(--dds-easing-ease-in-out, ease-in-out)).
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-image-zoom
  style="--dds-image-zoom-overlay-bg: value; --dds-image-zoom-transition-speed: value;">
  Image zoom
</dap-ds-image-zoom>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-image-zoom {
  --dds-image-zoom-overlay-bg: value;
  --dds-image-zoom-transition-speed: value;
  --dds-image-zoom-transition-timing: value;
}
<dap-ds-image-zoom class="my-custom-dap-ds-image-zoom">
  Image zoom
</dap-ds-image-zoom>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-image-zoom {
  --dds-image-zoom-overlay-bg: value;
  --dds-image-zoom-transition-speed: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.