Image
An image with aspect ratio, hover effects, optional lightbox and optional NuxtImg.
Component
Props
| Props | Required | Default | Type |
|---|---|---|---|
src | true | — | string |
alt | — | '' | string |
caption | — | — | string |
showCaption | — | false | boolean |
captionPlacement | — | ImageCaptionPlacement.BELOW | ImageCaptionPlacement |
width | — | — | number |
height | — | — | number |
aspectRatio | — | — | AspectRatio |
fit | — | ImageFit.COVER | ImageFit |
hoverEffect | — | ImageHoverEffect.NONE | ImageHoverEffect |
hoverSplitDirection | — | ImageHoverSplitDirection.DIAGONAL | ImageHoverSplitDirection |
hasHoverIcon | — | true | boolean |
hoverIcon | — | — | string |
useLightbox | — | false | boolean |
lightboxSrc | — | — | string |
isClickable | — | false | boolean |
useNuxtImg | — | false | boolean |
sizes | — | — | string |
densities | — | — | string |
loading | — | ImageLoading.LAZY | ImageLoading |
containerClass | — | — | string |
wrapperClass | — | — | string |
imageClass | — | — | string |
captionClass | — | — | string |
openAriaLabel | — | — | string |
Usage
src
Sets the image source.
<template>
<Image src="/images/river.jpg" alt="River between mountains" />
</template>
alt
Sets the alternative text. Redundant wording such as "Image of" is removed with cleanImageAlt, since screen readers already announce an image.
<template>
<Image src="/images/river.jpg" alt="Image of a river between mountains" />
</template>
caption
Sets the image caption. It is always shown in the lightbox, and on the page only when showCaption is on.
<template>
<Image src="/images/river.jpg" caption="River valley" />
</template>
showCaption
Shows the caption on the page, at the position set by captionPlacement.
<template>
<Image src="/images/river.jpg" caption="River valley" showCaption />
</template>
captionPlacement
Sets where the caption is displayed via the ImageCaptionPlacement enum.
<template>
<Image
src="/images/river.jpg"
caption="River valley"
showCaption
:captionPlacement="ImageCaptionPlacement.OVERLAY_BOTTOM"
/>
</template>
Options
| Value | Description |
|---|---|
NONE | none |
BELOW | below |
OVERLAY_BOTTOM | overlayBottom |
HOVER | hover |
width
Sets the intrinsic width of the image. It helps the browser reserve space and avoid layout shifts.
<template>
<Image src="/images/river.jpg" :width="1200" :height="800" />
</template>
height
Sets the intrinsic height of the image. Use it together with width.
<template>
<Image src="/images/river.jpg" :width="1200" :height="800" />
</template>
aspectRatio
Crops the image to a fixed ratio via the AspectRatio enum. Without it, the image keeps its natural proportions.
<template>
<Image src="/images/river.jpg" :aspectRatio="AspectRatio.AR_16_9" />
</template>
Options
| Value | Description |
|---|---|
AR_1_1 | 1:1 |
AR_4_3 | 4:3 |
AR_3_2 | 3:2 |
AR_16_9 | 16:9 |
AR_3_4 | 3:4 |
AR_4_5 | 4:5 |
AR_2_3 | 2:3 |
fit
Sets how the image fills the box defined by aspectRatio via the ImageFit enum.
<template>
<Image
src="/images/logo.png"
:aspectRatio="AspectRatio.AR_1_1"
:fit="ImageFit.CONTAIN"
/>
</template>
Options
| Value | Description |
|---|---|
COVER | cover |
CONTAIN | contain |
hoverEffect
Sets the effect shown when you hover the image via the ImageHoverEffect enum.
<template>
<Image src="/images/river.jpg" :hoverEffect="ImageHoverEffect.GRAYSCALE" />
</template>
Options
| Value | Description |
|---|---|
NONE | none |
ZOOM_IN | zoomIn |
ZOOM_OUT | zoomOut |
OVERLAY | overlay |
BLUR | blur |
GRAYSCALE | grayscale |
SPLIT_ZOOM | splitZoom |
hoverSplitDirection
Sets the direction in which the two chromatic layers separate with the SPLIT_ZOOM effect.
<template>
<Image
src="/images/river.jpg"
:hoverEffect="ImageHoverEffect.SPLIT_ZOOM"
:hoverSplitDirection="ImageHoverSplitDirection.HORIZONTAL"
/>
</template>
Options
| Value | Description |
|---|---|
DIAGONAL | diagonal |
HORIZONTAL | horizontal |
VERTICAL | vertical |
hasHoverIcon
Shows an icon in the center of the OVERLAY effect.
<template>
<Image
src="/images/river.jpg"
:hoverEffect="ImageHoverEffect.OVERLAY"
:hasHoverIcon="false"
/>
</template>
hoverIcon
Sets the icon of the OVERLAY effect. By default it is a magnifier when useLightbox is on, and an eye otherwise.
<template>
<Image
src="/images/river.jpg"
:hoverEffect="ImageHoverEffect.OVERLAY"
hoverIcon="mdi:heart"
/>
</template>
useLightbox
Opens the image in a Lightbox when you click it. The image becomes a button and the pointer shows a zoom cursor.
<template>
<Image src="/images/river.jpg" useLightbox />
</template>
lightboxSrc
Sets a larger source for the lightbox, so the thumbnail can stay light.
<template>
<Image
src="/images/river-small.jpg"
lightboxSrc="/images/river-large.jpg"
useLightbox
/>
</template>
isClickable
Makes the image a button that emits click without opening a lightbox. It is always true when useLightbox is on.
<template>
<Image src="/images/river.jpg" isClickable @click="handleClick" />
</template>
useNuxtImg
Renders the image with NuxtImg from @nuxt/image instead of a plain img. It requires the @nuxt/image module in your app, and enables sizes and densities.
<template>
<Image src="/images/river.jpg" useNuxtImg />
</template>
sizes
Sets the sizes attribute passed to NuxtImg. It only applies with useNuxtImg.
<template>
<Image src="/images/river.jpg" useNuxtImg sizes="100vw md:50vw" />
</template>
densities
Sets the densities attribute passed to NuxtImg. It only applies with useNuxtImg.
<template>
<Image src="/images/river.jpg" useNuxtImg densities="x1 x2" />
</template>
loading
Sets how the browser loads the image via the ImageLoading enum. Use EAGER for images above the fold.
<template>
<Image src="/images/hero.jpg" :loading="ImageLoading.EAGER" />
</template>
Options
| Value | Description |
|---|---|
LAZY | lazy |
EAGER | eager |
containerClass
Adds custom classes to the root figure element.
<template>
<Image src="/images/river.jpg" containerClass="max-w-md" />
</template>
wrapperClass
Adds custom classes to the element that wraps the image, where the aspect ratio and rounded corners live.
<template>
<Image src="/images/river.jpg" wrapperClass="rounded-xl" />
</template>
imageClass
Adds custom classes to the img element.
<template>
<Image src="/images/river.jpg" imageClass="object-top" />
</template>
captionClass
Adds custom classes to the caption.
<template>
<Image src="/images/river.jpg" caption="River valley" showCaption captionClass="text-center" />
</template>
openAriaLabel
Sets the accessible name of the button when the image is clickable. Falls back to useDSConfig().lightbox.openImageText().
<template>
<Image src="/images/river.jpg" useLightbox openAriaLabel="Enlarge photo" />
</template>
Accessibility
Always provide an alt text, or leave it empty when the image is decorative. A clickable image is a native button, so it works with Enter and Space and shows a focus outline. The chromatic layers of SPLIT_ZOOM are hidden from assistive technology. Hover animations are disabled for users who prefer reduced motion.
Emits
| Value | Description |
|---|---|
@click | Emits the click event when the image is clickable, either with `useLightbox` or `isClickable`. |
Example
<template>
<Image src="/images/river.jpg" isClickable @click="handleClick" />
</template>
<script setup lang="ts">
const handleClick = () => {
console.log('Image clicked')
}
</script>