---
title: useAnimation
description: "`useAnimation` is a custom hook that implements animations similar to CSS `keyframes`."
links:
- source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/hooks/use-animation
- storybook: https://yamada-ui.github.io/yamada-ui?path=/story/hooks-useanimation--basic
---
```tsx
const animation = useAnimation({
keyframes: {
"0%": {
bg: "red.500",
},
"20%": {
bg: "green.500",
},
"40%": {
bg: "purple.500",
},
"60%": {
bg: "yellow.500",
},
"80%": {
bg: "blue.500",
},
"100%": {
bg: "red.500",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
})
return
```
## Usage
```tsx
import { useAnimation } from "@yamada-ui/react"
```
```tsx
import { useAnimation } from "@/components/ui"
```
```tsx
import { useAnimation } from "@workspaces/ui"
```
```tsx
const animation = useAnimation()
```
### Use Theme Tokens
To use [theme](https://yamada-ui.com/docs/theming.md) [animations](https://yamada-ui.com/docs/theming/tokens/animations.md), set the argument.
```tsx
const animation = useAnimation("gradient")
return
```
:::warning
By default, no animation tokens are defined.
:::
### Use Multiple Animations
To use multiple animations, set the arguments as an array.
```tsx
const animation = useAnimation([
{
keyframes: {
"0%": {
bg: "red.500",
},
"20%": {
bg: "green.500",
},
"40%": {
bg: "purple.500",
},
"60%": {
bg: "yellow.500",
},
"80%": {
bg: "blue.500",
},
"100%": {
bg: "red.500",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
},
{
keyframes: {
"0%": {
h: "xs",
},
"50%": {
h: "md",
},
"100%": {
h: "xs",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
},
{
keyframes: {
"0%": {
w: "full",
},
"50%": {
w: "50%",
},
"100%": {
w: "full",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
},
])
return (
)
```
### Use Responsive Design
To use responsive design, set the `animation` as a object.
```tsx
const desktopAnimation = useAnimation({
keyframes: {
"0%": {
bg: "red.500",
},
"20%": {
bg: "green.500",
},
"40%": {
bg: "purple.500",
},
"60%": {
bg: "yellow.500",
},
"80%": {
bg: "blue.500",
},
"100%": {
bg: "red.500",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
})
const tabletAnimation = useAnimation({
keyframes: {
"0%": {
bg: "cyan.500",
},
"20%": {
bg: "emerald.500",
},
"40%": {
bg: "pink.500",
},
"60%": {
bg: "amber.500",
},
"80%": {
bg: "sky.500",
},
"100%": {
bg: "cyan.500",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
})
return (
)
```
### Use Color Mode
To use color mode, pass an array to `animation`.
```tsx
const lightAnimation = useAnimation({
keyframes: {
"0%": {
bg: "red.500",
},
"20%": {
bg: "green.500",
},
"40%": {
bg: "purple.500",
},
"60%": {
bg: "yellow.500",
},
"80%": {
bg: "blue.500",
},
"100%": {
bg: "red.500",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
})
const darkAnimation = useAnimation({
keyframes: {
"0%": {
bg: "red.800",
},
"20%": {
bg: "green.800",
},
"40%": {
bg: "purple.800",
},
"60%": {
bg: "yellow.800",
},
"80%": {
bg: "blue.800",
},
"100%": {
bg: "red.800",
},
},
duration: "10s",
iterationCount: "infinite",
timingFunction: "linear",
})
return
```