
CSS Pop In Animation: Keyframes, Bounce, Scroll and Modals
A pop in animation is the small thing that makes a button, card or popup feel like it actually arrived on the page instead of just appearing. I’ve been using some version of this one since 2012, and the CSS for it got a lot better in the last couple of years.
In this post, I’ll show you how to make a CSS pop in animation with @keyframes, then how to give it a springy bounce, trigger it on scroll, stagger it across a list, and use it for popups and toasts. I ran every example below in the browser before publishing it.
Let’s get into it.
The CSS Pop In Animation
Since you’re likely here for the code, here’s the full snippet:
@keyframes pop-in {
from {
opacity: 0;
transform: scale(0.5);
}
to {
opacity: 1;
transform: scale(1);
}
}
.pop-in {
animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
Add the class to any element and it pops in when the page loads:
<div class="card pop-in">Hello there</div>
That’s it. The rest of this post is about making it feel better and running it at the right moment.
How the Pop In Effect Works
The @keyframes rule describes two states. At the start (from, same as 0%) the element is invisible and half size. At the end (to, same as 100%) it’s fully visible at its normal size. The browser fills in everything between.
The animation shorthand on .pop-in sets four things:
pop-inis the name of the keyframes to run.0.4sis the duration. Somewhere between 0.2s and 0.5s feels snappy. Longer starts to feel slow.cubic-bezier(0.34, 1.56, 0.64, 1)is the easing. It’s what gives the pop, and I’ll explain it in the next section.bothis the fill mode. It holds thefromstate before the animation starts and keeps thetostate after it ends. You need this as soon as you add a delay, or the element shows at full size, vanishes, then pops in.
The starting scale controls how dramatic the pop is. scale(0.5) is a clear pop. scale(0.9) is a gentle settle that suits buttons and modals. scale(0) grows out of nothing, which looks great on small things like badges and dots.
CSS @keyframes Syntax
If you’re new to CSS keyframe animation, here’s the whole syntax in one example. A @keyframes rule names an animation and lists its steps. from and to are the same as 0% and 100%, and you can add any percentage between them.
@keyframes name {
0% { opacity: 0; transform: scale(0.5); }
60% { opacity: 1; transform: scale(1.1); }
100% { transform: scale(1); }
}
.element {
/* name | duration | easing | delay | iteration count | direction | fill mode */
animation: name 0.5s ease-out 0.1s 1 normal both;
}
The animation shorthand takes up to eight values. You only need the name and a duration; the rest have defaults (ease, no delay, plays once, normal direction, no fill mode). The first time value is always the duration and the second is the delay. If you’d rather spell it out, the longhand properties are animation-name, animation-duration, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, animation-fill-mode and animation-play-state.
A property you leave out of a keyframe animates between the nearest keyframes that do set it. At the start or end, the element’s own value fills in. In the example, 100% doesn’t set opacity, so it ends at the element’s normal opacity of 1.
Add a Bounce With Overshoot
A plain ease-out pop works, but it feels flat. Real objects overshoot a little and settle back. You can get that a few ways.
Use a cubic-bezier With Overshoot
This is what the main snippet uses. The 1.56 in the curve pushes the scale past 1 near the end, then it eases back down. You don’t need any extra keyframes:
.pop-in {
animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
Add a Middle Keyframe
If you want full control over how far it overshoots, add a step in the middle:
@keyframes pop-in-bounce {
0% { opacity: 0; transform: scale(0.5); }
60% { opacity: 1; transform: scale(1.1); }
100% { opacity: 1; transform: scale(1); }
}
.pop-in-bounce {
animation: pop-in-bounce 0.45s ease-out both;
}
Make It Springy With linear()
This is my favorite. The linear() easing function lets you plot a curve point by point, so you can make the element wobble like it’s on a spring. It overshoots, dips back under, and settles:
.pop-in-spring {
animation: pop-in 0.7s both;
animation-timing-function: linear(
0, 0.3 9%, 0.78 19%, 1.08 30%, 1.13 38%,
1.05 50%, 0.98 63%, 1.005 78%, 1
);
}
Each pair is a progress value and the point in the animation where it happens. Values above 1 are the overshoot. linear() works in Chrome 113, Firefox 112 and Safari 17.2 and later. Older browsers ignore that declaration and use the default ease, so nothing breaks.
One thing worth knowing: the overshoot only shows up on the scale. Opacity can’t go above 1, so the fade just finishes early, which is what you want anyway.
Pop In From a Direction
By default an element scales from its center. For a dropdown or tooltip, it looks better when it grows out of the thing that opened it. Change transform-origin:
.dropdown {
transform-origin: top left;
animation: pop-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
You can also slide while you scale by adding a translateY() to the start state:
@keyframes pop-in-up {
from {
opacity: 0;
transform: translateY(16px) scale(0.9);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
Stagger a Pop In Across a List
For a grid of cards or a list of items, popping them in one after another looks a lot nicer than all at once. The cleanest way is a custom property with each item’s position, and a delay calculated from it:
<ul class="pop-list">
<li style="--i: 0">One</li>
<li style="--i: 1">Two</li>
<li style="--i: 2">Three</li>
<li style="--i: 3">Four</li>
</ul>
.pop-list li {
animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
animation-delay: calc(var(--i, 0) * 60ms);
}
Each item waits 60ms longer than the one before it. This works for any number of items without writing a :nth-child() rule for each one. If you render the list with JavaScript or a template, set --i from the loop index.
Newer browsers can skip the inline style with sibling-index(), which returns the element’s position among its siblings, starting at 1. It’s in Chrome 138, Firefox 154 and Safari 26.2. Put it after the custom property version so older browsers keep working:
.pop-list li {
animation-delay: calc(var(--i, 0) * 60ms);
animation-delay: calc((sibling-index() - 1) * 60ms);
}
Browsers that don’t understand sibling-index() drop the second line and use the first.
Keep the total stagger short. With 30 items at 60ms each, the last one waits almost two seconds. For long lists, cap it with min(), like calc(min(var(--i, 0), 8) * 60ms).
Pop In on Scroll
A lot of people want elements to pop in as they scroll into view. There are two good ways to do it now.
Use Scroll-Driven Animations (No JavaScript)
animation-timeline: view() ties an animation to the element’s position in the viewport instead of to time. The element pops in as you scroll it into view:
@media (prefers-reduced-motion: no-preference) {
@supports (animation-timeline: view()) {
.pop-on-scroll {
animation: pop-in linear both;
animation-timeline: view();
animation-range: entry 10% cover 30%;
}
}
}
animation-range controls when it plays. entry 10% starts it once the element is a little way into the viewport, and cover 30% finishes it before it gets far up the screen.
Two gotchas. First, animation-timeline has to come after the animation shorthand, because the shorthand resets it. Second, the animation follows the scroll position, so it plays backwards when you scroll back up. Some people like that. If you want it to happen once, use the JavaScript version below.
Scroll-driven animations work in Chrome 115, Safari 26 and Firefox 159 and later. The @supports check means older browsers just show the element with no animation.
Use IntersectionObserver (Plays Once)
If you want the pop to play one time, or you need it in older browsers, use a few lines of JavaScript. It waits until the element is on screen, then switches it to the animated state:
.pop-on-scroll[data-pop="waiting"] {
opacity: 0;
}
.pop-on-scroll[data-pop="in"] {
animation: pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
const items = document.querySelectorAll(".pop-on-scroll");
const observer = new IntersectionObserver((entries) => {
for (const entry of entries) {
if (!entry.isIntersecting) continue;
entry.target.dataset.pop = "in";
observer.unobserve(entry.target);
}
}, { threshold: 0.2 });
for (const item of items) {
item.dataset.pop = "waiting";
observer.observe(item);
}
The script is what hides the elements, so if JavaScript fails to load, everything still shows up. Pick one of these two methods per element. Don’t stack them.
Pop In a Popup or Modal
Keyframe animations run every time an element goes from display: none to visible. That makes a native <dialog> easy, because it’s hidden until you open it:
dialog[open] {
animation: pop-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
dialog[open]::backdrop {
animation: fade-in 0.3s ease-out both;
}
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
<dialog id="hello">
<p>Popped in.</p>
<form method="dialog"><button>Close</button></form>
</dialog>
<button onclick="document.getElementById('hello').showModal()">Open</button>
A popover works the same way, and doesn’t need any JavaScript at all. The popovertarget button opens it, and :popover-open matches while it’s showing:
<button popovertarget="tip">What's this?</button>
<div id="tip" popover>Hi, I popped in.</div>
[popover]:popover-open {
animation: pop-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
The same trick works on any div you show and hide with display: none. For a big modal, I’d start closer to full size, like scale(0.9), since a large box zooming up from half size is a lot.
Pop In a Toast With @starting-style
Toasts, notifications and new list items usually get added to the page with JavaScript. The keyframes work for those too, but @starting-style is a nice option. It sets the values a transition starts from on the element’s first render:
.toast {
opacity: 1;
transform: scale(1);
transition:
opacity 0.3s ease-out,
transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@starting-style {
.toast {
opacity: 0;
transform: scale(0.8);
}
}
const toast = document.createElement("div");
toast.className = "toast";
toast.textContent = "Saved!";
document.body.append(toast);
The difference from keyframes is that it’s a transition, so it can also animate out. Add display to the transition with allow-discrete and it fades out before it’s hidden:
.toast {
transition:
opacity 0.3s ease-out,
transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
display 0.3s allow-discrete;
}
.toast.is-hidden {
display: none;
opacity: 0;
transform: scale(0.8);
}
@starting-style works in Chrome 117, Firefox 129 and Safari 17.5 and later, and allow-discrete works in Chrome 117, Firefox 129 and Safari 17.4. Older browsers show and hide the toast without the transition, so it fails safely.
Replay the Pop on Click
A pop on click is fun on a like button or a cart icon. A CSS animation only plays when its class is added, so remove the class when it finishes and it’s ready to go again:
@keyframes pop {
0% { transform: scale(1); }
40% { transform: scale(1.25); }
100% { transform: scale(1); }
}
.like.is-popping {
animation: pop 0.3s ease-out;
}
const like = document.querySelector(".like");
like.addEventListener("click", () => {
like.classList.add("is-popping");
});
like.addEventListener("animationend", () => {
like.classList.remove("is-popping");
});
Respect Reduced Motion
Some people turn on reduced motion in their operating system because zooming and scaling animations make them feel sick. The prefers-reduced-motion media query lets you honor that. A good compromise is to keep the fade and drop the scale:
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
.pop-in,
.pop-in-spring,
.pop-list li,
.pop-on-scroll[data-pop="in"],
dialog[open],
[popover]:popover-open {
animation-name: fade-in;
}
}
A fade still tells people something changed, without the motion. prefers-reduced-motion works in Chrome 74, Firefox 63 and Safari 10.1 and later, so you can use it everywhere.
Keep It Smooth
Only animate transform and opacity. Browsers can run those without recalculating layout, so they stay smooth even on a slow phone. Animating width, height, top or margin makes the browser redo layout on every frame, and that’s where jank comes from.
You don’t need will-change: transform for a short pop in. Save it for when you’ve actually seen an animation stutter.
Why Your Pop In Animation Isn’t Working
These are the problems I run into most:
- Nothing happens on a
<span>or<a>.transformdoesn’t apply to inline elements. Adddisplay: inline-block. - The element flashes before it pops. You have a delay without
both(orbackwards) as the fill mode. Addbothto the shorthand. - It only plays once. That’s how CSS animations work. Remove and re-add the class, like the click example above.
- It jumps at the end. Your
tokeyframe doesn’t match the element’s normal style. Make the last keyframe match where the element should end up. - The scroll version doesn’t play. Check that
animation-timelinecomes after theanimationshorthand, and that the browser supports it.
Browser Support
The basic pop in animation works in every browser people use. @keyframes, transform and opacity have worked without prefixes since Chrome 43, Firefox 16 and Safari 9. Here’s what the newer pieces in this post need:
| Feature | Chrome | Firefox | Safari |
|---|---|---|---|
prefers-reduced-motion |
74 | 63 | 10.1 |
linear() easing |
113 | 112 | 17.2 |
Popover and :popover-open |
114 | 125 | 17 |
animation-timeline: view() |
115 | 159 | 26 |
@starting-style |
117 | 129 | 17.5 |
sibling-index() |
138 | 154 | 26.2 |
I pulled these from MDN’s browser compatibility data in November 2026. Every example falls back to a plain pop or no animation at all, so none of them break the page in older browsers.
Live Demo
You can play with the original pop in effect on CodePen.
FAQ
What is a pop in animation in CSS?
It’s an animation where an element scales up from smaller than its normal size while it fades in. You build it with @keyframes that go from opacity: 0 and a small scale() to opacity: 1 and scale(1).
How do I make a CSS pop in animation bounce?
Use an easing with overshoot, like cubic-bezier(0.34, 1.56, 0.64, 1), or add a middle keyframe at scale(1.1). For a springy wobble, use the linear() easing function with points above 1.
How do I make an element pop in when it scrolls into view?
Use animation-timeline: view() for a CSS-only version. If you want it to play once, use an IntersectionObserver that adds the animation when the element becomes visible.
Should I use a transition or a keyframe animation for a pop in?
Use keyframes when the element shows up on page load or when its display changes, like a dialog or popover. Use a transition with @starting-style when you also want an exit animation, like a toast that fades away.
Can I make a popup animation without JavaScript?
Yes. Use the popover attribute with a popovertarget button and the :popover-open keyframes above. The browser handles opening and closing, and the pop in runs every time it opens.
If you want to go deeper, MDN’s @keyframes reference covers every option on the animation properties.
Slap a sticker on this post
Comments
Loading comments…