---
title: "Add to Cart"
description: "An add to cart button that morphs into a quantity stepper: the pill resizes, minus and plus open out from the centre, and the count rolls."
category: "Micro Interactions"
publishedAt: "2026-11-16"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/micro-interactions/add-to-cart"
markdown: "https://beui.dev/micro-interactions/add-to-cart.md"
license: "MIT"
---

# Add to Cart

> An add to cart button that morphs into a quantity stepper: the pill resizes, minus and plus open out from the centre, and the count rolls.

## Install

```bash
npx shadcn@latest add @beui/add-to-cart
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { AddToCart } from "@/components/motion/add-to-cart";

export function AddToCartUsage() {
  return <AddToCart />;
}
```

## API Reference

### AddToCart

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `quantity` | `number` | — | No | Items in the cart, for controlled use. 0 shows the add button. |
| `defaultQuantity` | `number` | `0` | No | The initial quantity when uncontrolled. Default: 0 |
| `onQuantityChange` | `((quantity: number) => void)` | — | No | Called with the new quantity when an item is added or removed. |
| `max` | `number` | `99` | No | Most items one cart line can hold. |
| `disabled` | `boolean` | `false` | No | Blocks adding and stepping, and dims the button. Default: false |
| `labels` | `Partial<{ add: string; increase: string; decrease: string; remove: string; quantity: string; }>` | — | No | Override any built-in string, e.g. for translation. |
| `sound` | `boolean` | `false` | No | Play a drop on add, a tick per step and a crumple on remove. Off by default; a `SoundProvider` can mute it app-wide. |
| `morphWidth` | `boolean` | `true` | No | Resize the pill to fit each face (default). Turn it off and give it a width, for example `w-full`, to keep one size in both states. |
| `className` | `string` | — | No | Classes merged onto the root element. |

## About Add to Cart

Add to Cart is a React button built with Framer Motion that turns into a quantity stepper once an item is in the cart. The pill resizes between the two faces, minus and plus open out from the centre around a rolling count, the minus becomes a trash icon on the last item, and removing it folds the stepper back into the button. To keep one size in both states, set morphWidth to false and give it a width, such as w-full.

### When to use it

- A product card or page adds items to a cart.
- A food ordering menu lets people pick quantities inline.
- A ticket or seat picker sets how many to buy.

### Accessibility

Every control is a real button with a clear name: Add to cart, Add one, Remove one and Remove from cart. The quantity is announced in a polite live region, and focus moves to the new face when a press swaps it, so keyboard users never lose their place. With reduced motion the faces crossfade without movement.

### FAQ

**How do I sync it with my cart?**

Pass quantity and onQuantityChange to control it from your cart state.

**Can I limit the quantity?**

Yes. Set max; the plus button disables at the limit.

## Source

- Registry detail: https://beui.dev/r/add-to-cart
- Raw source: https://beui.dev/r/add-to-cart/raw
- GitHub: https://github.com/starc007/ui-components
