Device Mockup
Browser and iPhone mockups for React and Tailwind CSS, drawn entirely in CSS and inline SVG with no images. Wrap a screenshot or live components in a Safari window or a phone with a dynamic island; frames scale with container queries and can tilt slightly toward the cursor.
- Pure CSS & SVG
- Safari + iPhone frames
- Container-query scaling
- Optional 3D tilt
- prefers-reduced-motion
import { PhoneMockup, SafariMockup } from "@/components/dusk/device-mockup/device-mockup";
function Dashboard() {
return (
<div className="flex size-full bg-background text-foreground">
<aside className="hidden w-[18%] flex-col gap-2 border-r border-white/5 p-[2%] sm:flex">
<span className="mb-2 h-3 w-2/3 rounded bg-white/25" />
{[0, 1, 2, 3, 4].map((i) => (
<span key={i} className="h-2 rounded bg-white/10" style={{ width: `${85 - i * 9}%` }} />
))}
</aside>
<div className="flex flex-1 flex-col gap-[3%] p-[3%]">
<div className="grid grid-cols-3 gap-[3%]">
{["24.8k", "1,204", "3.6%"].map((value) => (
<div key={value} className="rounded-lg border border-white/5 bg-white/[0.03] p-[6%]">
<span className="block h-1.5 w-1/2 rounded bg-white/15" />
<span className="mt-2 block text-[clamp(10px,2cqw,20px)] font-semibold tabular-nums">{value}</span>
</div>
))}
</div>
<div className="flex flex-1 items-end gap-[1.5%] rounded-lg border border-white/5 bg-white/[0.03] p-[3%]">
{[35, 55, 42, 70, 52, 88, 64, 78, 58, 95, 72, 84].map((h, i) => (
<span key={i} className="flex-1 rounded-t bg-white/20" style={{ height: `${h}%` }} />
))}
</div>
</div>
</div>
);
}
function MobileApp() {
return (
<div className="flex size-full flex-col gap-3 bg-background px-[8%] pt-[22%] text-foreground">
<span className="text-[clamp(10px,7cqw,22px)] font-semibold">Overview</span>
<div className="rounded-2xl border border-white/10 bg-white/[0.04] p-4">
<span className="block text-[clamp(8px,4cqw,13px)] text-muted-foreground">Revenue</span>
<span className="block text-[clamp(12px,9cqw,28px)] font-bold tabular-nums">$12,480</span>
</div>
{[0, 1, 2].map((i) => (
<div key={i} className="flex items-center gap-3 rounded-xl bg-white/[0.05] p-3">
<span className="size-6 shrink-0 rounded-full bg-white/15" />
<span className="h-2 flex-1 rounded bg-white/15" />
</div>
))}
</div>
);
}
export default function DeviceMockupDemo() {
return (
<div className="relative w-full max-w-2xl pb-6 sm:pr-16">
<SafariMockup url="app.acme.dev/overview">
<Dashboard />
</SafariMockup>
<PhoneMockup className="absolute right-0 -bottom-2 hidden w-[26%] sm:block">
<MobileApp />
</PhoneMockup>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/device-mockup.json1. Install the dependencies.
npm install motion lucide-react2. Copy the source into
components/dusk/device-mockup/device-mockup.tsx.device-mockup.tsx "use client"; import * as React from "react"; import { motion, useMotionValue, useReducedMotion, useSpring, useTransform, type MotionValue, } from "motion/react"; import { ChevronLeft, ChevronRight, Lock, Plus, RotateCw, Share } from "lucide-react"; import { cn } from "@/lib/utils"; const spring = { stiffness: 200, damping: 22, mass: 0.6 }; /** Pointer-driven 3D tilt on motion values: no React renders while it moves. */ function useTilt(maxTilt: number) { const reduceMotion = useReducedMotion(); const px = useMotionValue(0.5); const py = useMotionValue(0.5); const rotateX = useSpring(useTransform(py, [0, 1], [maxTilt, -maxTilt]), spring); const rotateY = useSpring(useTransform(px, [0, 1], [-maxTilt, maxTilt]), spring); const enabled = maxTilt > 0 && !reduceMotion; const handlers = enabled ? { onPointerMove: (event: React.PointerEvent<HTMLElement>) => { if (event.pointerType !== "mouse") return; const rect = event.currentTarget.getBoundingClientRect(); px.set((event.clientX - rect.left) / rect.width); py.set((event.clientY - rect.top) / rect.height); }, onPointerLeave: () => { px.set(0.5); py.set(0.5); }, } : {}; return { enabled, handlers, rotateX, rotateY }; } function tiltAmount(tilt: boolean | number | undefined) { if (tilt === true) return 4; if (typeof tilt === "number") return Math.max(0, tilt); return 0; } type TiltStyle = { rotateX: MotionValue<number>; rotateY: MotionValue<number> }; interface MockupBaseProps extends Omit<React.ComponentProps<"div">, "children"> { /** What appears on the screen: any element, a component or a screenshot. */ children?: React.ReactNode; /** Convenience for a screenshot. Ignored when `children` are passed. */ src?: string; /** Alt text for `src`. Describe the screenshot, or pass "" if it's decorative. */ alt?: string; /** Tilt toward the cursor on hover (mouse only). `true` = 4°, or a max angle in degrees. */ tilt?: boolean | number; /** Classes for the screen area. */ screenClassName?: string; } function Screen({ children, src, alt }: Pick<MockupBaseProps, "children" | "src" | "alt">) { if (children !== undefined) return <>{children}</>; if (src) { // eslint-disable-next-line @next/next/no-img-element -- framework-agnostic registry component return <img src={src} alt={alt ?? ""} className="block size-full object-cover object-top" draggable={false} />; } return null; } /** Outer wrapper: a sized container with perspective that receives pointer events. */ function Stage({ tilt, className, style, children, ...props }: Omit<React.ComponentProps<"div">, "children"> & { tilt: ReturnType<typeof useTilt>; children: (style: TiltStyle | undefined) => React.ReactNode; }) { return ( <div className={cn("@container relative w-full", className)} style={{ perspective: tilt.enabled ? 1200 : undefined, ...style }} {...tilt.handlers} {...props} > {children(tilt.enabled ? { rotateX: tilt.rotateX, rotateY: tilt.rotateY } : undefined)} </div> ); } export interface SafariMockupProps extends MockupBaseProps { /** Text in the address bar. */ url?: string; /** Screen aspect ratio (width / height), e.g. `16 / 10`. */ ratio?: number; } /** * A browser window drawn in CSS and inline SVG: traffic lights, navigation * buttons and an address bar. Wrap any content or a screenshot in it. The * chrome adapts to its own width with container queries, so it scales from a * phone column to a full hero. */ export function SafariMockup({ url = "duskui.com", ratio = 16 / 10, tilt, src, alt, screenClassName, className, children, ...props }: SafariMockupProps) { const t = useTilt(tiltAmount(tilt)); return ( <Stage tilt={t} data-slot="safari-mockup" className={cn("max-w-4xl", className)} {...props}> {(style) => ( <motion.div style={style} className="overflow-hidden rounded-[clamp(8px,1.6cqw,14px)] border border-white/10 bg-[#141414] shadow-xl will-change-transform" > <div aria-hidden className="flex h-[clamp(28px,5.5cqw,44px)] items-center gap-[clamp(6px,1.4cqw,12px)] border-b border-white/[0.06] bg-[#1b1b1b] px-[clamp(8px,1.8cqw,16px)] text-white/55" > <span className="flex shrink-0 gap-[clamp(4px,0.8cqw,8px)]"> {["bg-[#ff5f57]", "bg-[#febc2e]", "bg-[#28c840]"].map((color) => ( <span key={color} className={cn("size-[clamp(7px,1.2cqw,12px)] rounded-full", color)} /> ))} </span> <span className="hidden shrink-0 items-center gap-1 @md:flex [&_svg]:size-4"> <ChevronLeft /> <ChevronRight className="opacity-50" /> </span> <span className="mx-auto flex h-[66%] min-w-0 max-w-md flex-1 items-center justify-center gap-1.5 rounded-[clamp(4px,0.8cqw,8px)] bg-white/[0.06] px-3 text-[clamp(9px,1.5cqw,13px)] text-white/60"> <Lock className="size-[1em] shrink-0" /> <span className="truncate">{url}</span> <RotateCw className="ml-auto hidden size-[1em] shrink-0 opacity-60 @lg:block" /> </span> <span className="hidden shrink-0 items-center gap-3 @md:flex [&_svg]:size-4"> <Share /> <Plus /> </span> </div> <div className={cn("relative overflow-hidden bg-background", screenClassName)} style={{ aspectRatio: ratio }} > <Screen src={src} alt={alt}> {children} </Screen> </div> </motion.div> )} </Stage> ); } export interface PhoneMockupProps extends MockupBaseProps { /** Show the status bar (time, signal, battery) over the screen. */ statusBar?: boolean; /** Time in the status bar. */ time?: string; /** Classes for the status bar, e.g. `text-black` over a light screen. */ statusBarClassName?: string; /** Frame finish. */ color?: "graphite" | "silver" | "mint"; } const finishes = { graphite: "bg-[linear-gradient(145deg,#3a3d3c,#151716_45%,#2a2d2c)]", silver: "bg-[linear-gradient(145deg,#e7e9e8,#a7abaa_45%,#d9dcdb)]", mint: "bg-[linear-gradient(145deg,#3a4743,#171d1b_45%,#2d3835)]", } as const; /** * An iPhone-style frame drawn in CSS: rounded titanium body, side buttons, * a dynamic island and an optional status bar. Every dimension is a share of * the frame's width (container query units), so it scales cleanly at any size. * The screen content sits full-bleed under the island, like a real phone. */ export function PhoneMockup({ statusBar = true, time = "9:41", statusBarClassName, color = "graphite", tilt, src, alt, screenClassName, className, children, ...props }: PhoneMockupProps) { const t = useTilt(tiltAmount(tilt)); const dark = color !== "silver"; return ( <Stage tilt={t} data-slot="phone-mockup" className={cn("max-w-[300px]", className)} {...props}> {(style) => ( <motion.div style={style} className={cn( "relative rounded-[16cqw] p-[1.3cqw] will-change-transform", "shadow-xl", finishes[color] )} > {/* Side buttons: action, volume up/down on the left; power on the right. */} {[ ["left", "17%", "6%"], ["left", "26%", "10%"], ["left", "38%", "10%"], ["right", "28%", "15%"], ].map(([side, top, height]) => ( <span key={`${side}-${top}`} aria-hidden className={cn( "absolute w-[1.1cqw] rounded-full", finishes[color], side === "left" ? "-left-[0.7cqw]" : "-right-[0.7cqw]" )} style={{ top, height }} /> ))} {/* Black bezel ring */} <div className="rounded-[14.8cqw] bg-black p-[2.6cqw]"> <div className={cn( "relative aspect-[9/19.5] overflow-hidden rounded-[12.4cqw] bg-background", screenClassName )} > <Screen src={src} alt={alt}> {children} </Screen> {statusBar && ( <div aria-hidden className={cn( "pointer-events-none absolute inset-x-0 top-0 z-10 flex h-[13cqw] items-center justify-between px-[8cqw] text-[4.4cqw] font-semibold text-white", statusBarClassName )} > <span className="w-[16cqw] text-center tabular-nums">{time}</span> <span className="flex items-center gap-[1.4cqw]"> <svg viewBox="0 0 18 12" className="h-[2.9cqw] fill-current"> <rect x="0" y="8" width="3" height="4" rx="0.8" /> <rect x="5" y="5.5" width="3" height="6.5" rx="0.8" /> <rect x="10" y="3" width="3" height="9" rx="0.8" /> <rect x="15" y="0" width="3" height="12" rx="0.8" /> </svg> <svg viewBox="0 0 16 12" className="h-[2.9cqw] fill-current"> <path d="M8 2.2c2.3 0 4.4.9 6 2.4l1.2-1.3A10.3 10.3 0 0 0 8 .4 10.3 10.3 0 0 0 .8 3.3L2 4.6a8.5 8.5 0 0 1 6-2.4Zm0 3.6c1.3 0 2.5.5 3.4 1.3l1.2-1.3A6.7 6.7 0 0 0 8 4a6.7 6.7 0 0 0-4.6 1.8l1.2 1.3c.9-.8 2.1-1.3 3.4-1.3Zm0 3.6c-.5 0-1 .2-1.3.5L8 11.6l1.3-1.7c-.3-.3-.8-.5-1.3-.5Z" /> </svg> <svg viewBox="0 0 27 12" className="h-[2.9cqw]"> <rect x="0.5" y="0.5" width="23" height="11" rx="3.2" fill="none" stroke="currentColor" strokeOpacity="0.45" /> <rect x="2.2" y="2.2" width="17" height="7.6" rx="1.8" fill="currentColor" /> <path d="M25 4v4c.8-.3 1.4-1.1 1.4-2S25.8 4.3 25 4Z" fill="currentColor" fillOpacity="0.45" /> </svg> </span> </div> )} {/* Dynamic island */} <span aria-hidden className="absolute top-[3.2cqw] left-1/2 z-20 h-[9cqw] w-[30cqw] -translate-x-1/2 rounded-full bg-black" /> </div> </div> {/* Edge highlight on the frame */} <span aria-hidden className={cn( "pointer-events-none absolute inset-0 rounded-[inherit] ring-1 ring-inset", dark ? "ring-white/10" : "ring-black/10" )} /> </motion.div> )} </Stage> ); }
Usage
import { PhoneMockup, SafariMockup } from "@/components/dusk/device-mockup/device-mockup"
export function ProductShot() {
return (
<>
<SafariMockup url="acme.com" src="/screenshot.png" alt="Acme dashboard" tilt />
<PhoneMockup className="max-w-[260px]">
<MobileScreen />
</PhoneMockup>
</>
)
}Examples
Safari window with tilt
tilt rotates the window a few degrees toward a mouse cursor (pass a number for the max angle). The toolbar drops its navigation buttons when the window is narrow.
Components for product teams
Hover with a mouse: the window tilts slightly toward the cursor.
Get startedimport { ArrowRight } from "lucide-react";
import { SafariMockup } from "@/components/dusk/device-mockup/device-mockup";
export default function DeviceMockupSafariDemo() {
return (
<SafariMockup url="duskui.com" tilt className="max-w-xl">
<div className="flex size-full flex-col items-center justify-center gap-2 p-4 text-center sm:gap-3 sm:p-6">
<span className="rounded-full border px-3 py-1 text-xs text-muted-foreground">Version 2.0</span>
<p className="text-lg font-semibold tracking-tight sm:text-3xl">Components for product teams</p>
<p className="max-w-xs text-sm text-muted-foreground max-sm:hidden">
Hover with a mouse: the window tilts slightly toward the cursor.
</p>
<span className="mt-1 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-foreground">
Get started <ArrowRight className="size-4" aria-hidden />
</span>
</div>
</SafariMockup>
);
}Phone finishes
graphite, silver and mint (a muted sage) frames. Every dimension is a share of the frame's width, so the island, bezel and status bar stay in proportion at any size. Use statusBarClassName to darken the status bar over light screens.
import { PhoneMockup, type PhoneMockupProps } from "@/components/dusk/device-mockup/device-mockup";
function Screen({ title, light }: { title: string; light?: boolean }) {
return (
<div
className="flex size-full flex-col gap-2 px-[9%] pt-[24%]"
style={{ background: light ? "#f5f5f5" : "#0a0a0a", color: light ? "#0a0a0a" : "#fff" }}
>
<span className="text-[clamp(9px,7cqw,18px)] font-semibold">{title}</span>
<span className="aspect-[4/3] rounded-xl" style={{ background: light ? "#0000000f" : "#ffffff14" }} />
{[80, 60, 70].map((w) => (
<span key={w} className="h-1.5 rounded" style={{ width: `${w}%`, background: light ? "#0001" : "#fff2" }} />
))}
</div>
);
}
const phones: { color: PhoneMockupProps["color"]; title: string; light?: boolean }[] = [
{ color: "graphite", title: "Music" },
{ color: "silver", title: "Photos", light: true },
{ color: "mint", title: "Wallet" },
];
export default function DeviceMockupPhonesDemo() {
return (
<div className="grid w-full max-w-xl grid-cols-3 items-end gap-4 sm:gap-8">
{phones.map((phone) => (
<PhoneMockup
key={phone.title}
color={phone.color}
tilt
statusBarClassName={phone.light ? "text-black" : undefined}
>
<Screen title={phone.title} light={phone.light} />
</PhoneMockup>
))}
</div>
);
}API Reference
Both components accept any <div> attribute. Set the size with className (e.g. max-w-xl).
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | What appears on the screen: components, a video or an image. |
| src / alt | string | — | Shortcut for a screenshot. Ignored when children are passed. |
| tilt | boolean | number | false | Tilt toward the cursor on hover (mouse only). true = 4°, or a max angle in degrees. |
| screenClassName | string | — | Classes for the screen area. |
| url | string | "duskui.com" | SafariMockup: text in the address bar. |
| ratio | number | 16 / 10 | SafariMockup: screen aspect ratio. |
| color | "graphite" | "silver" | "mint" | "graphite" | PhoneMockup: frame finish. |
| statusBar | boolean | true | PhoneMockup: show time, signal and battery over the screen. |
| time | string | "9:41" | PhoneMockup: time in the status bar. |
| statusBarClassName | string | — | PhoneMockup: classes for the status bar, e.g. text-black. |
Accessibility
- All frame chrome (toolbar, island, status bar, buttons) is
aria-hidden; only your screen content is exposed. - Describe screenshots with
alt, or passalt=""when they are decorative. - The tilt reacts to a mouse only, never touch, and is disabled with prefers-reduced-motion.
- Pointer tracking uses motion values, so moving the cursor never re-renders React.