# Custom keyframes for scroll animations

> Replace the generated entrance with native Web Animations keyframes: set a custom easing, end at the resting style and keep the element's own values.

The [`from`](/guides/entrances/) option gives the most common entrances. For full control, give native [Web Animations keyframes](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats) in the [`keyframes`](/reference/options/#keyframes) option. The keyframes replace the generated entrance.

## Give native keyframes

Set `keyframes` to an array of keyframe objects. This entrance zooms in and bounces a little at the end:

You cannot use `from` and `keyframes` together. TypeScript rejects the two options on the same element.

## Set the easing

Set the easing in the keyframes. The `easing` of a keyframe applies from that keyframe to the next keyframe. Without an `easing`, the change from a keyframe to the next keyframe is linear. No option sets the easing of the full entrance.

The `easing` takes a CSS [easing function](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/easing-function):

* A keyword, such as `ease-out` or `ease-in-out`.
* A [`cubic-bezier()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/easing-function/cubic-bezier) curve. A second or fourth number above 1 makes the element go past its end position and come back.
* A [`linear()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/easing-function/linear) function. It connects a list of points, so it can make a spring or a bounce. The positions in `linear()` are fractions of the [`duration`](/reference/options/#duration). Set a longer `duration` for a spring with more bounces. It needs Chrome 113, Firefox 112 or Safari 17.2. In other browsers, the element shows with no animation.

This example zooms three cards at the same time: with `ease-out`, with a `cubic-bezier()` overshoot and with a `linear()` spring. The curve under each card shows the progress of the entrance over time. The dashed line is the end size. The code shows the `linear()` spring:

## End at the resting style

The entrance does not keep its last keyframe after it ends. The element then returns to its own style. If the last keyframe is different from that style, the element jumps at the end of the entrance. Make the last keyframe agree with the resting style of the element.

## Keep the element’s own values

While the entrance plays, the keyframes replace the element’s own values of the properties that they animate. In the JavaScript API, they also replace them while the element waits. To end at the element’s own value, end with a neutral [additive keyframe](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/composite). For example, this entrance ends at the `opacity` of the element, also when the CSS sets `opacity: 0.8`:

```js
const keyframes = [{ opacity: 0 }, { opacity: 0, composite: "add" }];
```

An additive keyframe adds its value to the element’s own value. An `opacity` of 0 adds nothing.

* A keyframe with `composite` needs Firefox 80 or Safari 16.
* Chromium runs an animation with an additive keyframe on the main thread. The animation can stutter when the main thread is busy.

## Give explicit values to the first keyframe

Set each animated property in the first keyframe. An open WebKit bug ([212409](https://bugs.webkit.org/show_bug.cgi?id=212409)) can take an [implicit start value](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats#implicit_tofrom_keyframes) from an earlier animation.

## Animate custom properties

A keyframe can animate a CSS [custom property](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Cascading_variables/Using_custom_properties), such as `"--progress"`. Register the property with [`@property`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@property) and give it a syntax, such as `"<number>"`. Without a registration, the browser cannot interpolate the value, so the value changes in one step at the middle of the entrance.

## Animate the properties that the compositor runs

Animate `opacity`, `transform`, `translate`, `scale` and `rotate` when possible. The browser runs these animations [on the compositor](https://web.dev/articles/stick-to-compositor-only-properties-and-manage-layer-count), so a busy main thread does not make them stutter. A layout property, such as `width`, `top` or `margin`, causes [a layout and a paint](https://web.dev/articles/rendering-performance) on each frame.
