# Using Lottie Animations in eBooks

*By Naail Abdul Rahman · August 20, 2020*

How to add Lottie animations to eBooks as an exciting way to enrich a reader's experience.

---

We’re always looking for new and creative ways to use Lottie animations. One such avenue we have been experimenting with is using them in eBooks.

![](https://assets-blog.lottiefiles.dev/2021/04/ezgif.com-gif-maker--5--1.gif)

_An ePub with an embedded Lottie, as viewed in the Kobo Reader app._

eBooks are an exciting way to publish your digital content. Being digital also enables them to be much more than simple text and images - they can contain interactive elements, videos, audio and fun little animations - enabling you to provide your readers with a much richer experience.

There are many competing standards and formats for eBbooks, however, the most popular and de-facto reference standard for them is [EPUB](https://www.w3.org/publishing/epub3/).

> “EPUB® defines a distribution and interchange format for digital publications and documents. The EPUB format provides a means of representing, packaging and encoding structured and semantically enhanced Web content—including HTML, CSS, SVG and other resources—for distribution in a single-file container.”

For the purposes of this document, we will be exploring this format. Since authoring an eBook is similar to authoring a website, the process for adding a Lottie animation into it is very similar. Unfortunately, a lot of the tools in the market for authoring eBooks don’t typically have scripting support, so our approach for now is a little more hands on.

## **Adding a simple Lottie Animation to your EPUB**

A sample project following this guide is available on [GitHub](https://github.com/LottieFiles/labs-epub3).

The structure of an EPUB is basically a number of HTML files, their supporting CSS files and assets, and a package.opf file describing the make-up of the package and its content.

**Create your project**

Start off a new project or open up your existing project. There are plenty of guides on how to get started with creating an EPUB. TheBookeDesigner has a nice introductory [guide](https://www.thebookdesigner.com/2015/07/4-ways-to-create-an-epub-ebook/), and the IDPF hosts a collection of [sample projects](https://idpf.github.io/epub3-samples/) for reference.

**Add the Lottie library to your project**

Download the Lottie javascript library from [https://cdnjs.com/libraries/lottie-web](https://cdnjs.com/libraries/lottie-web) into a folder called “scripts” at the root of your EPUB project. You will need to declare it in your package.opf file as well (see below)

Once you have the library in your project, add a reference to it in the .html file where you want your animations to appear.

It should look something like this

```html
<head>
       ...
       <script type="text/javascript" src="script/lottie.min.js"></script>
   </head>
```

**Add animations**

Now you need some animations to add into your project. You can check out our collection of quality animations at [LottieFiles](https://lottiefiles.com/featured) to find awesome animations created by the community. You can also check out our [LottieFiles Marketplace](https://lottiefiles.com/marketplace) for premium animations, or even [hire an animator](https://lottiefiles.com/marketplace/animators) to bring your vision to life.

Once you have your animation, place the animation .json files in a new folder named “lottie” in the root of your project. Once that’s done, add a placeholder to host the animation. You can apply CSS stylings as you wish. The example below is set up so that the placeholder image is shown, in case the reader software doesn’t support this functionality and doesn’t fire the script.

```html
<div id="canvas" style="height: 12em;">
           <img src="cover.jpg" style="height: 12em;"></img>
       </div>
```

And finally the javascript to initiate the animation.

```html
<script type="text/javascript">
 
           // clear out the placeholder
           var elem = document.getElementById("canvas");
           elem.innerHTML = "";
 
           // load the animation
           lottie.loadAnimation({
               container: elem,
               renderer: 'svg',
               loop: true,
               autoplay: true,
               path: 'lottie/newton.json',
           });
       </script>
```

There are more configuration options you can play around with in Lottie, that is covered in the official [Lottie Documentation](https://airbnb.io/lottie/#/web).

**Declare your assets in the manifest**

The EPUB specifications requires all the assets that you just added be declared in the package.opf manifest.

```xml
   <manifest>
       ...
       <item id="c1" media-type="application/xhtml+xml" href="c1.xhtml" properties="scripted"/>
       <item id="cover" media-type="image/jpeg" href="cover.jpg"/>
       <item id="js" href="script/lottie.min.js" media-type="text/javascript"/>  
       <item id="anim" media-type="application/json" href="lottie/newton.json" />
   </manifest>
```

Pay particular attention to _**properties=”scripted”**_ declared for the html file which hosts the animation.

**Pack it up, and ship it**

You can now use your favourite eBook software or any other tool to package the project into your final eBook. We prefer using the official [EPUB Check](https://github.com/w3c/epubcheck) tool as it also runs helpful validations.

## **Adding Interactivity**

As highlighted above, where Lottie animations work, it also opens up your eBook for exciting interactive features.

We recommend having a look at our LottieFiles Interactivity library. You can follow [the guide](https://lottiefiles.com/interactivity) for implementing scrolling based effects for Lotties.

## **What about animated SVGs?**

SVGs (Scalable Vector Graphics), the web standard for vector graphics, has animation capabilities and can also work in a similar way, although the [EPUB specifications](https://www.w3.org/AudioVideo/ebook/) specifically mention that animation elements in SVGs are not part of the current standard, and as a consequence validation tools are likely to complain.

However, they do sometimes work (as with Lottie, with limitations) and we have included one in [our sample](https://github.com/LottieFiles/labs-epub3).

## **Download Sample**

You can check out our sample EPUB included in our [GitHub repository](https://github.com/LottieFiles/labs-epub3), or download it directly [here](https://github.com/LottieFiles/labs-epub3/raw/master/sample.epub).

## **Limitations**

Rendering Lottie depends heavily on the use of Javascript, and this functionality is limited to readers that support the full use of the HTML Canvas and Javascript. Per our testing, Apple Books on iPhones, iPads and Macs provide the best support.

![](https://static.lottiefiles.com/blog_media/jvhgWunucjR7Lx86ZqoPTdWYmLNrdXXlz4mEHaHM.png)

If you test it out with other readers, please let us know if it worked for you and we’ll update the results.

Browse free Lottie animations

---

## Related Articles

- [Lottie/dotLottie vs. GIF: Choosing the Right Animation for You](/blog/working-with-lottie-animations/lottie-vs-gif)
- [Introducing Motion Copilot 2.0 in Lottie Creator](/blog/working-with-lottie-animations/introducing-motion-copilot-on-lottie-creator)
- [Lottie Creator 2.0: A Powerful Web-Based Lottie Animation Tool](/blog/working-with-lottie-animations/lottie-creator-a-powerful-web-based-lottie-animation-tool)
- [Introducing Motion System: One Workflow for Animation That Actually Ships](/blog/working-with-lottie-animations/introducing-motion-system-one-workflow-for-animation-that-actually-ships)