# Motion > Motion is a production-grade animation library for JavaScript, React and Vue. This index links the official documentation, tutorials and articles for the Motion library and the Motion+ premium toolkit. The Motion MCP server at https://mcp.motion.dev searches Motion's docs and examples. It is free and needs no account. MCP setup for Claude Code, Cursor and other agents: https://motion.dev/docs/ai-kit-install Every docs page is also available as Markdown: add .md to its URL (https://motion.dev/docs/react.md), or request the page with Accept: text/markdown. https://motion.dev/llms-full.txt has the full text of every docs page in one file. The motion, motion/react and motion-v packages are free and MIT-licensed. Motion+ is a separate paid product: a one-time Solo licence for one developer, or an annual per-seat Team plan for two or more (https://motion.dev/plus). Pages in the Motion+ sections below document Motion+ features. Each entry says how to install and import it, because Motion+ components are not part of the free packages. This file has the full text of every Motion docs page, React first, then JavaScript, Vue and AI Kit. Pages labelled Motion+ document paid features. Each page starts after a line that gives its URL. --- Source: https://motion.dev/docs/react-motion-component # Motion component Animate elements with a declarative API. Supports variants, gestures, and layout animations. Most [React animations](https://motion.dev/docs/react-animation) in Motion are powered by the `` component. There's a `motion` component for every HTML and SVG element, for instance `motion.div`, `motion.circle` etc. It extends standard React components with animation props that run at up to 120fps - without triggering React re-renders. ## Usage Import `motion` from Motion: ``` // React import { motion } from "motion/react" // React Server Components (Next.js etc) import * as motion from "motion/react-client" ``` Video: https://www.youtube.com/embed/mWch9bA5A7s?iv_load_policy=3&rel=0&modestbranding=1&playsinline=1&autoplay=0&mute=1 You can use a `motion` component exactly as you would any normal HTML/SVG component: ``` ``` Styling works exactly as it does anywhere else in your app, including [Tailwind CSS utility classes](https://motion.dev/docs/react-tailwind). But you also gain access to powerful animation APIs like the `animate`, `layout`, `whileInView` props. ``` ``` ### Performance `motion` components bypass React's render cycle entirely. Animated values update on every frame via the browser's native animation pipeline, so even complex animations with dozens of animated properties won't cause React re-renders or style/layout thrashing. Using [motion values](https://motion.dev/docs/react-motion-value) instead of React state to update `style` will also avoid re-renders. ``` const x = useMotionValue(0) useEffect(() => { // Won't trigger a re-render! const timeout = setTimeout(() => x.set(100), 1000) return () => clearTimeout(timeout) }, []) return ``` ### Server-side rendering `motion` components are fully compatible with server-side rendering, meaning the initial state of the component will be reflected in the server-generated output. ``` // Server will output `translateX(100px)` ``` ### Custom components You can add motion capabilities to any React component with `motion.create()`. The returned component accepts all standard motion props (`animate`, `whileHover`, `drag`, `layout`, etc.) alongside the original component's props. ``` const MotionComponent = motion.create(Component) ``` Your component **must** pass a ref to the component you want to animate. **React 18:** Use `forwardRef` to wrap the component and pass `ref` to the element you want to animate: ``` const Component = React.forwardRef((props, ref) => { return
}) ``` **React 19:** React 19 can pass `ref` via `props`: ``` const Component = (props) => { return
}) ``` It's also possible to pass strings to `motion.create`, which will create custom DOM elements. ``` // Will render into HTML const MotionComponent = motion.create('custom-element') ``` By default, all `motion` props (like `animate` etc) are filtered out of the `props` forwarded to the provided component. By providing a `forwardMotionProps` config, the provided component will receive these props. ``` motion.create(Component, { forwardMotionProps: true }) ``` **Tip:** Building with AI? The Motion AI Kit MCP gives your AI editor access to the latest docs and source code of 510+ examples. **Warning:** Make sure not to call `motion.create()` within a React render function! This will make a new component every render, breaking your animations. ## Props `motion` components accept the following props. ### Animation Motion provides declarative animation props like `animate` and `exit`. [Learn more about React animations in Motion](https://motion.dev/docs/react-animation). #### `initial` The initial visual state of the `motion` component. This can be set as an animation target: ``` ``` Variants: ``` ``` ``` ``` Or set as `false` to disable the enter animation and initially render as the values found in `animate`. ``` ``` #### `animate` A target to animate to on enter, and on update. Can be set as an animation target: ``` ``` Or variants: ``` ``` ``` ``` #### `exit` A target to animate to when a component is removed from the tree. Can be set either as an animation target, or variant. **Note:** Owing to React limitations, the component being removed must be a direct child of AnimatePresence to enable this animation. #### `transition` The default [transition](https://motion.dev/docs/react-transitions) for this component to use when an animation prop (`animate`, `whileHover` etc) has no `transition` defined. ``` ``` #### `variants` The [variants](https://motion.dev/docs/react-animation#variants) for this component. ``` const variants = { active: { backgroundColor: "#f00" }, inactive: { backgroundColor: "#fff", transition: { duration: 2 } } } return ( ) ``` #### `style` The normal React DOM `style` prop, with added support for [motion values](https://motion.dev/docs/react-motion-value) and independent transforms. ``` const x = useMotionValue(30) return ``` #### `onUpdate` Callback triggered every frame any value on the `motion` component updates. It's provided a single argument with the latest values. ``` console.log(latest.opacity)} /> ``` #### `onAnimationStart` Callback triggered when any animation (except layout animations, see `onLayoutAnimationStart`) starts. It's provided a single argument, with the target or variant name of the started animation. ``` console.log(latest.r)} /> ``` #### `onAnimationComplete` Callback triggered when any animation (except layout animations, see `onLayoutAnimationComplete`) completes. It's provided a single argument, with the target or variant name of the completed animation. ``` console.log(latest.r)} /> ``` ### Hover #### `whileHover` Animation state, or variant label, to perform a [hover animation](https://motion.dev/docs/react-hover-animation) to while the hover gesture is active. ``` // As target ``` ``` // As variants ``` #### `onHoverStart` Callback function that fires when a pointer starts hovering over the component. Provided the triggering `PointerEvent`. ``` console.log(event)} /> ``` #### `onHoverEnd` Callback function that fires when a pointer stops hovering over the component. Provided the triggering `PointerEvent`. ``` console.log(event)} /> ``` #### Tap #### `whileTap` Animation state, or variant label, to perform a [press animation](https://motion.dev/docs/react-gestures) to while the hover gesture is active. ``` // As target ``` ``` // As variants ``` #### `onTapStart` Callback function that fires when a pointer starts pressing the component. Provided the triggering `PointerEvent`. ``` console.log(event)} /> ``` #### `onTap` Callback function that fires when a pointer stops pressing the component and the pointer was released **inside** the component. Provided the triggering `PointerEvent`. ``` console.log(event)} /> ``` #### `onTapCancel` Callback function that fires when a pointer stops pressing the component and the pointer was released **outside** the component. Provided the triggering `PointerEvent`. ``` console.log(event)} /> ``` ### Focus #### `whileFocus` Animation state, or variant label, to animate to while the focus gesture is active. ``` // As target ``` ``` // As variants ``` ### Pan #### `onPan` Callback function that fires when the pan gesture is recognised on this element. ``` function onPan(event, info) { console.log(info.point.x, info.point.y) } ``` Pan and drag events are provided the origin `PointerEvent` as well as an object `info` that contains `x` and `y` point values for the following: - `point`: Relative to the device or page. - `delta`: Distance since the last event. - `offset`: Distance from the original event. - `velocity`: Current velocity of the pointer. **Note:** For pan gestures to work correctly with touch input, the element needs touch scrolling to be disabled on either x/y or both axis with the touch-action CSS rule. #### `onPanStart` Callback function that fires when a pan gesture starts. Provided the triggering `PointerEvent` and `info`. ``` console.log(info.delta.x)} /> ``` #### `onPanEnd` Callback function that fires when a pan gesture ends. Provided the triggering `PointerEvent` and `info`. ``` console.log(info.delta.x)} /> ``` ### Drag #### `drag` **Default: **`false` Enable dragging for this element. Set `true` to drag in both directions. Set `"x"` or `"y"` to only drag in a specific direction. ``` ``` #### `whileDrag` Animation state, or variant label, to perform a [drag animation](https://motion.dev/docs/react-drag) to while the hover gesture is active. ``` // As target ``` ``` // As variants ``` #### `dragConstraints` Applies constraints on the draggable area. Set as an object of optional `top`, `left`, `right`, and `bottom` values, measured in pixels: ``` ``` Or as a `ref` to another element to use its bounding box as the draggable constraints: ``` const MyComponent = () => { const constraintsRef = useRef(null) return ( ) } ``` #### `dragSnapToOrigin` **Default: **`false` If `true`, the draggable element will animate back to its center/origin when released. ``` ``` #### `dragElastic` **Default: **`0.5` The degree of movement allowed outside constraints. `0` = no movement, `1` = full movement. Set to `0.5` by default. Can also be set as `false` to disable movement. By passing an object of `top`/`right`/`bottom`/`left`, individual values can be set per constraint. Any missing values will be set to `0`. ``` ``` #### `dragMomentum` **Default: **`true` Apply momentum from the pan gesture to the component when dragging finishes. Set to `true` by default. ``` ``` #### `dragTransition` Allows you to change dragging momentum transition. When releasing a draggable element, an animation with type `"inertia"` starts. The animation is based on your dragging velocity. This property allows you to customize it. ``` ``` #### `dragDirectionLock` **Default: **`false` Locks drag direction into the soonest detected direction. For example, if the component is moved more on the `x` axis than `y` axis before the drag gesture kicks in, it will **only** drag on the `x` axis for the remainder of the gesture. ``` ``` #### `dragPropagation` **Default:** `false` Allows drag gesture propagation to child components. ``` ``` #### `dragControls` Usually, dragging is initiated by pressing down on a component and moving it. For some use-cases, for instance clicking at an arbitrary point on a video scrubber, we might want to initiate dragging from a different component than the draggable one. By creating a `dragControls` using the `useDragControls`[ hook](https://motion.dev/docs/react-use-drag-controls), we can pass this into the draggable component's `dragControls` prop. It exposes a `start` method that can start dragging from pointer events on other components. ``` const dragControls = useDragControls() function startDrag(event) { dragControls.start(event, { snapToCursor: true }) } return ( <>
) ``` **Tip:** Given that by setting `dragControls` you are taking control of initiating the drag gesture, it is possible to disable the draggable element as the initiator by setting `dragListener={false}`. #### `dragListener` Determines whether to trigger the drag gesture from event listeners. If passing `dragControls`, setting this to `false` will ensure dragging can only be initiated by the controls, rather than a `pointerdown` event on the draggable element. #### `onDrag` Callback function that fires when the drag gesture is recognised on this element. ``` function onDrag(event, info) { console.log(info.point.x, info.point.y) } ``` Pan and drag events are provided the origin `PointerEvent` as well as an object `info` that contains `x` and `y` point values for the following: - `point`: Relative to the device or page. - `delta`: Distance since the last event. - `offset`: Distance from the original event. - `velocity`: Current velocity of the pointer. #### `onDragStart` Callback function that fires when a drag gesture starts. Provided the triggering `PointerEvent` and `info`. ``` console.log(info.delta.x)} /> ``` #### `onDragEnd` Callback function that fires when a drag gesture ends. Provided the triggering `PointerEvent` and `info`. ``` console.log(info.delta.x)} /> ``` #### `onDirectionLock` Callback function that fires a drag direction is determined. ``` console.log(axis)} /> ``` ### Gestures #### `propagate` Prevent children gestures from propagating to their parents. Currently only supports `tap`. ``` // Pressing this button won't fire the above scale animation ``` ### Viewport Learn more about [scroll-triggered animations](https://motion.dev/docs/react-scroll-animations) in React. #### `whileInView` Target or variants to label to while the element is in view. ``` // As target ``` ``` // As variants ``` #### `viewport` Options to define how the element is tracked within the viewport. ``` ``` Available options: - `once`: If `true`, once element enters the viewport it won't detect subsequent leave/enter events. - `root`: The `ref` of an ancestor scrollable element to detect intersections with (instead of `window`). - `margin`: A margin to add to the viewport to change the detection area. Defaults to `"0px"`. Use multiple values to adjust top/right/bottom/left, e.g. `"0px -20px 0px 100px"`. - `amount`: The amount of an element that should enter the viewport to be considered "entered". Either `"some"`, `"all"` or a number between `0` and `1`. Defaults to `"some"`. #### `onViewportEnter` Callback function that fires when an element enters the viewport. Provided the `IntersectionObserverEntry` with details of the intersection event. ``` console.log(entry.isIntersecting)} /> ``` #### `onViewportLeave` Callback function that fires when an element enters the viewport. Provided the `IntersectionObserverEntry` with details of the intersection event. ``` console.log(entry.intersectionRect)} /> ``` ### Layout Learn more about [layout animations](https://motion.dev/docs/react-layout-animations) in React. #### `layout` **Default: **`false` If `true`, this component will perform [layout animations](https://motion.dev/docs/react-layout-animations). ``` ``` If set to `"position"` or `"size"`, only its position or size will animate, respectively. ``` ``` #### `layoutId` If set, this component will animate changes to its layout. Additionally, when a new element enters the DOM and an element already exists with a matching `layoutId`, it will animate out from the previous element's size/position. ``` {items.map(item => ( {item.name} {item.isSelected && } ))} ``` If the previous component remains in the tree, the two elements will crossfade. #### `layoutDependency` By default, layout changes are detected every render. To reduce measurements and thus improve performance, you can pass a `layoutDependency` prop. Measurements will only occur when this value changes. ``` ``` ### `layoutAnchor` **Default: **`{ x: 0, y: 0 }` Motion's layout animations look correct when a parent and child animate with different transitions, because it resolves the child's position relative to its parent. By default, it does this using the top/left of the parent. `layoutAnchor` can customise this point, where `x` and `y` can be set as independent progress values between `0` and `1`. - `0` = top/left - `0.5` = center - `1` = bottom/right Setting to `false` disables relative projection for this element, and elements will animate relative to their page-relative change. ``` ``` Live example: https://examples.motion.dev/react/layout-anchor #### `layoutScroll` For layout animations to work correctly within scrollable elements, their scroll offset needs measuring. For performance reasons, Framer Motion doesn't measure the scroll offset of every ancestor. Add the `layoutScroll` prop to elements that should be measured. ``` ``` #### `layoutRoot` For layout animations to work correctly within `position: fixed` elements, we need to account for page scroll. Add `layoutRoot` to mark an element as `position: fixed`. ``` ``` #### `onLayoutAnimationStart` A callback to run when a layout animation starts. #### `onLayoutAnimationComplete` A callback to run when a layout animation completes. ### Advanced #### `inherit` Set to `false` to prevent a component inheriting or propagating changes in a parent variant. #### `custom` Custom data to pass through to dynamic variants. ``` const variants = { visible: (custom) => ({ opacity: 1, transition: { delay: custom * 0.2 } }) } return ( ) ``` #### `transformTemplate` By default, transforms are applied in order of `translate`, `scale`, `rotate` and `skew`. To change this, `transformTemplate` can be set as a function that accepts the latest transforms and the generated transform string and returns a new transform string. ``` // Use the latest transform values `rotate(${rotate}deg) translateX(${x}px)` } /> ``` ``` // Or the generated transform string `translate(-50%, -50%) ${generated}` } /> ``` ## FAQs ### What is the `` component? `` is a drop-in replacement for HTML and SVG elements that adds animation capabilities. Instead of writing `
`, you write ``. The element behaves identically but can now accept animation props like `animate`, `whileHover`, and `transition`. ### How do I animate an element in React with Motion? Pass an `animate` prop to any `` component with the values you want to animate to. For example, `` will animate opacity from its current value to 1. Motion automatically detects changes and animates between them. ### Does `` affect performance? `` is optimised to animate `transform` and `opacity` on the compositor thread wherever possible, avoiding layout and paint. For best performance, prefer animating `transform` and `opacity` over properties like `width` or `top`. ### Can I use `` with custom components? Yes. Use `motion.create()` to wrap any component that forwards its ref and accepts a `style` prop. For example: `const MotionButton = motion.create(Button)`. --- Source: https://motion.dev/docs/react-motion-ui-installation # Install Motion UI Install Motion UI in your React project from the private registry, keeping your token out of source control. Motion UI is served through Motion's private registry. You need a [Motion+ membership](https://motion.dev/plus) to get an access token for the registry at `api.motion.dev`. Your access token is a secret: it never belongs in `package.json`, lockfiles, or anything else you commit. The setup below keeps it in an environment variable instead. You can find your token on your [Motion+ tokens page](https://motion.dev/dashboard/tokens). ## Quick start (npm, pnpm, Bun) **1. Create (or update) `.npmrc` in your project root:** ```ini @motionplus:registry=https://api.motion.dev/npm/ //api.motion.dev/npm/:_authToken=${MOTION_TOKEN} ``` This file is safe to commit: it references an environment variable, not the token itself. **2. Add the dependency to `package.json`:** ```json { "dependencies": { "motion-plus": "npm:@motionplus/core@^2.12.0" } } ``` This installs the scoped package `@motionplus/core` under the name `motion-plus`, so imports work exactly as documented: ```tsx import { Cursor } from "motion-plus/react" ``` If you prefer, you can depend on `@motionplus/core` directly and import from `@motionplus/core/react` instead. **3. Provide the token and install:** ```bash export MOTION_TOKEN=your-token-here npm install # or pnpm install / bun install ``` Semver ranges work like any npm package: `^2.12.0`, `2.12.0`, `latest`. ## Where to put the token Your package manager reads `${MOTION_TOKEN}` from the **process environment** at install time. How you set it depends on your tooling: - **Bun** loads `.env` files automatically. Add `MOTION_TOKEN=...` to `.env` (and `.env` to `.gitignore`) and you're done. - **npm and pnpm** do *not* read `.env` files. Export the variable in your shell, use [direnv](https://direnv.net), or prefix installs with [dotenv-cli](https://www.npmjs.com/package/dotenv-cli): `npx dotenv-cli -- npm install`. **Note:** npm exits with `Failed to replace env in config` on every command while `MOTION_TOKEN` is unset, including commands that don't touch the network. Everyone on your team (and CI) needs it set. ## Yarn **Yarn 1 (Classic)** ignores the scoped-registry line in `.npmrc`, so add a `.yarnrc` alongside it: ```ini "@motionplus:registry" "https://api.motion.dev/npm/" ``` Keep the `.npmrc` from the quick start: Yarn 1 reads the auth token from it. Then set `MOTION_TOKEN` in your shell and `yarn install`. **Yarn 2+ (Berry)** uses `.yarnrc.yml` instead of `.npmrc`: ```yaml npmScopes: motionplus: npmRegistryServer: "https://api.motion.dev/npm" npmAuthToken: "${MOTION_TOKEN}" ``` ## CI Add `MOTION_TOKEN` as a secret in your CI provider and expose it as an environment variable. For example, in GitHub Actions: ```yaml - run: npm ci env: MOTION_TOKEN: ${{ secrets.MOTION_TOKEN }} ``` The same applies to deploy platforms that run your install step (Vercel, Netlify, etc.): add `MOTION_TOKEN` to their environment variable settings. ## Migrating from the URL-based install If you previously installed Motion UI via `https://api.motion.dev/registry.tgz?...`: 1. Replace the dependency in `package.json` with the alias form from the quick start. Your imports don't change. 2. Add the `.npmrc` (and `.yarnrc` or `.yarnrc.yml` if you use Yarn). 3. Delete your lockfile entry for `motion-plus` (or simply reinstall) so it re-resolves against the registry. 4. **If your token was ever committed** (in `package.json`, a lockfile, or a URL), treat it as compromised: regenerate it from your account page. The old endpoint keeps working, so you can migrate whenever suits you. ## Troubleshooting - **`401 Unauthorized`.** `MOTION_TOKEN` is empty or invalid at install time. Remember npm and pnpm don't read `.env` files; check the variable is actually exported in the environment running the install. Regenerate the token from your account page if needed. - **`401` under pnpm with a warning that it "Ignored project-level auth setting".** pnpm 11+ refuses to expand `${MOTION_TOKEN}` in an `_authToken` line that sits in a committed project `.npmrc`, so it sends no credential. Keep the `@motionplus:registry=...` line in `.npmrc`, but provide the token from a source pnpm trusts. In a CI or deploy build step (Cloudflare Pages, etc.), run this before `pnpm install`: ```bash pnpm config set "//api.motion.dev/npm/:_authToken" "$MOTION_TOKEN" ``` It writes the resolved token to the user-level config, which stays out of your repo. Writing the same line to `~/.npmrc` works too. - **`404` from `registry.npmjs.org` for `@motionplus/...`.** The scoped-registry config isn't being picked up. Check the `.npmrc` is in the project root (Yarn users: see the Yarn section above). - **Install works locally but fails in CI or on deploy.** `MOTION_TOKEN` isn't set in that environment. Add it as a secret. - **Monorepos (pnpm workspaces, Rush, Turborepo).** The config above works natively; place `.npmrc` at the workspace root. --- Source: https://motion.dev/docs/framer # Motion x Framer integration guide Add animations to your Framer project, in Code Components and Overrides. [Framer](https://framer.link/pgsExYX) is the world's best no-code website builder. If you have a Framer website, all your animations are already powered by Motion. Framer offers a number of [animations, interactions and components](https://framer.link/bdH9gwO) that mean you usually never need to write any code to achieve amazing effects. However, advanced users can write [code components ](https://framer.link/MXPS0dB)and [overrides](https://framer.link/bdhlZ3f), which are custom React components that you can drop into your canvas. The full Motion for React API is available to use in both. ## Import Import Motion for React via `"framer-motion"`: ``` import { motion, useSpring } from "framer-motion" ``` Use `"framer-motion"` whenever the Motion docs instruct you to use `"motion/react"`. ## Overrides Components returned by overrides support the full `motion`[ component API](https://motion.dev/docs/react-motion-component). This means you can pass props like `animate`, `transition`, `whileHover` etc: ``` export function withRotateAnimation(Component): ComponentType { return forwardRef((props, ref) => { return ( ) }) } ``` ## Next With Motion set up in your Framer project, we recommend you follow the rest of the [Quick Start](https://motion.dev/docs/react) guide to begin learning Motion for React. --- Source: https://motion.dev/docs/figma # Figma Motion: animate with Figma and export to Motion Animate in Figma Motion and export to real Motion code for React. Or use Motion directly inside Figma Sites. [Figma Motion](https://www.figma.com/motion/) is a powerful timeline and AI animation editor in Figma that can export as real Motion code. Figma also features Motion prominently in [Figma Sites](https://www.figma.com/sites/) and [Figma Make](https://www.figma.com/make/), and in this guide learn how to use all of them. ## Exporting Figma Motion to code Animations can be added to shapes in Figma by clicking the add (+) button in the Animations panel: ![Figma animations panel](https://images.motion.dev/docs/figma/figma-animations-panel.png) Then, further edited using the timeline editor, which is opened with the Figma Motion button: ![Figma Motion icon](https://images.motion.dev/docs/figma/figma-motion-icon.png) A full usage guide can be found on the [official Figma Motion docs](https://help.figma.com/hc/en-us/categories/41274596092695-Figma-Motion), but once you're happy with your animation you can jump into Dev Mode. ![Figma Dev Mode icon](https://images.motion.dev/docs/figma/figma-dev-mode-icon.png) Select your animated layer, and then in the Motion panel select "React". This will present you with fully-valid Motion code that you can copy-paste into your project. ![Figma Motion export](https://images.motion.dev/docs/figma/figma-export.png) **Note:** Code exported with Figma Motion assumes you already have Motion installed in your project. Please follow the [Motion for React quick start guide](https://motion.dev/docs/react) to set Motion up in your project. ## Figma Sites Figma Sites is a no-code website builder. Motion powers the animations on the websites it publishes. No setup or installation needed - simply add animations like Hover effect or Press effect via the Interactions panel to add real Motion animations. ![Add animation panel in Figma Sites](https://images.motion.dev/docs/r6kq04Sawfi36eiGmq1gAZS3134.png) ## Figma Make Figma Make is an AI code generator that can generate React code from text, image, and Figma artboard prompts. In general, it will produce Motion code simply by asking it to animate something. For instance, you can give it a screenshot of the [Motion homepage](https://motion.dev/) and tell it to animate: ![Prompting Figma Make to animate the Motion homepage](https://images.motion.dev/docs/I9UrB7u2e1BkL2tS96LYDd7ms.png) This will produce a code file with Motion already imported: ```jsx {words.map((word, index) => ( {word} ))} ``` If your generated Make project doesn't include a `motion` import then you can either ask the AI to add it for you, or simply add an import to the top of your component: ``` import { motion } from "motion/react" ``` **Note:** As with many AI generators, Figma Make tends to import Motion from `"framer-motion"`, its former package name. That import still runs, but `motion` is the current package, and we recommend moving to it. The move is usually a rename: change the import to `"motion/react"`, and install `motion` in place of `framer-motion` if your project lists `framer-motion`. The [upgrade guide](https://motion.dev/docs/react-upgrade-guide) has the steps. ## FAQ ### Does Figma Motion use Motion? Yes. When you export a Figma Motion animation as React in Dev Mode, you get real, production-ready Motion code that you can paste straight into your project. The animations Figma Sites publishes are also powered by Motion. ### How do I export a Figma Motion animation to code? Open Dev Mode, select your animated layer, then pick a format in the Motion panel. Choosing "React" gives you Motion code. Figma Motion can also export CSS and JSON. ### Do I need to install Motion to use the exported code? Yes. The exported React code assumes Motion is already installed in your project. Follow the [Motion for React quick start](https://motion.dev/docs/react) to add it, then paste the code in. ### Why does my exported code import from framer-motion? Sometimes, because of outdated training data, agents will generate an import from `"framer-motion"`. This still works and will for many versions to come, but we recommend you change it to `"motion/react"` to ensure best compatibility with our docs and examples. ### Can I add Motion animations without exporting code? Yes. Figma Sites publishes real Motion animations with no setup. Add effects like Hover or Press from the Interactions panel and Figma generates the Motion animation for you. --- Source: https://motion.dev/docs/react-tailwind # Animating with Tailwind CSS Combine Motion with Tailwind CSS's utility-first workflow. Motion is the perfect animation companion for [Tailwind CSS](https://tailwindcss.com) v4: Tailwind handles the styling, Motion handles the animation. In this guide, we'll learn how to: - **Perform basic animations **with the two libraries. - **Create responsive animations** by animating CSS variables. - **Generate Tailwind CSS spring animations** directly in your code editor using Motion for AI. ## Basic animations The key to using Motion with Tailwind CSS is to let each library do what it does best. - **Tailwind CSS**'s utility classes for static and responsive styling. - **Motion**'s animation props like `animate` and `layout` for animation. Motion animates by applying inline styles, or via native browser animations - both of which override Tailwind CSS classes. This separation is partly why the two work so well together. Here's a basic example of a button with a hover effect. Tailwind styles the button, while Motion handles the interactivity. ``` import { motion } from "motion/react"; function Button() { return ( Click Me! ); } ``` ## Responsive animations It's possible to make an animation responsive to screen size by combining Tailwind CSS's ability to set responsive CSS variables together with Motion's ability to animate those variables. To start, we can define our initial values like so: ``` ``` Motion can also generate these curves at runtime or on the server. The [CSS spring animation guide](https://motion.dev/docs/css) covers React Server Components, Astro, Vue and CSS-in-JS. ## Troubleshooting ### My animation is moving weirdly If you find that an Motion x Tailwind CSS animation is stuttery, or moving weirdly in some way, usually there's a conflict between the Motion animation and a pre-existing Tailwind transition class. To fix, ensure that the element has no `transition-` class applied, for instance `transition-all` etc. --- Source: https://motion.dev/docs/base-ui # Base UI & Motion Animate Base UI components with Motion. [Base UI](https://base-ui.com/) is a component library for React that's rapidly growing in popularity. It's possible to animate almost all Base UI components with Motion, and in this guide we'll explore how. Live example: https://examples.motion.dev/react/base-tabs ## Setup `motion` components By default, Base UI components render and control their own DOM elements. However most components provide [the ](https://base-ui.com/react/handbook/composition#composing-custom-react-components)`render`[ prop](https://base-ui.com/react/handbook/composition#composing-custom-react-components) that allows you to switch this out for a `motion`[ component](https://motion.dev/docs/react-motion-component). ``` import { Menu } from "@base-ui-components/react/menu" import { motion } from "motion/react" function Component() { return ( } /> ) } ``` ## Exit animations In most situations, you can animate Base UI components as they leave the DOM using `AnimatePresence` and the `exit` prop, as usual: ``` {open && ( } /> )} ``` However, some Base UI components like `ContextMenu` and `Popover` control this conditional rendering themselves. To add exit animations to these components, we must: - Hoist their `open` state - Add `keepMounted` to their `Portal` component - Conditionally render the `Portal` component with `AnimatePresence` A component's `open` state can be hoisted by defining it manually with `useState`: ``` const [open, setOpen] = useState(false) return ( ``` Then, conditionally render the `Portal` (with a `keepMounted` prop) as a child of `AnimatePresence`: ``` return ( Open menu {open && ( ``` We can then add an exit animation via a `motion` component rendered via a `render` prop: ``` function App() { const [open, setOpen] = useState(false) return ( Open menu {open && ( } > {/* Children */} ``` **Note:** `Portal` will keep the tree mounted as long as Base UI detects animations on an element using element.getAnimations(). Motion will run `opacity`, `transform`, `filter`, and `clipPath` animations via hardware acceleration, so ensure at least one of these values is used for the exit animation. ## Examples Live example: https://examples.motion.dev/react/base-progress [Motion+](https://motion.dev/plus) unlocks the source code to the full vault of Motion examples. It's a one-time payment, lifetime update membership that also unlocks a creative animation library containing components like `Cursor` and `AnimateNumber`. Check out all the [Motion x Base UI examples](https://motion.dev/examples?platform=react&category=base-ui). Motion+ also includes a custom LLM ruleset for Motion x Base UI to improve the way your AI editor will integrate the two libraries. Live example: https://examples.motion.dev/react/base-dialog --- Source: https://motion.dev/docs/radix # Radix UI & Motion Animate Radix UI components with Motion. [Radix](https://www.radix-ui.com/primitives) is one of the most popular component libraries for React, with pre-built, accessible components for common UI patterns like Accordion, Switch etc. It doesn't come with animations out of the box, but in this guide we'll show how to integrate Motion for React with Radix UI to add a layer of polish to these components. In this guide, we'll learn how to use `motion`[ components](https://motion.dev/docs/react-motion-component) with Radix primitives, as well as specific setups for exit and layout animations. Live example: https://examples.motion.dev/react/number-radix-slider ## Setup `motion` components with Radix Most Radix components render and control their own DOM elements. But they also provide [the ](https://www.radix-ui.com/primitives/docs/guides/composition)`asChild`[ prop](https://www.radix-ui.com/primitives/docs/guides/composition) that, when set to `true`, will make the component use the first provided child as its DOM node instead. By passing a `motion`[ component](https://motion.dev/docs/react-motion-component) as this child, we can now use all of its animation props as normal: ``` {isOpen && } ``` By default Radix tends to control state like this `isOpen` internally. However, it provides some helper props for us to track or control this state externally. For instance, the Tooltip component provides the `open` and `onOpenChange` props, which makes it easy to track the tooltip state: ``` const [isOpen, setOpen] = useState(false) return ( ``` Now we can use this state to conditionally render the tooltip contents. ``` {isOpen && ( ``` This is to ensure `motion` components know to perform layout animations when the state changes. You can even pass this state to `layoutDependency` for better performance. ``` ``` ## Radix x Motion examples Live example: https://examples.motion.dev/react/radix-toast [Motion+](https://motion.dev/plus) is a one-time payment, lifetime membership that gains you access to the source code of an ever-growing library of [Motion examples](https://motion.dev/examples), as well as Motion UI components like `Cursor` and `AnimateNumber`. Check out all the [Motion x Radix examples](https://motion.dev/examples?platform=react&category=radix). Live example: https://examples.motion.dev/react/radix-tabs --- Source: https://motion.dev/docs/react-accessibility # Accessibility Respect users' Reduced Motion preferences with the reducedMotion option and useReducedMotion hook. Animations can have serious usability implications, even inducing motion sickness in some people. All modern operating systems provide a setting called "Reduced Motion", where people can indicate they prefer less physical motion, either because of personal preference or because they can suffer from motion sickness. There are already some excellent guides about *why* and *how* we should design accessible animations, like those at [A List Apart](http://alistapart.com/article/designing-safer-web-animation-for-motion-sensitivity/) and [Smashing Magazine](https://www.smashingmagazine.com/2018/04/designing-accessibility-inclusion/). The main takeaways are that for users with "Reduced Motion" enabled, we should keep educational transitions but be aware of motion sickness. That means replacing transform animations on large elements with opacity transitions, disabling auto-playing videos, and disabling parallax animations. Motion for React provides APIs that make it simple to respect these people's preferences. In this guide, we'll learn how to use the `reducedMotion` option and `useReducedMotion` hook to make our animations accessible. ## Automatic The `reducedMotion` option can be set on `MotionConfig` to define how you want to adhere to the Reduced Motion setting. By setting `reducedMotion` it to `"user"`, all `motion` components will **automatically** disable transform and [layout animations](https://motion.dev/docs/react-layout-animations), while preserving the animation of other values like `opacity` and `backgroundColor`. ``` import { MotionConfig } from "framer-motion" export function App({ children }) { return ( {children} ) } ``` [Framer](https://framer.com), the no-code site builder, uses this API and exposes it via a setting in `Site Settings > Accessibility`. Additionally, you can allow a user to override Reduced Motion for just your site by setting reducedMotion to `"always"` or `"never"` based on their profile. ``` ``` ## Manual While `reducedMotion` is a great blanket tool for ensuring accessible animations across your whole site, more bespoke solutions can be created with [the ](https://motion.dev/docs/react-use-reduced-motion)`useReducedMotion`[ hook](https://motion.dev/docs/react-use-reduced-motion). This hook returns `true`/`false` depending on whether your visitor has Reduced Motion enabled. ``` import { useReducedMotion } from "framer-motion" // In your componentconst shouldReduceMotion = useReducedMotion() ``` We can use this boolean to fix some of the common accessibility problems, like the following. ### Replace `transform` with `opacity` When Reduced Motion is enabled on iOS, the operating system still animates between states to help users transition between each context. But instead of the default scale and x/y animations, it fades content in and out. We can achieve this in Motion by passing different values to `animate` based on whether `useReducedMotion` returns `true` or not. ``` function Sidebar({ isOpen }) { const shouldReduceMotion = useReducedMotion() let animate if (isOpen) { animate = shouldReduceMotion ? { opacity: 1 } : { x: 0 } } else { animate = shouldReduceMotion ? { opacity: 0 } : { x: "-100%" } } return } ``` ### Disable auto-playing video `useReducedMotion` isn’t only compatible with the Motion. It returns a simple boolean, so you can use it for any purpose, like disabling the autoplay of a background `video` element: ``` function BackgroundVideo() { const shouldReduceMotion = useReducedMotion() return