A pure CSS mobile device emulator for React
Installation β’ Basic Usage β’ API β’ Supported Devices β’ Examples β’ Contributing β’ License
- π Zero Dependencies - Built with pure CSS
- π± Multiple Devices - iPhone, Galaxy, Pixel and more
- π Orientation Modes - Portrait and landscape
- πΌοΈ Realistic Frames - Precise device frame visualization
- π Adjustable Scale - Resize as needed
- π External URL Support - Load any URL inside the emulator
- π§© Highly Customizable - Custom device specifications
npm install react-mobile-emulator
# or
yarn add react-mobile-emulator
# or
pnpm add react-mobile-emulator
import { MobileDeviceEmulator } from 'react-mobile-emulator';
function App() {
return (
<MobileDeviceEmulator
deviceType="iphone13"
orientation="portrait"
scale={1}
>
<div>Your content here</div>
</MobileDeviceEmulator>
);
}
import { MobileDeviceEmulator } from 'react-mobile-emulator';
function ExternalUrlExample() {
return (
<MobileDeviceEmulator deviceType="galaxyS21" url="https://example.com" />
);
}
Prop | Type | Default | Description |
---|---|---|---|
deviceType |
'iphone13' | 'iphone14Pro' | 'galaxyS21' | 'pixel6' | 'custom' |
'iphone13' |
Device type to emulate |
orientation |
'portrait' | 'landscape' |
'portrait' |
Device orientation |
children |
ReactNode |
- | Content to display inside device frame |
url |
string |
- | URL to load in an iframe (alternative to children) |
scale |
number |
1 |
Optional CSS scale factor |
customSpecs |
DeviceSpecs |
- | Custom device specifications (for deviceType='custom') |
showFrame |
boolean |
true |
Display device frame |
showButtons |
boolean |
true |
Display device buttons (power, volume) |
className |
string |
- | Custom container class name |
backgroundColor |
string |
'#f5f5f5' |
Optional background color |
type DeviceType =
| 'iphone13'
| 'iphone14Pro'
| 'galaxyS21'
| 'pixel6'
| 'custom';
type Orientation = 'portrait' | 'landscape';
type DeviceSpecs = {
width: number;
height: number;
borderRadius: number;
bezelColor: string;
bezelThickness: number;
notchType?: 'dynamic-island' | 'notch' | 'punch-hole' | 'none';
notchWidth?: number;
notchHeight?: number;
};
Device | Type | Resolution | Notes |
---|---|---|---|
iPhone 13 | 'iphone13' |
390 Γ 844 | Standard notch |
iPhone 14 Pro | 'iphone14Pro' |
393 Γ 852 | Dynamic Island |
Galaxy S21 | 'galaxyS21' |
360 Γ 800 | Punch-hole |
Pixel 6 | 'pixel6' |
393 Γ 830 | Punch-hole |
Custom | 'custom' |
User-defined | Requires customSpecs |
<MobileDeviceEmulator
deviceType="custom"
customSpecs={{
width: 375,
height: 812,
borderRadius: 40,
bezelColor: '#000000',
bezelThickness: 10,
notchType: 'none',
}}
>
<YourApp />
</MobileDeviceEmulator>
import { useState } from 'react';
import { MobileDeviceEmulator, Orientation } from 'react-mobile-emulator';
function ResponsiveExample() {
const [orientation, setOrientation] = useState < Orientation > 'portrait';
const [scale, setScale] = useState(1);
return (
<div>
<div className="controls">
<button
onClick={() =>
setOrientation(
orientation === 'portrait' ? 'landscape' : 'portrait'
)
}
>
Toggle Orientation
</button>
<input
type="range"
min={0.5}
max={1.5}
step={0.1}
value={scale}
onChange={e => setScale(Number(e.target.value))}
/>
</div>
<MobileDeviceEmulator
deviceType="iphone14Pro"
orientation={orientation}
scale={scale}
>
<YourApp />
</MobileDeviceEmulator>
</div>
);
}
<MobileDeviceEmulator deviceType="pixel6" showFrame={false}>
<YourApp />
</MobileDeviceEmulator>
Contributions, issues, and feature requests are welcome!
- Fork this repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'feat: Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Crafted with β€οΈ by Daniel Angelo for the React Community