3D buttons
Five takes on depth: a pressable body, a perspective tilt, stacked layers, an embossed face and a lifting hover. Each is sized and token-driven.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/buttons-3dDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/buttons-3d.tsx"use client"
import * as React from "react"
import { motion, useReducedMotion, type HTMLMotionProps } from "motion/react"
import { cn } from "@/lib/utils"
/* 3D button family: 5 variations on depth and press. All are sized, use framer-motion, take colour ONLY from semantic tokens and are reduced-motion safe. The shadows derive from tokens through color-mix (a black/white mix for the shadow, not a colour). */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const sizes: Record<StyledSize, string> = {
sm: "h-8 gap-1.5 rounded-md px-3 text-sm",
md: "h-9 gap-2 rounded-lg px-4 text-sm",
lg: "h-10 gap-2 rounded-lg px-5 text-sm",
xl: "h-12 gap-2.5 rounded-xl px-6 text-base",
}
const base =
"relative inline-flex shrink-0 select-none items-center justify-center font-medium whitespace-nowrap outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
type Props = HTMLMotionProps<"button"> & { size?: StyledSize }
/* Push: a token-derived shadow under the body that presses down on click. */
export function PushButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
return (
<motion.button
data-slot="styled-button"
whileHover={reduce ? undefined : { y: -2 }}
whileTap={reduce ? undefined : { y: 3 }}
transition={{ type: "spring", stiffness: 500, damping: 24 }}
className={cn(
base,
sizes[size],
"bg-brand text-brand-foreground shadow-[0_4px_0_0_color-mix(in_oklab,var(--brand)_70%,black)]",
className
)}
{...props}
>
{children}
</motion.button>
)
}
/* Tilt: a 3D perspective tilt at a fixed angle rather than towards the cursor. */
export function TiltButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
return (
<motion.button
data-slot="styled-button"
style={{ transformPerspective: 600 }}
whileHover={reduce ? undefined : { rotateX: 18, rotateY: -12, scale: 1.04 }}
whileTap={reduce ? undefined : { scale: 0.97 }}
transition={{ type: "spring", stiffness: 300, damping: 18 }}
className={cn(base, sizes[size], "bg-primary text-primary-foreground", className)}
{...props}
>
{children}
</motion.button>
)
}
/* Layered: token yuzeylerden istiflenmis katmanli govde; basinca toplanir. */
export function LayeredButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
return (
<motion.button
data-slot="styled-button"
whileHover={reduce ? undefined : { x: -1, y: -1 }}
whileTap={reduce ? undefined : { x: 4, y: 4 }}
transition={{ type: "spring", stiffness: 500, damping: 26 }}
className={cn(
base,
sizes[size],
"border border-border bg-secondary text-secondary-foreground shadow-[3px_3px_0_0_var(--surface-3),6px_6px_0_0_var(--surface-2)]",
className
)}
{...props}
>
{children}
</motion.button>
)
}
/* Emboss: token yuzeyde is golgelerle kabartma; basinca oyuk gorunur. */
export function EmbossButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
return (
<motion.button
data-slot="styled-button"
whileTap={reduce ? undefined : { scale: 0.98 }}
transition={{ type: "spring", stiffness: 500, damping: 26 }}
className={cn(
base,
sizes[size],
"bg-secondary text-secondary-foreground shadow-[inset_0_1px_0_0_color-mix(in_oklab,var(--secondary)_60%,white),inset_0_-2px_0_0_color-mix(in_oklab,var(--secondary)_70%,black)] active:shadow-[inset_0_2px_4px_0_color-mix(in_oklab,var(--secondary)_70%,black)]",
className
)}
{...props}
>
{children}
</motion.button>
)
}
/* Lift: rises on hover and the shadow beneath grows (a floating-card feel). */
export function LiftButton({ className, size = "md", children, ...props }: Props) {
const reduce = useReducedMotion()
return (
<motion.button
data-slot="styled-button"
whileHover={reduce ? undefined : { y: -4 }}
whileTap={reduce ? undefined : { y: -1, scale: 0.98 }}
transition={{ type: "spring", stiffness: 350, damping: 20 }}
className={cn(
base,
sizes[size],
"bg-primary text-primary-foreground shadow-md transition-shadow duration-(--motion-base) hover:shadow-xl",
className
)}
{...props}
>
{children}
</motion.button>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Push
A solid bottom body; the button presses down on tap.
import { PushButton } from "@/components/ui/buttons-3d"
<PushButton>Push</PushButton>Tilt
A fixed 3D perspective tilt on hover.
import { TiltButton } from "@/components/ui/buttons-3d"
<TiltButton>Tilt</TiltButton>Layered
Stacked token surfaces behind the face; they collapse on press.
import { LayeredButton } from "@/components/ui/buttons-3d"
<LayeredButton>Layered</LayeredButton>Emboss
Inner light and shadow raise the face; it dents on press.
import { EmbossButton } from "@/components/ui/buttons-3d"
<EmbossButton>Emboss</EmbossButton>Lift
The button lifts on hover as its shadow grows.
import { LiftButton } from "@/components/ui/buttons-3d"
<LiftButton>Lift</LiftButton>ai2 3D buttons: 5 styled variations on the token system
The ai2 3D buttons are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around depth and tactile press. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion springs drive the press, the perspective tilt, the layer collapse and the lift. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the springs are disabled and the buttons stay flat and still.
What is in the ai2 3D buttons?
5 exports in one file: Push, Tilt, Layered, Emboss and Lift. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion springs drive the press, the perspective tilt, the layer collapse and the lift.
- Reduced-motion aware: Under prefers-reduced-motion, the springs are disabled and the buttons stay flat and still.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The 3D buttons sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.