Go back

div-phone

A responsive Tailwind CSS iPhone component

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-phone

Tailwind 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/postcss

Then 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

The color union is also exported for use in your own component APIs:

import type { PhoneColor } from 'div-phone';

Requirements

Troubleshooting

If the phone renders without its frame styling, confirm that:

  1. Your application imports Tailwind with @import "tailwindcss".
  2. Your CSS includes an @source path that resolves to node_modules/div-phone/dist.
  3. 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!