Add a Snowflake Animation to Your Streamlit Web App
The snowflake effect is CSS rather than a Streamlit component: a keyframe animation moves the flakes down the page, and the stylesheet is injected into the app with st.markdown. Size, speed and how many flakes fall are all adjustable from that CSS.

In the demo app the snow falls over a population pyramid of Japan, drawn to look like a Christmas tree. I build that chart type step by step in an interactive population pyramid with Plotly.
The CSS
Each snowflake is a small element with the class snowflake. Two keyframe animations move it: one drops it from above the screen to the bottom, the other shakes it 80 pixels sideways and back. Save the stylesheet as style/style.css in your project.
/* customizable snowflake styling */
.snowflake {
color: #FFF;
font-size: 1em;
font-family: Arial;
text-shadow: 0 0 1px #000;
}
@-webkit-keyframes snowflakes-fall{0%{top:-10%}100%{top:100%}}@-webkit-keyframes snowflakes-shake{0%{-webkit-transform:translateX(0px);transform:translateX(0px)}50%{-webkit-transform:translateX(80px);transform:translateX(80px)}100%{-webkit-transform:translateX(0px);transform:translateX(0px)}}@keyframes snowflakes-fall{0%{top:-10%}100%{top:100%}}@keyframes snowflakes-shake{0%{transform:translateX(0px)}50%{transform:translateX(80px)}100%{transform:translateX(0px)}}.snowflake{position:fixed;top:-10%;z-index:9999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default;-webkit-animation-name:snowflakes-fall,snowflakes-shake;-webkit-animation-duration:10s,3s;-webkit-animation-timing-function:linear,ease-in-out;-webkit-animation-iteration-count:infinite,infinite;-webkit-animation-play-state:running,running;animation-name:snowflakes-fall,snowflakes-shake;animation-duration:10s,3s;animation-timing-function:linear,ease-in-out;animation-iteration-count:infinite,infinite;animation-play-state:running,running}.snowflake:nth-of-type(0){left:1%;-webkit-animation-delay:0s,0s;animation-delay:0s,0s}.snowflake:nth-of-type(1){left:10%;-webkit-animation-delay:1s,1s;animation-delay:1s,1s}.snowflake:nth-of-type(2){left:20%;-webkit-animation-delay:6s,.5s;animation-delay:6s,.5s}.snowflake:nth-of-type(3){left:30%;-webkit-animation-delay:4s,2s;animation-delay:4s,2s}.snowflake:nth-of-type(4){left:40%;-webkit-animation-delay:2s,2s;animation-delay:2s,2s}.snowflake:nth-of-type(5){left:50%;-webkit-animation-delay:8s,3s;animation-delay:8s,3s}.snowflake:nth-of-type(6){left:60%;-webkit-animation-delay:6s,2s;animation-delay:6s,2s}.snowflake:nth-of-type(7){left:70%;-webkit-animation-delay:2.5s,1s;animation-delay:2.5s,1s}.snowflake:nth-of-type(8){left:80%;-webkit-animation-delay:1s,0s;animation-delay:1s,0s}.snowflake:nth-of-type(9){left:90%;-webkit-animation-delay:3s,1.5s;animation-delay:3s,1.5s}
/* [OPTIONAL] hide streamlit branding */
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
The last three rules are optional. They hide Streamlit’s menu, footer and header so the snow is the only decoration on the page.
Add it to the app
Read the stylesheet, inject it with st.markdown, then write a few elements with the snowflake class. The CSS takes over from there and animates every element that carries the class.
import streamlit as st
def local_css(file_name):
with open(file_name) as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
local_css("style/style.css")
animation_symbol = "❄"
st.markdown(
f"""
<div class="snowflake">{animation_symbol}</div>
<div class="snowflake">{animation_symbol}</div>
<div class="snowflake">{animation_symbol}</div>
""",
unsafe_allow_html=True,
)
Each element is one flake, so more copies mean more snow. Run the app with streamlit run and the flakes start falling as soon as the page loads. The same trick of styling elements with your own classes is what I build on in styling a Streamlit app with custom CSS.
Adjust size, speed and count
Everything you would want to change sits in the CSS file. The first .snowflake block controls the look, the animation-duration values control the speed, and the nth-of-type rules decide where each flake starts and when it begins to fall.
| To change | Edit this |
|---|---|
| Size | font-size in the first .snowflake block (1em by default) |
| Color | color in the same block (#FFF), plus text-shadow, which keeps white flakes visible on a white page |
| Fall speed | the first value of animation-duration (10s); a lower number falls faster |
| Sideways sway | the second value of animation-duration (3s) and the 80px in snowflakes-shake |
| Symbol | animation_symbol in the Python code; any emoji or character works |
| Number of flakes | the number of snowflake elements you write with st.markdown |
Change the same value in both the -webkit- rules and the plain rules, or older browsers keep the old setting. The nth-of-type rules define starting positions for flakes one to nine (the nth-of-type(0) rule never matches, because counting starts at 1). A tenth flake has no position or delay of its own, so add a rule for it if you write more than nine.
For animations that are more than falling characters, Lottie animations are the next step up.
