Gallery✨ Premium

Magnifying Glass

A round lens follows the mouse, a finger or the arrow keys and shows your own image magnified twice, high-resolution file included.

JSBackground

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

A printmaking studio's shop — the etching read line by line — Magnifying Glass example 1

① A printmaking studio's shop — the etching read line by line

WhenIn the Atelier Vernadoux shop, a restrike of an etching of an ancient temple (print 12/30) fills the left column; on the right, the price and the “Add to basket” and “Framing” buttons. The buyer moves the lens over the fluted columns and the engraved caption.
WhyBuying a print online means judging how fine the lines are without holding it: the lens gives that close look without leaving the page, while the whole etching stays in view.
Settingsdata-zoom="2.5", --mgl-width: 300px, --mgl-ratio: 4/3, --mgl-ring: 2px solid #2a241d (the etching's ink), frame edged with 6 px of white like a mount; .mgl-label caption removed.
Nature park trail map — reading the small names — Magnifying Glass example 2

② Nature park trail map — reading the small names

WhenThe Orvellane Massif topographic map fills the full width under the header and the “Download the map (PDF)” button. The hiker passes the lens over a hut or a trail variant to read its name and the summit heights.
WhyA map you can read whole at web-page size would be illegible; the lens keeps the overview and gives detail on demand, with a mouse or with a finger on a tablet.
Settings--mgl-width: 100%, --mgl-ratio: 540/316, --mgl-radius: 0, larger lens --mgl-size: 130px, data-zoom="2.5"; legend laid on top with pointer-events: none.
Scanned lease in a tenant portal — square lens on the keyboard — Magnifying Glass example 3

③ Scanned lease in a tenant portal — square lens on the keyboard

WhenIn the Domicelle portal, a preview of page 2 of the lease fits in a small thumbnail next to the document list and the “Sign the amendment” button. The tenant moves through it with the arrow keys to reread clause 7 on notice.
WhyA thumbnail is enough to recognise the document; the square lens, which matches lines of text, lets you reread a clause without opening the PDF. The scene shows the keyboard path: the frame has focus and receives the arrow keys.
Settings--mgl-shape: 4px (square lens), --mgl-size: 92px, --mgl-ring: 2px solid #3b5bdb, data-zoom="3", --mgl-width: 180px, --mgl-ratio: 4/3. In the capture, the scene focuses the frame and sends it the arrow keys the code listens for.

How it works

The .mgl-frame holds a real <img class="mgl-image"> tag and an empty disc, .mgl-lens. When the lens opens, the script uses the image itself as its background, or the file named in data-zoom-src if you supply a larger one. Swap the photo in the HTML and the lens follows: nothing is copied into the JavaScript.

On every move, the script redoes the object-fit: cover crop (same scale, same offset as the visible photo), multiplies it by data-zoom (2 by default) and positions the background so the target point sits in the middle of the disc. The lens may overflow the frame; the frame's rounded edge clips it cleanly.

The script finds every .fx-0180-root on the page and wires each one separately: two magnifiers on one page do not interfere, and pasting the script twice breaks nothing. The frame takes the available width up to --mgl-width (280 px) and keeps the shape set by --mgl-ratio.

Accessibility

  • Keyboard: the frame takes Tab focus and the lens opens in the middle (then, next times, where it was last); arrow keys move it by 12 px (48 px with Shift) and Escape closes it.
  • Touch: putting a finger down opens the lens there, dragging moves it, lifting the finger closes it, a single tap included. The frame blocks page scrolling during the gesture (touch-action: none); the page scrolls from the rest of the screen.
  • Screen readers: the frame is a group named by its aria-label and the image keeps its alt text; the lens and caption are hidden (aria-hidden), since they show nothing more than the image.
  • Reduced motion: under prefers-reduced-motion: reduce, the lens appears without a fade; it still follows the pointer, because the user is the one moving it.

Browser compatibility

Pointer Events, object-fit, aspect-ratio and about 3.5 KB of JavaScript, no dependency. Measured in Chromium 151, Firefox 153 and WebKit 26.5: lens over a red image swapped in by the buyer (the lens shows the red), two independent copies, script pasted twice without error, Tab and arrow keys, a real finger at 390 px (Chromium), no overflow.

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 image shows on its own, without a lens. Before Safari 15 and Chrome 88 (no aspect-ratio), the frame takes the height of the image itself; the zoom stays exact because it is computed from the frame's real size.

The code

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

index.html — structure
<div class="fx-0180-root">
  <div class="mgl-frame" tabindex="0" role="group" aria-label="Magnifier: hover the image, drag a finger or use the arrow keys" data-zoom="2">
    <img class="mgl-image" src="your-photo.jpg" data-zoom-src="your-photo-large.jpg" alt="Photo description">
    <span class="mgl-label" aria-hidden="true">Move Mouse</span>
    <div class="mgl-lens" aria-hidden="true"></div>
  </div>
</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 .mgl-image) violet grid pattern (inline SVG) Put in your photo and its alt text. Add data-zoom-src on the same tag so the lens shows a larger, sharper file than the displayed image (same framing).
data-zoom (on .mgl-frame) 2 Magnification inside the lens. 3 to 4 for printed text or a map, 1.5 for a product photo.
--mgl-size 100px Lens diameter (or side).
--mgl-shape 50% Lens rounding: 50% for a disc, 0 or a few pixels for a square lens.
--mgl-ring 3px solid #fff Lens border, to match your brand.
--mgl-width · --mgl-ratio · --mgl-radius 280px · 7 / 5 · 0.75rem Maximum frame width (it shrinks on small screens), proportions and rounding. 100% for a full-width image.
.mgl-label caption “Move Mouse” Text laid in the middle of the image. Delete the <span> on a real photo.

FAQ

Yes. The script reads the image from the <img> tag (or data-zoom-src) when the lens opens. If you change the photo by script, the lens follows as soon as the new image has loaded.
The lens enlarges the displayed file. A 560 px photo shown at 280 px holds a zoom of 2 without loss; beyond that, supply a larger file in data-zoom-src.
Set --mgl-shape: 0 (or 4px to soften the corners) on the root. The zoom maths stay the same; only the disc's shape changes.