Skip to content

Product Detail with Image Zoom Lens

Tailwind CSS product detail section with a round magnifier lens that zooms the photo on hover or arrow keys, plus adjustable 2x to 4x levels.

Also known as: image magnifier, product photo zoom, magnifying glass hover, product gallery zoom lens

Product Detail with Image Zoom Lens live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A product detail section built with Tailwind CSS where a round magnifier lens follows the cursor over the product photo and shows that spot at 2×, 3× or 4× magnification. Next to the image sit the title, rating, sale price, color swatches and cart buttons, so it drops straight into an online store product page.

How it works

The root is section.izl-product, a two-column grid from the md breakpoint that stacks on phones. The photo lives in .izl-stage, a focusable box with a fixed aspect-[4/3] ratio and overflow-hidden. Inside it are the img (object-cover), the .izl-lens circle and the .izl-hint badge.

On DOMContentLoaded the script sets the lens background-image to the high-resolution URL in data-izl-src (falling back to the visible image). On pointerenter and pointermove it converts the cursor position into a 0 to 1 value inside the stage, adds izl-active to the stage and calls render(). That function moves the lens with transform, sets background-size to the stage size multiplied by the zoom factor and shifts background-position so the magnified pixel under the cursor sits in the lens center. pointerleave removes izl-active, which fades the lens out and the hint back in through style.css.

The buttons with data-izl-level change the zoom factor live and update aria-pressed, which Tailwind's aria-pressed: variant uses to highlight the active level. A resize listener recalculates sizes. Without JavaScript the page shows a normal product photo.

Customization

  • data-izl-zoom on .izl-stage: the starting magnification, e.g. 2.5. Keep the matching level button aria-pressed="true".
  • data-izl-src: point to a larger version of the same photo with the same crop ratio; a sharper source makes high zoom levels look crisp.
  • h-40 w-40 on .izl-lens: a bigger lens (h-56 w-56) shows more area; rounded-xl instead of rounded-full gives a square loupe.
  • data-izl-level buttons: add or remove levels such as 1.5 or 5.
  • aspect-[4/3] on .izl-stage: match your photo ratio, e.g. aspect-square, and request both image URLs with that ratio.
  • bg-stone-100 on the section and bg-stone-900 on the buttons: retheme the page palette.

Use cases

  • Online stores: shoppers hover over a product photo and inspect fabric or finish in a round magnifier lens
  • Product detail pages: title, rating, sale price, color swatches and cart buttons sit beside the zoomable image
  • Keyboard users: arrow keys move the lens so people without a mouse can zoom too
  • Photo-heavy catalogs: visitors switch between 2x, 3x and 4x magnification to check small details

Accessibility

.izl-stage has tabindex="0", role="group" and an aria-describedby hint, so keyboard users can focus it: the lens appears in the center, arrow keys move it (Shift for larger steps), Enter or Space toggles it and Escape hides it. The lens and hint are aria-hidden because they are purely visual; the product photo keeps a descriptive alt. Zoom buttons expose aria-pressed, color swatches are real radio inputs in a fieldset with a legend, and every control shows a focus ring. Fades are disabled under prefers-reduced-motion.

Usage notes

The demo photo comes from Unsplash; replace both URLs with your own product images. touch-action: pan-y keeps vertical page scrolling on phones while a horizontal drag moves the lens. Multiple product sections can share a page because each .izl-product is initialized on its own; rename the izl-color radio name per copy.

Product Detail with Image Zoom Lens at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Product Details
License
Free for personal and commercial use

Questions about this template

Can I use the Product Detail with Image Zoom Lens code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Product Detail with Image Zoom Lens – free Tailwind CSS product detail page template
Product Detail with Image Zoom Lens · free Tailwind CSS product detail page template

More Product Details

Bootstrap Product Page – free Bootstrap 5 product detail page template

Bootstrap Product Page

Bootstrap 5 product details page with image gallery, color and size pickers, quantity stepper, and tabs for description, specifications and customer reviews.

Product Detail with Gallery – free Tailwind CSS product detail page template

Product Detail with Gallery

Dark Tailwind CSS product page section with a thumbnail image gallery, finish options, quantity stepper and add to cart button with loading state.

Frequently Bought Together Section for Shopify – free Shopify product detail page template

Frequently Bought Together Section for Shopify

Shopify section that shows the current product with up to 3 picked products, checkboxes, variant selects, a live total and one button that adds everything checked to the cart.

Sticky Add to Cart Bar for Shopify – free Shopify product detail page template

Sticky Add to Cart Bar for Shopify

Shopify section: a bar fixed to the bottom of product pages that appears once the main add-to-cart button scrolls away, with image, price, variant select and a real product form.