Theming
dotLottie theming is a powerful feature that allows you to customize your Lottie animations by changing animated properties such as colors, sizes, and more. This guide explains how theming works in dotLottie and how you can apply themes to your animations.
What is dotLottie?
Before diving into theming, it’s essential to understand what dotLottie is. dotLottie is a packaging format for Lottie animations that makes it easy to bundle, share, and use animations across various platforms. A dotLottie file is essentially a zip file containing your animation files (in JSON format) and a manifest.json
file. It can also include a themes folder for theming purposes.
How Theming Works
Theming in dotLottie involves several key steps:
-
Exposing Animated Properties for Theming: You must first expose the properties you wish to theme in your Lottie animation by adding a slot ID to them. This makes them accessible for overriding through theming.
-
Creating a Theme File: Next, you create a JSON theme file that specifies new values for the properties you exposed. Each property is identified using the slot ID, and the new values are defined within this file.
-
Bundling Themes with Animations: Using the dotLottie-js, you bundle the theme file(s) with your Lottie animations into a single dotLottie file. This step involves specifying which animations the themes apply to.
Step 1: Expose Properties in Your Lottie Animation
To theme a property, it must first be marked for theming in the animation file by assigning a slot ID. Below is an example of how a color property can be exposed by adding a sid
(slot ID) to it in the Lottie JSON:
You may refer to the Lottie documentation for more information on the structure of Lottie animations.
Step 2: Create a Theme File
Once properties are exposed, you can define new values in a theme file. Here’s an example of a theme file changing the previously exposed color:
The
p
object contains the new property values. In this case, it changes the color to a light green forball_color
and a white forbackground_color
.
Step 3: Bundle Themes with Animations
You can use the dotLottie-js library to bundle your animations and themes into a dotLottie file. Here’s an example of how to add a theme to a dotLottie and apply it to an animation:
The created .lottie file will contain the animation and theme added, ready for use in your projects.
The manifest.json
contains the information from our theme assignment:
Applying Themes Using dotlottie-web Player
dotLottie-web is a javascript library that allows you to play and control Lottie animations on the web. It also supports theming, enabling you to apply themes to your animations dynamically.
This allows for easy theme switching with JavaScript:
This simple setup enables you to dynamically apply or remove themes from your animations with user interaction.
You can also use dotlottie-ios and dotlottie-android to apply themes to your animations on mobile platforms.