opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Mockups
  4. Phone
Back to Mockups

Components / Mockups

Phone

Free Mockups React component — PhoneMockupCard. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

iPhone 15 Pro frame with Dynamic Island and a full-screen preview slot. Pass variant for purple, orange, white, titanium, or cherry finishes. Use visibleRatio to crop from the top, and showDynamicIsland to toggle the island and camera.

Preview

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/mockups/phone-mockup-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { PhoneMockupCard } from "@/components/mockups/phone-mockup-card";

    <PhoneMockupCard variant="orange" visibleRatio={2 / 3} showDynamicIsland={false} />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/mockups/phone-mockup-card.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import {
forwardRef,
type ComponentPropsWithoutRef,
type ReactNode,
} from "react";
 
import { cn } from "@/lib/cn";
 
const phoneFrameVariants = {
purple: {
frame: "bg-[#4a4254]",
button: "bg-[#423d4d]",
},
orange: {
frame: "bg-[#d4845a]",
button: "bg-[#cc7a50]",
},
white: {
frame: "bg-[#e4e4e8]",
button: "bg-[#d8d8de]",
},
titanium: {
frame: "bg-[#9a9590]",
button: "bg-[#8f8a85]",
},
cherry: {
frame: "bg-[#d49aa8]",
button: "bg-[#ca90a0]",
},
} as const;
 
type PhoneFrameVariant = keyof typeof phoneFrameVariants;
 
const PHONE_ASPECT = 70.6 / 146.6;
 
type PhoneMockupCardProps = Readonly<
ComponentPropsWithoutRef<"div"> & {
variant?: PhoneFrameVariant;
// Fraction of the frame height to show (0–1). Default 1 = full phone. Crops from the top.
visibleRatio?: number;
// Show or hide the Dynamic Island and camera dot.
showDynamicIsland?: boolean;
}
>;
 
const buttonClass = (color: string) =>
cn("absolute w-[2px] rounded-l-sm", color);
 
function PhoneSideButtons({
frame,
}: Readonly<{
frame: (typeof phoneFrameVariants)[PhoneFrameVariant];
}>) {
return (
<>
{/* Mute switch */}
<div
className={cn(
buttonClass(frame.button),
"top-[15.5%] -left-[2px] h-[3.2%]",
)}
aria-hidden="true"
/>
{/* Volume up */}
<div
className={cn(
buttonClass(frame.button),
"top-[21%] -left-[2px] h-[7.2%]",
)}
aria-hidden="true"
/>
{/* Volume down */}
<div
className={cn(
buttonClass(frame.button),
"top-[30.5%] -left-[2px] h-[7.2%]",
)}
aria-hidden="true"
/>
{/* Power button */}
<div
className={cn(
buttonClass(frame.button),
"top-[23%] -right-[2px] h-[11.5%] rounded-l-none rounded-r-sm",
)}
aria-hidden="true"
/>
</>
);
}
 
function PhoneScreen({
children,
showDynamicIsland,
}: Readonly<{
children: ReactNode;
showDynamicIsland: boolean;
}>) {
return (
<div className="relative h-full w-full overflow-hidden rounded-[2.5rem] bg-black">
{/* Screen — thin ~4px bezel on all sides */}
<div className="absolute inset-[3.5px] overflow-hidden rounded-[2.3rem] bg-white">
<div className="relative h-full w-full">{children}</div>
 
{showDynamicIsland ? (
<div
className="absolute top-[9px] left-1/2 z-20 h-[20px] w-[66px] -translate-x-1/2 rounded-full bg-black"
aria-hidden="true"
>
<div
className="absolute top-1/2 right-[5px] block h-[8px] w-[8px] shrink-0 -translate-y-1/2 rounded-full bg-[#6a90c8]/20"
aria-hidden="true"
/>
</div>
) : null}
 
{/* Home indicator */}
<div
className="absolute bottom-[5.5px] left-1/2 z-20 h-[3px] w-[32%] -translate-x-1/2 rounded-full bg-black/20"
aria-hidden="true"
/>
</div>
</div>
);
}
 
// iPhone proportions: 70.6 x 146.6 mm — thin uniform bezels
export const PhoneMockupCard = forwardRef<HTMLDivElement, PhoneMockupCardProps>(
(
{
className,
children,
variant = "purple",
visibleRatio = 1,
showDynamicIsland = true,
style,
...props
},
ref,
) => {
const frame = phoneFrameVariants[variant];
const ratio = Math.min(1, Math.max(0, visibleRatio));
const isCropped = ratio < 1;
 
const phoneFrameClassName = cn(
"relative w-[256px] rounded-[2.6rem] p-[2px]",
frame.frame,
);
 
const fullPhoneFrameClassName = cn(
phoneFrameClassName,
"aspect-[70.6/146.6]",
);
 
if (!isCropped) {
return (
<div
ref={ref}
data-slot="phone-mockup-card"
data-variant={variant}
className={cn(fullPhoneFrameClassName, className)}
style={style}
{...props}
>
<PhoneSideButtons frame={frame} />
<PhoneScreen showDynamicIsland={showDynamicIsland}>
{children}
</PhoneScreen>
</div>
);
}
 
return (
<div
ref={ref}
data-slot="phone-mockup-card"
data-variant={variant}
data-visible-ratio={ratio}
className={cn("relative w-[260px] overflow-hidden", className)}
style={{
aspectRatio: PHONE_ASPECT / ratio,
...style,
}}
{...props}
>
{/* Frame + screen — clipped from top */}
<div className="absolute inset-0 right-[2px] left-[2px] overflow-hidden">
<div
className={cn(phoneFrameClassName, "w-full shrink-0")}
style={{ height: `${100 / ratio}%` }}
>
<PhoneScreen showDynamicIsland={showDynamicIsland}>
{children}
</PhoneScreen>
</div>
</div>
 
{/* Side buttons — outside clip layer, full phone height */}
<div
className="pointer-events-none absolute top-0 left-[2px] z-10 w-[256px] shrink-0"
style={{ height: `${100 / ratio}%` }}
>
<PhoneSideButtons frame={frame} />
</div>
</div>
);
},
);
 
PhoneMockupCard.displayName = "PhoneMockupCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/mockups/phone-mockup-card.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.