How to Add Lottie Animations to a Streamlit App
Lottie animations are JSON-defined vector animations that stay sharp at any size and weigh far less than a GIF. The streamlit-lottie package renders them in an app: install it, load the JSON from a URL or a file, and drop it in like any other widget.
Where to find animations
Every Lottie animation is a JSON file, so it loads like any other data in Python. LottieFiles has a large library of free animations; each one can be downloaded as a JSON file or used straight from its URL.

Install the package
The streamlit-lottie package adds the st_lottie component to Streamlit. Install it in your terminal:
pip install streamlit-lottie
Load an animation
An animation can come from a JSON file saved on your drive or from its URL on LottieFiles. The script needs these imports for both ways:
import json
import requests
import streamlit as st
from streamlit_lottie import st_lottie
json reads local files, requests downloads from the web, and st_lottie displays the animation.
To load an animation from the web, this function downloads the JSON and returns None if the request fails:
def load_lottieurl(url: str):
r = requests.get(url)
if r.status_code != 200:
return None
return r.json()
For a JSON file on your drive, a second function opens and parses it:
def load_lottiefile(filepath: str):
with open(filepath, "r") as f:
return json.load(f)
Show the animation
Both loaders are called at the top of the script, and each animation is displayed with its own st_lottie call:
lottie_coding = load_lottiefile("lottiefiles/coding.json")
lottie_hello = load_lottieurl("https://assets9.lottiefiles.com/packages/lf20_M9p23l.json")
st.title("Include Lottie Files in Streamlit")
st_lottie(
lottie_coding,
speed=1,
reverse=False,
loop=True,
quality="low", # medium ; high
height=None,
width=None,
key=None,
)
st_lottie(lottie_hello, key="hello")
- lottie_coding and lottie_hello are the JSON objects returned by the two loaders: one from a local file, one from a URL.
- The first call spells out the optional arguments, so you can see what you can change: playback speed, direction, looping, quality (low, medium or high) and the size. The second call uses the defaults.
- The video also set
renderer="svg". streamlit-lottie 0.0.5, the current release, removed that argument and raises a TypeError if you pass it, so the code above leaves it out. - Give every call a unique
keywhen you show more than one animation.
Start the app with streamlit run app.py, using the name of your script. If the URL animation is missing, open the URL in your browser to check that it still returns JSON. A local copy of the file does not depend on LottieFiles being reachable.
You can see a Lottie animation in a full project in the personal website I built in Streamlit, and for a CSS-only effect there is the snowflake animation.
