Step-by-step guide on how to use PhotoSwipe in Angular 4+ project
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Step-by-step guide and a simple demo on how to use PhotoSwipe in Angular 4+ project


  • No tests has been made on angular 2+ project, but instructions should be the same

  • If you have any question, consult the demo project or open an issue

  • Demo project include a reusable PhotoSwipe wrapper in the form of an angular 2+ component


  1. Create a new angular 2+ project. If you are using Angular CLI, just run this command in command line:

       ng new YOUR_PROJECT_NAME
  2. Install PhotoSwipe via NPM by running this command:

        npm install photoswipe
  3. In your component, import photoSwipe:

        import PhotoSwipe from 'photoswipe';
        import PhotoSwipeUI_Default from 'photoswipe/dist/photoswipe-ui-default';
  4. To open a gallery, simply initialize the PhotoSwipe() class, then call the .init() function, ie.

    <a (click)="onClick()" href="#">Open Slideshow</a>
            // Build gallery images array
            images = [
                { src: '', w: 600, h: 400 },
                { src: '', w: 800, h: 600 },
                // ...
            // define options (if needed)
            const options = {
                // optionName: 'option value'
                // for example:
                index: 0 // start at first slide
            // Initializes and opens PhotoSwipe
            const gallery = new PhotoSwipe(this.photoSwipe.nativeElement, PhotoSwipeUI_Default, images, options);
  5. Include PhotoSwipe css and js files via CDN:

        <!-- PhotoSwipe -->
        <link rel="stylesheet" href="" />
        <!-- Skin CSS file (styling of UI - buttons, caption, etc.)
        In the folder of skin CSS file there are also:
        - .png and .svg icons sprite,
        - preloader.gif (for browsers that do not support CSS animations) -->
        <link rel="stylesheet" href="" />
        <!-- photoswipe - Core JS file -->
        <script src=""></script>
        <!-- photoswipe - UI JS file -->
        <script src=""></script>

That's all! Cheers!