Magnifier Glass Lens
A round glass lens that follows the pointer and magnifies the content under it; arrow keys move it too.
AI prompt
Product photograph of a round glass magnifier lens resting on a printed page of fine technical text, the text inside the lens enlarged three times with crisp edges and slight colour fringing at the rim, a thin silver ring around the glass, a soft white highlight arc at the upper left, shallow depth of field on the surrounding paper, neutral soft light. Negative: distorted lens, fingerprints, broken text, heavy vignette, extra objects. Reduced motion: static image with the lens in the middle.About this pattern
Definition
A loupe shows a zoomed copy of the content under a small round window. Cloning the content, scaling it and offsetting it so the point under the pointer sits in the lens centre is all it takes, plus a rim and a highlight to make it feel like glass.
Purpose & UX principles
- The clone must be positioned so that the pointer location maps to the centre of the lens: translate by lens radius minus pointer times zoom.
- Add a thin bright rim, a soft inner shadow and a small highlight arc for the glass feel.
- Useful for product images, maps, and charts with fine detail.
Interaction states
- A Zoom slider, pointer movement, drag and arrow keys.
Motion specification
- The lens follows the pointer directly with no easing, so it feels attached to the hand.
- Reduced motion: unaffected, because the movement is driven by the user.
Responsive behaviour
- On touch, drag the lens; also support arrow keys when the area is focused.
- Hide the real pointer inside the lens only if the lens is large.
Code
<div class="bx"><div class="sc" id="sc" tabindex="0" aria-label="Content area. Move the pointer or use arrow keys to move the lens"><div class="in" id="in"><b>Tiny details</b><p>Fine print, hairlines and small icons are easy to miss at normal size.</p><div class="dots"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div></div><div class="ls" id="ls"><div class="cl" id="cl"></div></div></div><label class="rw">Zoom <b id="zv">2.5x</b><input id="zm" type="range" min="15" max="40" value="25"></label></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sc{height:150px;border-radius:12px;position:relative;overflow:hidden;background:#fffefb;border:1px solid var(--line);touch-action:none;cursor:crosshair}
.in{position:absolute;left:0;top:0;padding:14px;font-size:12px;color:#333}.in b{display:block;font-size:20px;margin-bottom:4px;letter-spacing:-.02em}.in p{max-width:230px;line-height:1.4;color:#666}
.dots{display:flex;gap:6px;margin-top:10px}.dots i{width:10px;height:10px;border-radius:50%;background:#d98a63}.dots i:nth-child(2n){background:#3f68c9}
.ls{position:absolute;width:70px;height:70px;border-radius:50%;overflow:hidden;pointer-events:none;box-shadow:0 0 0 3px #d9dce1,0 0 0 4px rgba(0,0,0,.18),0 8px 14px rgba(0,0,0,.25),inset 0 0 12px rgba(0,0,0,.25);background:#fffefb}
.cl{position:absolute;left:0;top:0;transform-origin:0 0}
.ls::after{content:"";position:absolute;left:12px;top:8px;width:26px;height:14px;border-radius:50%;background:linear-gradient(rgba(255,255,255,.7),rgba(255,255,255,0));transform:rotate(-30deg)}
.sc:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const sc=document.getElementById('sc'),inn=document.getElementById('in'),ls=document.getElementById('ls'),cl=document.getElementById('cl'),zm=document.getElementById('zm');let x=120,y=60;const R=35;
const clone=inn.cloneNode(true);clone.removeAttribute('id');clone.setAttribute('aria-hidden','true');cl.appendChild(clone);
function up(){const z=zm.value/10,w=sc.clientWidth,h=sc.clientHeight;x=Math.max(0,Math.min(w,x));y=Math.max(0,Math.min(h,y));ls.style.left=(x-R)+'px';ls.style.top=(y-R)+'px';cl.style.transform='translate('+(R-x*z)+'px,'+(R-y*z)+'px) scale('+z+')';document.getElementById('zv').textContent=z.toFixed(1)+'x';}
sc.addEventListener('pointermove',e=>{const r=sc.getBoundingClientRect();x=e.clientX-r.left;y=e.clientY-r.top;up();});
sc.addEventListener('keydown',e=>{const d={ArrowLeft:[-12,0],ArrowRight:[12,0],ArrowUp:[0,-12],ArrowDown:[0,12]}[e.key];if(d){e.preventDefault();x+=d[0];y+=d[1];up();}});
zm.addEventListener('input',up);up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Magnifier Glass Lens — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sc{height:150px;border-radius:12px;position:relative;overflow:hidden;background:#fffefb;border:1px solid var(--line);touch-action:none;cursor:crosshair}
.in{position:absolute;left:0;top:0;padding:14px;font-size:12px;color:#333}.in b{display:block;font-size:20px;margin-bottom:4px;letter-spacing:-.02em}.in p{max-width:230px;line-height:1.4;color:#666}
.dots{display:flex;gap:6px;margin-top:10px}.dots i{width:10px;height:10px;border-radius:50%;background:#d98a63}.dots i:nth-child(2n){background:#3f68c9}
.ls{position:absolute;width:70px;height:70px;border-radius:50%;overflow:hidden;pointer-events:none;box-shadow:0 0 0 3px #d9dce1,0 0 0 4px rgba(0,0,0,.18),0 8px 14px rgba(0,0,0,.25),inset 0 0 12px rgba(0,0,0,.25);background:#fffefb}
.cl{position:absolute;left:0;top:0;transform-origin:0 0}
.ls::after{content:"";position:absolute;left:12px;top:8px;width:26px;height:14px;border-radius:50%;background:linear-gradient(rgba(255,255,255,.7),rgba(255,255,255,0));transform:rotate(-30deg)}
.sc:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="sc" id="sc" tabindex="0" aria-label="Content area. Move the pointer or use arrow keys to move the lens"><div class="in" id="in"><b>Tiny details</b><p>Fine print, hairlines and small icons are easy to miss at normal size.</p><div class="dots"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></div></div><div class="ls" id="ls"><div class="cl" id="cl"></div></div></div><label class="rw">Zoom <b id="zv">2.5x</b><input id="zm" type="range" min="15" max="40" value="25"></label></div>
</div>
<script>
const sc=document.getElementById('sc'),inn=document.getElementById('in'),ls=document.getElementById('ls'),cl=document.getElementById('cl'),zm=document.getElementById('zm');let x=120,y=60;const R=35;
const clone=inn.cloneNode(true);clone.removeAttribute('id');clone.setAttribute('aria-hidden','true');cl.appendChild(clone);
function up(){const z=zm.value/10,w=sc.clientWidth,h=sc.clientHeight;x=Math.max(0,Math.min(w,x));y=Math.max(0,Math.min(h,y));ls.style.left=(x-R)+'px';ls.style.top=(y-R)+'px';cl.style.transform='translate('+(R-x*z)+'px,'+(R-y*z)+'px) scale('+z+')';document.getElementById('zv').textContent=z.toFixed(1)+'x';}
sc.addEventListener('pointermove',e=>{const r=sc.getBoundingClientRect();x=e.clientX-r.left;y=e.clientY-r.top;up();});
sc.addEventListener('keydown',e=>{const d={ArrowLeft:[-12,0],ArrowRight:[12,0],ArrowUp:[0,-12],ArrowDown:[0,12]}[e.key];if(d){e.preventDefault();x+=d[0];y+=d[1];up();}});
zm.addEventListener('input',up);up();
</script>
</body></html>