YL

FORM & INPUT

验证码格子输入OTP / PIN Input

几位数字各占一格,输入完自动跳下一格,粘贴时自动分拆——安全感的具象化。

中英对照

中文
验证码格子输入
英文
OTP / PIN Input
别名
一次性密码输入、验证码输入框、分格验证码
一句话
几位数字各占一格,输入完自动跳下一格,粘贴时自动分拆——安全感的具象化。

效果预览

–

适合用在哪

手机/邮箱验证码、两步验证、支付密码。

不适合:验证码位数不固定、或需要字母数字混合且很长时:分格体验变差,改用单框 + 自动格式化更合适。

和相近模式的区别

内联校验状态Input Validation States

OTP 格子管分位输入与自动跳格;校验态仍可套在整组外框(全对绿 / 全错红),但错误提示通常挂整组下方。

数字步进器Number Stepper

步进器改的是单个数值增减;OTP 是多格一次性密码,强调粘贴拆分与填满自动提交。

容易踩的坑

  • 未设 autocomplete="one-time-code" 和 inputmode="numeric",手机无法自动填充短信验证码。
  • 粘贴只填入第一格,用户需手动逐位输入 6 位数字,极易放弃。
  • 每格都没有 aria-label 标明第几位,读屏用户只听到 6 个相同的「编辑框」。

设计提示词 · Prompt

验证码格子输入(OTP Input):4-6 个等宽方格(40-52px 见方、圆角 10-12px、居中大号数字 20-24px),焦点格用品牌色描边 + 3px 12% 光晕。行为规则:输入即跳下一格;退格删除后跳回上一格;方向键可移动;粘贴整段验证码时自动拆分逐格填入;全部填满自动提交。已填格子可用浅品牌底色标记。格子间距 8-12px,中间加分隔线(-)也是常见变体。每个格子用单字符 input(maxlength=1)实现最稳。
OTP Input: 4-6 equal-width boxes (40-52px square, border radius 10-12px, centered large digits at 20-24px); the focused box uses a brand-color border + 3px 12% glow. Behavior rules: typing jumps to the next box; backspace deletes and jumps back to the previous box; arrow keys move between boxes; pasting a full code automatically splits it across boxes; auto-submit when all boxes are filled. Filled boxes can be marked with a light brand background. Box spacing 8-12px; adding a separator (-) in the middle is a common variant. Implementing each box as a single-character input (maxlength=1) is the most robust.

可复制 CSS

自包含的最小实现,粘贴到空白页面即可生效;类名可以按项目规范改名。

/* 6 格;焦点光晕;已填浅底 */
.otp {
  display: flex;
  align-items: center;
  gap: 10px;
}
.otp input {
  width: 48px;
  height: 48px;
  border: 1px solid #d1d5db;
  border-radius: 11px;
  text-align: center;
  font: 700 22px/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  background: #fff;
}
.otp input:focus {
  outline: 0;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.otp input.filled {
  background: #eef2ff;
  border-color: #c7d2fe;
}
.otp__dash {
  color: #9ca3af;
  font-size: 18px;
}

演示 HTML 结构

<div class="s">
  <div class="d-otp">
    <input value="7" readonly class="filled">
    <input value="2" readonly class="filled">
    <input placeholder="·">
    <span class="d-otp__dash">–</span>
    <input placeholder="·">
    <input placeholder="·">
  </div>
</div>

无障碍要点

  • 每个格子需要可访问名称(如「第 1 位验证码」),或用一组 aria-label 说明总位数。
  • 支持粘贴整段码;autocomplete="one-time-code" 有助于 iOS 短信自动填充。

常见问题

验证码格子输入的英文是什么?

验证码格子输入的英文是 OTP / PIN Input。

OTP / PIN Input 的中文是什么?

OTP / PIN Input 的中文是「验证码格子输入」。常见中文别名还包括 一次性密码输入、验证码输入框、分格验证码。几位数字各占一格,输入完自动跳下一格,粘贴时自动分拆——安全感的具象化。

格子尺寸取多少?

提示词 40–52px 见方,示例 48px;字号 20–24px(示例 22px),圆角 10–12px(示例 11px),间距 8–12px(示例 10px)。

一定要中间分隔线吗?

4 位常连写;6 位常见 3+3 中加 –。分隔只是视觉分组,逻辑上仍按顺序填格。

常见搭配

同一页面里经常和「验证码格子输入」一起出现的模式,可以收藏后用「组合收藏为整页提示词」一起交给 AI。

标签