Custom triggers

Compose a zoom button with your own label, styles, and markup using <ImageZoom.Root>, <ImageZoom.Trigger>, and <ImageZoom.Image>.

custom-trigger-photo.tsx
Ocean sunset
Press Enter or Space to zoom. Click, press Escape, or scroll to close.

Compose the button

Put the image and button inside the same <ImageZoom.Root>. They can be siblings, so the button can sit beside or below the image:

tsx
import * as ImageZoom from '@/components/ui/image-zoom'

export function Photo() {
  return (
    <ImageZoom.Root>
      <ImageZoom.Image src="/photo.jpg" alt="Ocean sunset" />
      <ImageZoom.Trigger aria-label="View photo: ocean sunset">
        View photo
      </ImageZoom.Trigger>
    </ImageZoom.Root>
  )
}

The button's accessible name includes its visible “View photo” label and identifies the image. Keep other buttons and links outside the trigger.

Style the trigger

The example places the button in a caption row below the image. Use className on <ImageZoom.Trigger> to style the button independently. The Code view includes the complete stylesheet.