Skip to content

Masked Input

Free

A text field that formats the value as you type: card numbers, IBANs, phones, amounts, dates, or your own pattern. A guide shows what is left to type.

  • Base UI
  • React 19
  • Tailwind CSS 4

Added Nov 9, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

Build the preset once at module level, so the mask does not rebuild, and add MaskedInputClear as a child at the end.

The sample also uses Field. One command adds them with this item:

card-number.tsx

MaskedInputControl

<div>
PropTypeDefaultDescription
classNamestring—
rounded"default""full"—
size"default""lg""sm""xs"—
maskRequiredMaskPreset<Raw>—A preset from #/lib/masks (or #/lib/phone-model). Build it once: a new object rebuilds the mask.
valuestring—The shown value (controlled). It is formatted by the mask, so "4155550132" shows formatted.
defaultValuestring—The first shown value (uncontrolled), formatted by the mask.
onValueChange—Runs on every change with the shown value, the raw value, and the checks.
guidebooleantrueThe ghost guide of the slots still to fill, while the input has focus. Default true.
rawNamestring—Also submit the raw value under this name (a hidden input), next to the shown one.
rejectFeedbackbooleantrueNudge the field 2px when the mask rejects a key. Default true.
onReject—Runs when the mask rejects a key (a letter in a number, a 13th month).
refRef<HTMLInputElement>—
...props<div> attributes—Every other attribute goes to the <div>.

MaskedInput

<div>
PropTypeDefaultDescription
classNamestring—
rounded"default""full"—
size"default""lg""sm""xs"—
maskRequiredMaskPreset<Raw>—A preset from #/lib/masks (or #/lib/phone-model). Build it once: a new object rebuilds the mask.
valuestring—The shown value (controlled). It is formatted by the mask, so "4155550132" shows formatted.
defaultValuestring""The first shown value (uncontrolled), formatted by the mask.
onValueChange—Runs on every change with the shown value, the raw value, and the checks.
guideboolean—The ghost guide of the slots still to fill, while the input has focus. Default true.
rawNamestring—Also submit the raw value under this name (a hidden input), next to the shown one.
rejectFeedbackboolean—Nudge the field 2px when the mask rejects a key. Default true.
onReject—Runs when the mask rejects a key (a letter in a number, a 13th month).
refRef<HTMLInputElement>—
addonsbooleantrueShow the start and end text of the preset (a currency symbol, "%", a unit). Default true.
...props<div> attributes—Every other attribute goes to the <div>.

MaskedInputClear

<button>
PropTypeDefaultDescription
classNamestring—
size"icon-sm""icon-xs""sm""xs"—
rounded"default""full"—
variant"dashed""default""destructive""destructive-outline""ghost""link""media""outline""secondary"—
onClick—
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.
  • Use it when a value has a fixed format.
  • Use a preset from lib/masks: pattern, currency, percent, date, time, cardNumber, iban, or hexColor.
  • Use MaskedInputClear for a button that empties the field.
  • Use rawName to also submit the raw value with a form.
EnterorSpaceOn MaskedInputClear: clears the field and puts focus back in it.

It is a native input, so a Field labels it and links its help and error text.

Each preset sets the keyboard and the autofill field.

MaskedInputClear has the name "Clear" by default. Translate it in another language.

Clear button
fade · 150ms · ease-out (0, 0, 0.2, 1) · fades in when the field has text

Built with

Installs with Masked Input

Components
Input Group
  1. AddedMasked Input, with Input Group.
Open the release