Phone Input, animated React component
A phone number field with a searchable country picker that formats the number in each country's own pattern. Digits drop into place with a small overshoot, a hairline fills toward a complete number, a check draws itself when it's valid and the country chip flips over when you change country.
- Free
- Cards
- Spring
Types with a key click for every character, in sync with the text. The click stays off until you switch it on.
Like Phone Input? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Phone Input stays free.
Play with it
Move the controls and watch it change. Copy code gives you a snippet with only the props you changed.
Type a number, or pick a country.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| defaultCountry | string | "US" | ISO 3166-1 alpha-2 code of the country selected at first. |
| label | string | — | Visible label above the field; also its accessible name. |
| placeholder | string | — | Placeholder for the number. Defaults to an example in the country's format. |
| minDigits | number | — | Digits needed before the number counts as valid. Defaults to the country's full length. |
| countries | Country[] | COUNTRIES | The countries to offer: iso, name, code, max digits and an optional # mask. |
| onChange | (value: PhoneInputValue) => void | — | Called with { iso, code, number, isValid } when the user types or picks a country. |
| autoplay | boolean | false | Types a few example numbers, switching country between them, until someone touches it. |
| className | string | — | Extra classes for the 340px-wide wrapper. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry
Run this once per project. It writes the Nexus UI entry into
components.jsonfor you:npx shadcn@latest registry add "@nexus-labs=https://www.nexus-ui.com/api/registry/{name}"Type it exactly as shown.
{name}is filled in by the CLI with the component you ask for, so you never replace it.
- 3
Add the component
Run this from your project root. It adds the component, the helpers it imports and its npm packages.
npx shadcn@latest add @nexus-labs/phone-input
- 4
Check what was added
With a project made as in the Quick Start (a
src/folder), these files land in it:components/phone-input/index.tsphone-input.tsx - 5
Copying by hand? Skip the registry
Instead of steps 2 and 3 you can copy the files yourself, with no registry and no API key. Step 1 still applies, so that
cn()exists. Install the packages:npm install framer-motion
Then show the source and create each file at the path it gives:
- 6
Use it in a page
Installing only adds the files. Import the component in a page and render it. The Usage tab on the preview shows a fuller example with props:
// src/app/page.tsx import { PhoneInput, type PhoneInputValue } from "@/components/phone-input"; export default function Page() { return ( <main> <PhoneInput /> </main> ); }
Like Phone Input? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Phone Input stays free.
About Phone Input
Phone Input is an animated international phone field: a searchable country selector with flags and dial codes that opens with a Framer Motion spring, next to a number input with simple length validation. Typing in the dropdown filters the country list. Use it in signup forms, checkout flows and contact pages; for strict number validation, pair it with a library such as libphonenumber-js.
Good for
- Signup and registration forms
- Checkout and payment pages
- Contact and callback request forms
- Onboarding flows requiring phone verification
Phone Input questions
How do I read the entered number?
Pass `onChange`; it receives `{ iso, code, number, isValid }` whenever the country or digits change.
How does validation work?
Only digits are accepted, capped at each country's maximum length, and the number counts as valid once it reaches `minDigits` (default 7). It is a length check, not full libphonenumber validation.
Which countries are included?
The exported `COUNTRIES` list has 29 countries; add entries there to support more. Set the starting country with `defaultCountry` as an ISO code such as "GB".
Can I use it with the keyboard?
Yes. Enter, Space or ArrowDown on the country button opens the list with its search box focused, Escape closes it, and each country is a button you can Tab to.