3D avatars
Five depth treatments: a coin flip, a perspective tilt, stacked layers, a shadow lift and a cube. 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/avatars-threedDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motionCopy the source
components/ui/avatars-threed.tsx"use client"
import type * as React from "react"
import { motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* 3D avatar family: 5 decorative avatars built on depth and perspective. Initials-based (no external image) - a consumer can put an <img> in place of the initials. Colour comes ONLY from tokens, size = the box scale. transformPerspective provides the 3D. Under reduced-motion the rotation and hover motion stop; the static depth (box-shadow layers) remains. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const box: Record<StyledSize, string> = {
sm: "size-8 text-xs",
md: "size-10 text-sm",
lg: "size-12 text-base",
xl: "size-16 text-lg",
}
const face =
"flex size-full items-center justify-center rounded-full bg-secondary font-medium text-secondary-foreground select-none"
type Props = React.ComponentProps<"div"> & { size?: StyledSize; initials?: string }
/* Coin: a continuously spinning coin (rotateY loop). Static under reduced. */
export function CoinAvatar({ className, size = "md", initials = "AI", ...props }: Props) {
const reduce = useReducedMotion()
return (
<div data-slot="styled-avatar" className={cn("relative inline-flex", box[size], className)} {...props}>
<motion.span
className={cn(face, "border-2 border-surface-3")}
style={{ transformPerspective: 600 }}
animate={reduce ? undefined : { rotateY: 360 }}
transition={reduce ? undefined : { duration: 3.2, ease: "linear", repeat: Infinity }}
>
{initials}
</motion.span>
</div>
)
}
/* CardTilt: a fixed 3D perspective tilt on hover. */
export function CardTiltAvatar({ className, size = "md", initials = "AI", ...props }: Props) {
const reduce = useReducedMotion()
return (
<div data-slot="styled-avatar" className={cn("relative inline-flex", box[size], className)} {...props}>
<motion.span
className={cn(face, "shadow-[0_6px_16px_-8px_color-mix(in_oklab,var(--foreground)_45%,transparent)]")}
style={{ transformPerspective: 500 }}
whileHover={reduce ? undefined : { rotateX: 18, rotateY: -18 }}
transition={{ type: "spring", stiffness: 300, damping: 18 }}
>
{initials}
</motion.span>
</div>
)
}
/* Layered: arkada kaydirilmis token katmanlar (statik derinlik). */
export function LayeredAvatar({ className, size = "md", initials = "AI", ...props }: Props) {
return (
<div data-slot="styled-avatar" className={cn("relative inline-flex", box[size], className)} {...props}>
<span aria-hidden="true" className="absolute inset-0 translate-x-1.5 translate-y-1.5 rounded-full bg-brand/25" />
<span aria-hidden="true" className="absolute inset-0 translate-x-0.5 translate-y-0.5 rounded-full bg-brand/40" />
<span className={cn(face, "relative")}>{initials}</span>
</div>
)
}
/* ShadowLift: rises on hover and its shadow grows. */
export function ShadowLiftAvatar({ className, size = "md", initials = "AI", ...props }: Props) {
const reduce = useReducedMotion()
return (
<div data-slot="styled-avatar" className={cn("group relative inline-flex", box[size], className)} {...props}>
<motion.span
className={cn(
face,
"shadow-[0_2px_6px_-2px_color-mix(in_oklab,var(--foreground)_35%,transparent)] transition-shadow duration-(--motion-base) group-hover:shadow-[0_14px_28px_-8px_color-mix(in_oklab,var(--foreground)_50%,transparent)]"
)}
whileHover={reduce ? undefined : { y: -6 }}
transition={{ type: "spring", stiffness: 300, damping: 18 }}
>
{initials}
</motion.span>
</div>
)
}
/* Cube: box-shadow katmanlariyla ince 3B derinlik (statik). */
export function CubeAvatar({ className, size = "md", initials = "AI", ...props }: Props) {
return (
<div data-slot="styled-avatar" className={cn("relative inline-flex", box[size], className)} {...props}>
<span
className={cn(
face,
"shadow-[2px_2px_0_color-mix(in_oklab,var(--foreground)_16%,transparent),4px_4px_0_color-mix(in_oklab,var(--foreground)_12%,transparent),6px_6px_0_color-mix(in_oklab,var(--foreground)_8%,transparent)]"
)}
>
{initials}
</span>
</div>
)
}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.
Coin
A coin-flip rotation in 3D.
import { CoinAvatar } from "@/components/ui/avatars-threed"
<CoinAvatar />Card tilt
A fixed perspective tilt on hover.
import { CardTiltAvatar } from "@/components/ui/avatars-threed"
<CardTiltAvatar />Layered
Stacked token layers behind the face.
import { LayeredAvatar } from "@/components/ui/avatars-threed"
<LayeredAvatar />Shadow lift
Lifts with a growing shadow on hover.
import { ShadowLiftAvatar } from "@/components/ui/avatars-threed"
<ShadowLiftAvatar />Cube
Subtle 3D depth via layered shadows.
import { CubeAvatar } from "@/components/ui/avatars-threed"
<CubeAvatar />ai2 3D avatars: 5 styled variations on the token system
The ai2 3D avatars are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around depth and perspective avatars. 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 drives the coin flip, tilt and lift with transformPerspective. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the flip and lift are disabled and the avatars stay flat.
What is in the ai2 3D avatars?
5 exports in one file: Coin, Card tilt, Layered, Shadow lift and Cube. 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 drives the coin flip, tilt and lift with transformPerspective.
- Reduced-motion aware: Under prefers-reduced-motion, the flip and lift are disabled and the avatars stay flat.
- 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 avatars 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.