---
title: "MazLazyImg"
description: "MazLazyImg is a standalone component to display images and svgs with lazy loading"
package: "maz-ui"
url: "https://maz-ui.com/components/maz-lazy-img"
---

# MazLazyImg

> MazLazyImg is a standalone component to display images and svgs with lazy loading

- Package: `maz-ui`
- Import: `import MazLazyImg from 'maz-ui/components/MazLazyImg'`
- Nuxt: auto-imported by `@maz-ui/nuxt`, no import needed in a Nuxt app
- Web: https://maz-ui.com/components/maz-lazy-img

> Before use it, you should install the MazUi plugin in your project, follow instructions in [Getting Started](../guide/getting-started.md)

```vue
<script setup lang="ts">
import MazLazyImg from 'maz-ui/components/MazLazyImg'
</script>

<template>
  <MazLazyImg src="https://placedog.net/1000/1000" block />
</template>
```

**Tip: Performance**

`MazLazyImg` relies on the [`vLazyImg`](../directives/lazy-img.md) directive, whose `IntersectionObserver`s are pooled and shared across every instance - rendering many images (galleries, lists, avatars) stays cheap.

## Responsive sources

Pass an object with `sources` to serve different images depending on the media query (like a native `<picture>`).

```vue
<template>
  <MazLazyImg
    :src="{
      sources: [
        { srcset: 'https://placedog.net/600/400', media: '(max-width: 600px)' },
        { srcset: 'https://placedog.net/1500/1000', media: '(min-width: 601px)' },
      ],
    }"
    block
  />
</template>
```

## Image height full

By default the image is displayed with `width: 100%`. Enable `image-height-full` to fill the **height** instead: the image keeps its aspect ratio, fills 100% of the height and overflows/crops horizontally. Handy for wide images or SVGs inside a fixed-height container.

```vue
<template>
  <div style="height: 200px;">
    <MazLazyImg image-height-full src="https://placedog.net/1500/1000" />
  </div>
</template>
```

## Fallback on error

Provide `fallback-src` to swap the image when it fails to load.

```vue
<template>
  <MazLazyImg
    src="https://broken-link-image-src.example"
    fallback-src="https://placedog.net/500/500"
    block
  />
</template>
```

## Without loader

Hide the spinner shown while the image is loading with `hide-loader`.

```vue
<template>
  <MazLazyImg src="https://placedog.net/1000/1000" hide-loader block />
</template>
```

## MazLazyImg API

`import MazLazyImg from 'maz-ui/components/MazLazyImg'`

### Props

- `src` (`MazImage | null`): The source of the image.
- `alt` (`string`): The alt of the image.
- `hide-loader` (`boolean`): Remove the loader.
- `observer-once` (`boolean`, default: `true`): Remove the observer once the image is loaded.
- `load-once` (`boolean`): Remove the observer once the image is loaded.
- `image-height-full` (`boolean`): Make the image height full.
- `observer-options` (`{ root?: HTMLElement | null | undefined; threshold: number; rootMargin?: string | undefined; }`): The options of the observer.
- `fallback-src` (`string`): The fallback src to replace the src on loading error.
- `img-class` (`ClassValue`): The classes of the image element.
- `block` (`boolean`): The image will be displayed in full width.

### Events

- `@intersecting` (payload: `el: Element`): Emitted when the image is intersecting
- `@loading` (payload: `el: Element`): Emitted when the image is loading
- `@loaded` (payload: `el: Element`): Emitted when the image is loaded
- `@error` (payload: `el: Element`): Emitted when the image is in error

### Slots

- `#default`
