Need private packages and team management tools?Check out npm Orgs. »


3.0.2 • Public • Published

Build Status npm GitHub release npm


Support Angular >=6.0.0



  • No other JS dependency. Just Angular

  • Use IntersectionObserver to determine the timing to load the image

  • Support image and picture

  • Preserve space to avoid dom reflow

  • Show small default loading image with fading transition

  • Load image directly for spider (SEO friendly) or non-supported browsers


npm install ngx-progressive-image-loader --save

Open your module file e.g app.module.ts and update imports array

import { NgxProgressiveImageLoaderModule, IImageLoaderOptions } from 'ngx-progressive-image-loader';
      // rootMargin must be specified in pixels or percent
      rootMargin: '30px',
      threshold: 0.1,
      // css filter
      filter: 'blur(3px) drop-shadow(0 0 0.75rem crimson)',
      // image width / height ratio for image holder
      imageRatio: 16 / 9,
      // loading image in placeholder. Can be URL or base64
        // tslint:disable-next-line:max-line-length

Add style to your global scss

@import '~ngx-progressive-image-loader/ngx-progressive-image-loader';
$scale: 0.5; // the scale of loading image in place holder 
@include progressive-image-loader($scale);


  • with img
  <ngx-image-placeholder> <!-- ngx-image-placeholder is optional -->
    <img [src]="'/assets/Avengers1.jpg'" alt="" ngxProgressiveImage>
  <img src="/assets/Avengers2.jpg" alt="" ngxProgressiveImage>
  • with img + srcset
  <img [src]="'/assets/Avengers6.jpg'" [srcset]="'/assets/Avengers6.jpg 800w,/assets/Avengers7.jpg 1366w'"
      size="(max-width: 1000px) 100vw, 100vw" ngxProgressiveImage>
  • with picture element
  <picture ngxProgressiveImage>
    <source [srcset]="'/assets/Avengers4.jpg'" media="(max-width: 1000px)">
    <source [srcset]="'/assets/Avengers5.jpg'" media="(min-width: 1000px)">
    <img [src]="'/assets/Avengers4.jpg'" alt="My default image">

Configuration for IImageLoaderOptions


  • root The element that is used as the viewport for checking visiblity of the target. Must be the ancestor of the target. Defaults to the browser viewport if not specified or if null.

  • rootMargin

    Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). The values can be percentages. This set of values serves to grow or shrink each side of the root element's bounding box before computing intersections. Defaults to all zeros.

  • threshold

    Either a single number or an array of numbers which indicate at what percentage of the target's visibility the observer's callback should be executed. If you only want to detect when visibility passes the 50% mark, you can use a value of 0.5. If you want the callback run every time visibility passes another 25%, you would specify the array [0, 0.25, 0.5, 0.75, 1]. The default is 0 (meaning as soon as even one pixel is visible, the callback will be run). A value of 1.0 means that the threshold isn't considered passed until every pixel is visible.

  • filter

    If you want to set more filter. It uses the input string as css filter.

  • placeholderImageSrc

    src for loading image. It works just like src, takes base64 or url.

  • imageRatio

    image width / height

For ngx-image-placeholder component, it takes

  • imageRatio

  • placeholderImageSrc

(after 3.0.0, you can set imageRatio and placeholderImageSrc directly on ngxProgressiveImage and spare ngx-image-placeholder layer)

For ngx-progressive-image-loader component, it takes

  • imageRatio

  • placeholderImageSrc

  • filter

For ngxProgressiveImage directive, (only for image or source elements)

  • imageRatio

  • placeholderImageSrc

  • noPlaceholder: boolean; default to false, set to true will skip image placeholder

Build project

npm i
npm run build

To run demo code locally

npm run start

Browser Compatibility

Browsers don't support Intersection Observer API will not work as expect. It will load images like old time.

Use pollyfill like below might make it work.

<script src=""></script>


  • Your commits conform to the conventions established here


Please ask your general questions at

Shoutouts 🙏

This project was generated with Angular CLI version 6.2.0 beta 02.

Kudos to the following authors: for detecting spider

And my wife and my child to let me work on a weekend for this.


npm i ngx-progressive-image-loader

Downloadsweekly downloads









last publish


  • avatar
Report a vulnerability