I've often used CSS to render physical devices on the canvas, wrapping {children} around interactive apps. div-phone packages that idea into a responsive iPhone frame for React, built with Tailwind CSS.
The default phone finish is black, although the latest 1.1.0 release allows you to also use the color prop to change color to orange.
Install
npm install div-phoneTailwind setup
div-phone ships Tailwind utility classes rather than a compiled stylesheet.
Tailwind CSS v4 ignores node_modules during automatic source detection, so
register the package as a source in your main CSS file:
@import 'tailwindcss';@source "../node_modules/div-phone/dist";The @source path is relative to the CSS file. Adjust the number of ../
segments for your project structure.
If your project uses PostCSS, install the optional integration packages:
npm install --save-dev postcss @tailwindcss/postcssThen configure the Tailwind v4 plugin:
export default { plugins: { '@tailwindcss/postcss': {}, },};Usage
The black frame is the default phone color:
import { Phone } from 'div-phone';export const BlackPhone = () => ( <Phone> <div className="h-full w-full bg-neutral-900 text-white">Your app goes here.</div> </Phone>);Select the orange finish with color="orange":
import { Phone } from 'div-phone';export const OrangePhone = () => ( <Phone color="orange"> <div className="h-full w-full bg-neutral-900 text-white">Your app goes here.</div> </Phone>);Props
children: React content rendered inside the phone screen.className: Optional classes added to the outer wrapper.color: The phone frame finish, either"black"(default) or"orange".shadow: Applies the outer shadow and defaults totrue.
The color union is also exported for use in your own component APIs:
import type { PhoneColor } from 'div-phone';Requirements
- React 17, 18, or 19
- Tailwind CSS 4
- PostCSS 8 and
@tailwindcss/postcss4 when using the optional PostCSS integration - Node.js 16.14 or newer
Troubleshooting
If the phone renders without its frame styling, confirm that:
- Your application imports Tailwind with
@import "tailwindcss". - Your CSS includes an
@sourcepath that resolves tonode_modules/div-phone/dist. - You restarted the development server after installing or updating the package.
Using div-phone for something cool? Tag me on 𝕏 with what you've built!