Gallery✨ Premium

Click to Zoom

A click, a tap or the Enter key enlarges your image twice at the chosen spot; a second click shows it whole again.

JSToggle

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Gallery has 44 effects, including 6 free. Explore the category →

3 usage examples

Nutrition table on a grocery product page — one click to read — Click to Zoom example 1

① Nutrition table on a grocery product page — one click to read

WhenOn the hazelnut and honey granola page at Drive Pomalinde, the nutrition label fits in a small thumbnail under the pack photo, next to the price per kilo and the “Add to cart” button. A click on the carbohydrates line enlarges it right there.
WhyOnly some shoppers need the table: a discreet thumbnail is enough, and zooming at the clicked point brings the wanted line straight into view.
Settings--czm-width: 110px, --czm-ratio: 26/30, --czm-radius: 6px, --czm-scale: 2.6; pill renamed “Zoom”, caption removed.
Wiring diagram in a thermostat's online manual — Click to Zoom example 2

② Wiring diagram in a thermostat's online manual

WhenIn the Thermivelle help centre, step 3 “Connect the wires” shows the thermostat-to-boiler diagram in a wide card, to the right of the step list. The installer clicks the boiler terminal block to read the letters R, C, W, Y, G and O/B.
WhyThe diagram must stay whole to understand the links, but the terminal letters are small: clicking the right spot enlarges that block without opening a new page.
Settings--czm-width: 100%, --czm-ratio: 420/280, --czm-radius: 10px, --czm-scale: 2.2; pill “Click to zoom”.
Mosaic at the top of a museum page — by touch and keyboard — Click to Zoom example 3

③ Mosaic at the top of a museum page — by touch and keyboard

WhenThe Castelvorne Museum opens its fish mosaic page on a full-width banner. A tap (or Enter) enlarges the tesserae, then the arrow keys follow the joints; a second tap brings back the whole view, above the text and the “Plan a visit” button.
WhyA mosaic is seen from afar, then up close: the banner gives the composition, the zoom shows the tesserae work. The scene plays a position-less activation (zoom on the centre) and the arrow keys, as a keyboard user would.
Settings--czm-width: 100%, --czm-ratio: 540/172, --czm-radius: 0, --czm-scale: 2.4. In the capture, the scene calls click() on the button and sends it arrow keys, as a keyboard user does.

How it works

The frame is a real <button class="czm-frame"> holding your <img class="czm-image">, an optional caption and the “Click to zoom” pill. On activation, the script toggles the is-zoomed class and the aria-pressed state; the CSS then applies scale(var(--czm-scale)) (2) over --czm-duration (0.4 s) and hides the pill.

With a mouse or a finger, the clicked point becomes the origin of the enlargement (transform-origin as a percentage): you zoom where you clicked. With Enter or Space, which have no position, the zoom starts from the centre; once enlarged, arrow keys shift the area by 10% and Escape returns to the whole view.

Each .fx-0183-root is wired separately, with no id: several clickable images on a page stay independent, and the script can be pasted twice without error.

Accessibility

  • Native button: the frame takes Tab focus and activates with Enter or Space; aria-pressed announces “pressed” while the image is enlarged. Its name comes from the image alt text and the pill.
  • Keyboard once zoomed: arrow keys move the view, Escape goes back. In Safari, Tab only reaches buttons when “Press Tab to highlight each item” is on (Option + Tab otherwise), as with any button.
  • Touch: a tap zooms at the touched point, a second tap goes back; touch-action: manipulation removes the double-tap delay without blocking scrolling.
  • Reduced motion: under prefers-reduced-motion: reduce, the image switches straight to the enlarged view and back, with no animation.

Browser compatibility

HTML button, CSS transforms, aspect-ratio and 2 KB of JavaScript, no dependency. Measured in Chromium 151, Firefox 153 and WebKit 26.5: zoom at the clicked point, two independent copies, script pasted twice without error, Enter then arrow keys, a real tap at 390 px (Chromium).

Chrome 88+✓ Full (measured)
Firefox 89+✓ Full (measured)
Safari 15+✓ Full (WebKit engine measured)
Edge 88+✓ Full (Chromium engine)
Mobile iOS 15+✓ Full (WebKit engine measured)
Android Chrome 88+✓ Full (Chromium engine)

Without JavaScript, the button shows the image without zoom. Without aspect-ratio, the frame takes the image's height.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0183-root">
  <button type="button" class="czm-frame" aria-pressed="false">
    <img class="czm-image" src="your-image.jpg" alt="Image description">
    <span class="czm-label" aria-hidden="true">Click Me</span>
    <span class="czm-hint">Click to zoom</span>
  </button>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Image (HTML — src of .czm-image) violet grid pattern (inline SVG) Your image and its alt, which also names the button. A file twice as wide as the frame stays sharp once enlarged.
--czm-scale 2 Enlargement after the click. 2.5 to 3 for small text.
--czm-duration 0.4s Duration of the zoom in and out.
--czm-width · --czm-ratio · --czm-radius 280px · 7 / 5 · 0.75rem Maximum width (the frame shrinks on small screens), proportions and rounding.
.czm-hint pill “Click to zoom” Prompt text, hidden once the image is enlarged; translate it or delete the <span>.
.czm-label caption “Click Me” Text centred on the image; remove it on a real photo.

FAQ

Yes with a mouse or a finger. On the keyboard, Enter or Space have no position: the zoom starts from the centre and the arrow keys then move the view.
No, it stays on the clicked point; click again to go back, then click elsewhere. For an image that follows the mouse continuously, use Pan Zoom.
No: the frame is already a button, and a button inside a link is invalid. Place the link next to it (title or a “View” button).