Kinetic OTP Input
A one-time-code field made of single cells. It advances as you type, accepts a pasted code and fires an event when it is full.
- <kt-kinetic-otp>
- Inputs
- No framework
The code
Copy the Kinetic OTP Input
Fastest: press Copy on the card above for one complete file. To build it into your own
project, use the files below: the markup, the styles, this component’s script and the shared
effects script (effects.js) that every component uses.
<kt-kinetic-otp label="Verification code" length="6"></kt-kinetic-otp>
<kt-kinetic-otp label="Backup code" length="8" mode="text" value="K4F9"></kt-kinetic-otp>
<kt-kinetic-otp label="PIN" length="4" mask value="1234" error></kt-kinetic-otp>
kt-kinetic-otp {
display: block;
width: 100%;
max-width: 340px;
}
.kt-otp {
--_color: var(--kt-accent);
--_ink: var(--kt-accent-ink);
--_err: color-mix(in srgb, #dc2626 72%, var(--kt-surface-ink));
position: relative;
padding: 12px 14px 14px;
border-radius: var(--kt-surface-radius);
border-style: solid;
border-width: var(--kt-card-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: var(--kt-surface-bg);
color: var(--kt-surface-ink);
box-shadow: var(--kt-comp-shadow);
transition: border-color 160ms ease, box-shadow 180ms ease, border-width 150ms ease;
}
.kt-otp-label {
display: block;
margin-bottom: 9px;
font-family: var(--font-mono);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
color: var(--kt-surface-muted);
}
.kt-otp-cells {
display: flex;
gap: 6px;
}
.kt-otp-cell {
flex: 1 1 0;
min-width: 0;
max-width: 48px;
height: 48px;
padding: 0;
margin: 0;
border-radius: min(var(--kt-radius-btn), 14px);
border-style: solid;
border-width: var(--kt-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: color-mix(in srgb, var(--kt-surface-ink) 6%, transparent);
color: var(--kt-surface-ink);
font-family: var(--font-mono);
font-size: 20px;
font-weight: 700;
line-height: 1;
text-align: center;
text-transform: uppercase;
caret-color: var(--_color);
outline: 0;
box-shadow: none;
transition: border-color 150ms ease, background-color 150ms ease, box-shadow 170ms ease;
}
.kt-otp-cell.kt-otp-gap {
margin-left: 8px;
}
.kt-otp-cell:hover:not(:disabled) {
border-color: var(--kt-comp-border, var(--kt-surface-ink));
}
.kt-otp-cell.is-filled {
background: color-mix(in srgb, var(--_color) 12%, transparent);
}
.kt-otp-cell:focus-visible {
border-color: var(--kt-comp-border, var(--_color));
background: var(--kt-surface-bg);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--_color) 30%, transparent);
}
.kt-otp-cell:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.kt-otp.is-error .kt-otp-cell {
border-color: var(--_err);
}
.kt-otp.is-complete:not(.is-error) .kt-otp-cell {
border-color: var(--kt-comp-border, var(--_color));
}
.kt-otp-status {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
@media (max-width: 360px) {
.kt-otp-cell { height: 42px; font-size: 18px; }
.kt-otp-cells { gap: 4px; }
}
/* VFX */
[data-vfx="sakuga"] .kt-otp-cell.is-popping { animation: kt-otp-pop 300ms var(--ease-overshoot); }
[data-vfx="elastic"] .kt-otp-cell.is-popping { animation: kt-otp-jelly 420ms cubic-bezier(0.34, 1.56, 0.64, 1); }
[data-vfx="glitch"] .kt-otp-cell.is-popping { animation: kt-otp-glitch 180ms steps(4, end); }
[data-vfx="neon"] .kt-otp-cell.is-popping {
box-shadow: 0 0 14px 1px color-mix(in srgb, var(--_color) 80%, transparent);
animation: kt-otp-pop 280ms var(--ease-snap);
}
[data-vfx="ink"] .kt-otp-cell.is-popping { animation: kt-otp-ink 300ms var(--ease-overshoot); }
[data-vfx="neon"] .kt-otp.is-complete .kt-otp-cell {
box-shadow: 0 0 10px color-mix(in srgb, var(--_color) 55%, transparent);
}
[data-vfx="sakuga"] .kt-otp.is-celebrating .kt-otp-cells,
[data-vfx="neon"] .kt-otp.is-celebrating .kt-otp-cells { animation: kt-otp-pop 360ms var(--ease-overshoot); }
[data-vfx="elastic"] .kt-otp.is-celebrating .kt-otp-cells { animation: kt-otp-jelly 460ms cubic-bezier(0.34, 1.56, 0.64, 1); }
[data-vfx="glitch"] .kt-otp.is-celebrating .kt-otp-cells { animation: kt-otp-glitch 220ms steps(4, end); }
[data-vfx="ink"] .kt-otp.is-celebrating .kt-otp-cells { animation: kt-otp-ink 340ms var(--ease-overshoot); }
@keyframes kt-otp-pop {
0% { transform: scale(0.9); }
45% { transform: scale(1.08); }
100% { transform: scale(1); }
}
@keyframes kt-otp-jelly {
0% { transform: scale(0.9, 1.08); }
35% { transform: scale(1.07, 0.95); }
68% { transform: scale(0.98, 1.02); }
100% { transform: scale(1, 1); }
}
@keyframes kt-otp-glitch {
0% { transform: translate(-2px, 1px) skewX(-8deg); }
50% { transform: translate(2px, -1px) skewX(6deg); }
100% { transform: translate(0, 0) skewX(0); }
}
@keyframes kt-otp-ink {
0% { transform: scale(1.06, 0.92) rotate(-2deg); }
55% { transform: scale(0.97, 1.04) rotate(1deg); }
100% { transform: scale(1, 1) rotate(0); }
}
class KtKineticOtp extends HTMLElement {
static get observedAttributes() {
return ["length", "value", "label", "mode", "mask", "error", "disabled", "sfx"];
}
constructor() {
super();
this._rendered = false;
this._uid = `kt-otp-${Math.random().toString(36).slice(2, 8)}`;
this._cells = [];
this._chars = [];
this._popTimer = null;
this._lastJoined = null;
}
connectedCallback() {
if (!this._rendered) {
this.render();
this._rendered = true;
}
this.syncAttributes();
}
disconnectedCallback() {
clearTimeout(this._popTimer);
}
attributeChangedCallback(name) {
if (!this._rendered) return;
if (name === "length" || name === "mode" || name === "mask") this.render();
this.syncAttributes();
}
get length() {
const n = parseInt(this.getAttribute("length") || "6", 10);
return Number.isFinite(n) ? Math.min(Math.max(n, 2), 10) : 6;
}
get mode() { return this.getAttribute("mode") === "text" ? "text" : "numeric"; }
get label() { return this.getAttribute("label") || "Verification code"; }
get disabled() { return this.hasAttribute("disabled"); }
get value() { return this._chars.join(""); }
set value(val) { this.setAttribute("value", String(val ?? "")); }
get sfx() { return this.getAttribute("sfx") ?? "ピッ!"; }
clean(text) {
const s = String(text || "");
return (this.mode === "numeric" ? s.replace(/\D/g, "") : s.replace(/[^a-zA-Z0-9]/g, "").toUpperCase()).split("");
}
render() {
this.innerHTML = "";
const wrap = document.createElement("div");
wrap.className = "kt-otp";
wrap.innerHTML = `
<span class="kt-otp-label" id="${this._uid}-label"></span>
<div class="kt-otp-cells" role="group" aria-labelledby="${this._uid}-label"></div>
<span class="kt-otp-status" role="status" aria-live="polite"></span>
`;
this._wrap = wrap;
this._labelEl = wrap.querySelector(".kt-otp-label");
this._box = wrap.querySelector(".kt-otp-cells");
this._status = wrap.querySelector(".kt-otp-status");
const n = this.length;
if (this._chars.length !== n) this._chars = Array.from({ length: n }, (_, i) => this._chars[i] || "");
this._cells = [];
for (let i = 0; i < n; i++) {
const input = document.createElement("input");
input.className = "kt-otp-cell";
input.type = this.hasAttribute("mask") ? "password" : "text";
input.inputMode = this.mode === "numeric" ? "numeric" : "text";
input.autocomplete = i === 0 ? "one-time-code" : "off";
input.spellcheck = false;
input.setAttribute("autocapitalize", "off");
input.setAttribute("aria-label", `Digit ${i + 1} of ${n}`);
if (this.mode === "text") input.setAttribute("aria-label", `Character ${i + 1} of ${n}`);
if (n >= 6 && n % 2 === 0 && i === n / 2) input.classList.add("kt-otp-gap");
input.addEventListener("input", (e) => this.onInput(e, i));
input.addEventListener("keydown", (e) => this.onKeydown(e, i));
input.addEventListener("paste", (e) => this.onPaste(e, i));
input.addEventListener("focus", () => {
input.select();
this._wrap.classList.add("is-focus");
});
input.addEventListener("blur", () => {
setTimeout(() => {
if (!this._cells.includes(document.activeElement)) this._wrap.classList.remove("is-focus");
}, 0);
});
input.addEventListener("pointerup", () => input.select());
this._box.appendChild(input);
this._cells.push(input);
}
this.appendChild(wrap);
}
syncAttributes() {
if (!this._box) return;
const n = this.length;
const attr = this.getAttribute("value") || "";
// the attribute only wins when it differs from what the cells already hold (typing sets it)
if (attr !== this.value) {
const chars = this.clean(attr).slice(0, n);
this._chars = Array.from({ length: n }, (_, i) => chars[i] || "");
}
this._labelEl.textContent = this.label;
const err = this.hasAttribute("error");
this._wrap.classList.toggle("is-error", err);
this._cells.forEach((c, i) => {
c.value = this._chars[i] || "";
c.disabled = this.disabled;
c.classList.toggle("is-filled", !!this._chars[i]);
if (err) c.setAttribute("aria-invalid", "true");
else c.removeAttribute("aria-invalid");
});
const complete = this._chars.every(Boolean);
this._wrap.classList.toggle("is-complete", complete);
this._lastJoined = this.value;
}
setChars(next, { focusIndex = null, announce = true } = {}) {
const n = this.length;
const prev = this.value;
this._chars = Array.from({ length: n }, (_, i) => next[i] || "");
const joined = this.value;
this._cells.forEach((c, i) => {
c.value = this._chars[i];
c.classList.toggle("is-filled", !!this._chars[i]);
});
if (this.getAttribute("value") !== joined) {
if (joined) this.setAttribute("value", joined);
else this.removeAttribute("value");
}
const complete = this._chars.every(Boolean);
this._wrap.classList.toggle("is-complete", complete);
if (focusIndex !== null) {
const t = this._cells[Math.min(Math.max(focusIndex, 0), n - 1)];
t?.focus({ preventScroll: true });
}
if (joined === prev) return;
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { value: joined, complete } }));
if (complete) {
if (announce) this._status.textContent = "Code complete";
this.dispatchEvent(new CustomEvent("complete", { bubbles: true, detail: { value: joined } }));
this.celebrate();
} else {
this._status.textContent = "";
}
}
onInput(e, i) {
const raw = e.target.value;
// a typed key replaces the cell; anything longer (autofill, IME) spreads across the cells
const chars = this.clean(e.inputType === "insertText" && e.data ? e.data : raw);
const next = this._chars.slice();
if (!chars.length) {
next[i] = "";
this.setChars(next);
return;
}
// several characters at once: autofill from the keyboard, or a fast typist
let pos = i;
for (const ch of chars) {
if (pos >= this.length) break;
next[pos++] = ch;
}
this.setChars(next, { focusIndex: Math.min(pos, this.length - 1) });
this.pop(i);
}
onKeydown(e, i) {
const n = this.length;
const focus = (k) => this._cells[Math.min(Math.max(k, 0), n - 1)]?.focus({ preventScroll: true });
if (e.key === "Backspace") {
e.preventDefault();
const next = this._chars.slice();
if (next[i]) {
next[i] = "";
this.setChars(next, { focusIndex: i });
} else if (i > 0) {
next[i - 1] = "";
this.setChars(next, { focusIndex: i - 1 });
}
} else if (e.key === "Delete") {
e.preventDefault();
const next = this._chars.slice();
next[i] = "";
this.setChars(next, { focusIndex: i });
} else if (e.key === "ArrowLeft") {
e.preventDefault();
focus(i - 1);
} else if (e.key === "ArrowRight") {
e.preventDefault();
focus(i + 1);
} else if (e.key === "Home") {
e.preventDefault();
focus(0);
} else if (e.key === "End") {
e.preventDefault();
focus(n - 1);
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && this.clean(e.key).length === 0) {
// reject characters the code cannot contain
e.preventDefault();
}
}
onPaste(e, i) {
e.preventDefault();
const text = (e.clipboardData || window.clipboardData)?.getData("text") || "";
const chars = this.clean(text);
if (!chars.length) return;
const n = this.length;
// a whole code replaces everything; a fragment fills from the current cell
const start = chars.length >= n ? 0 : i;
const next = chars.length >= n ? Array(n).fill("") : this._chars.slice();
let pos = start;
for (const ch of chars) {
if (pos >= n) break;
next[pos++] = ch;
}
this.setChars(next, { focusIndex: Math.min(pos, n - 1) });
this._cells.slice(start, pos).forEach((c, k) => setTimeout(() => this.pop(start + k), k * 25));
}
pop(i) {
if (SakugaFX.getMode() === "enterprise") return;
const c = this._cells[i];
if (!c) return;
c.classList.remove("is-popping");
void c.offsetWidth;
c.classList.add("is-popping");
setTimeout(() => c.classList.remove("is-popping"), 400);
}
celebrate() {
if (SakugaFX.getMode() === "enterprise") return;
const rect = this._box.getBoundingClientRect();
SakugaFX.emitImpact(rect.left + rect.width / 2, rect.top + rect.height / 2, readAccent(this._wrap), {
sfx: this.sfx,
scale: 0.9,
sfxY: rect.top - 4
});
this._wrap.classList.remove("is-celebrating");
void this._wrap.offsetWidth;
this._wrap.classList.add("is-celebrating");
clearTimeout(this._popTimer);
this._popTimer = setTimeout(() => this._wrap.classList.remove("is-celebrating"), 520);
}
}
customElements.define("kt-kinetic-otp", KtKineticOtp);
function contrastInk(hex) {
const clean = hex.replace("#", "");
if (clean.length !== 6) return "#ffffff";
const r = parseInt(clean.slice(0, 2), 16);
const g = parseInt(clean.slice(2, 4), 16);
const b = parseInt(clean.slice(4, 6), 16);
const lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return lum > 0.6 ? "#09090b" : "#ffffff";
}
function readAccent(el) {
const val = getComputedStyle(el).getPropertyValue("--kt-accent").trim();
return val || "#09090b";
}
class SakugaVFXEngine {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.rafId = null;
this.lastTime = 0;
this.textEnabled = false;
this.textOverride = "";
this.vfxTextColor = "auto";
this.resize();
window.addEventListener("resize", () => this.resize());
}
attach(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.resize();
}
resize() {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
this.canvas.width = Math.floor(window.innerWidth * dpr);
this.canvas.height = Math.floor(window.innerHeight * dpr);
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
getMode() {
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return "enterprise";
return document.documentElement.getAttribute("data-vfx") || "enterprise";
}
wake() {
if (this.rafId !== null) return;
this.lastTime = performance.now();
const tick = (now) => {
const dt = Math.min((now - this.lastTime) / 1000, 0.05);
this.lastTime = now;
this.render(dt);
if (this.items.length > 0) {
this.rafId = requestAnimationFrame(tick);
} else {
this.rafId = null;
this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
}
};
this.rafId = requestAnimationFrame(tick);
}
emitBurst(x, y, color, { count = 14, speed = 240, spread = Math.PI * 2, baseAngle = 0, shards = true } = {}) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < count; i++) {
const angle = baseAngle + (Math.random() - 0.5) * spread;
const vel = speed * (0.45 + Math.random() * 0.75);
this.items.push({
kind: shards && i % 3 === 0 ? "shard" : "spark",
x, y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - (spread > 4 ? 35 : 0),
gravity: 400,
drag: 0.94,
size: 3 + Math.random() * 4,
rot: Math.random() * Math.PI * 2,
vrot: (Math.random() - 0.5) * 14,
life: 0,
maxLife: 0.32 + Math.random() * 0.22,
color
});
}
this.wake();
}
emitShockwave(x, y, color, maxRadius = 64) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "ring", x, y, radius: 8, maxRadius, life: 0, maxLife: 0.32, color });
this.wake();
}
emitSlash(x, y, color, angle = -0.3) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "slash", x, y, angle, length: 96, life: 0, maxLife: 0.2, color });
this.wake();
}
emitSmoke(x, y, color, dirX = 0) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < 4; i++) {
this.items.push({
kind: "smoke",
x: x + (Math.random() - 0.5) * 8,
y: y + (Math.random() - 0.5) * 8,
vx: dirX * (50 + Math.random() * 70) + (Math.random() - 0.5) * 35,
vy: -20 - Math.random() * 50,
size: 5 + Math.random() * 5,
life: 0,
maxLife: 0.34 + Math.random() * 0.16,
color
});
}
this.wake();
}
emitPixels(x, y, color, count = 14) {
if (this.getMode() !== "glitch") return;
for (let i = 0; i < count; i++) {
const angle = Math.floor(Math.random() * 8) * (Math.PI / 4);
const vel = 120 + Math.random() * 200;
this.items.push({
kind: "pixel",
x: x + (Math.random() - 0.5) * 18,
y: y + (Math.random() - 0.5) * 12,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel,
size: 4 + Math.floor(Math.random() * 5),
life: 0,
maxLife: 0.24 + Math.random() * 0.14,
color
});
}
this.wake();
}
emitScanline(x, y, color, width = 120) {
if (this.getMode() !== "glitch") return;
for (let i = -1; i <= 1; i += 2) {
this.items.push({
kind: "scanline",
x,
y: y + i * (5 + Math.random() * 6),
width,
life: 0,
maxLife: 0.18,
color
});
}
this.wake();
}
emitRays(x, y, color, count = 10, maxRadius = 72) {
if (this.getMode() !== "neon") return;
for (let i = 0; i < count; i++) {
const angle = (Math.PI * 2 * i) / count + (Math.random() - 0.5) * 0.18;
this.items.push({
kind: "ray",
x,
y,
angle,
maxRadius: maxRadius * (0.75 + Math.random() * 0.45),
life: 0,
maxLife: 0.34,
color
});
}
this.wake();
}
emitInkSplatter(x, y, color, count = 14) {
if (this.getMode() !== "ink") return;
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const vel = 110 + Math.random() * 230;
this.items.push({
kind: "inkblot",
x,
y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - 30,
gravity: 480,
drag: 0.91,
size: 2.5 + Math.random() * 5.5,
life: 0,
maxLife: 0.38 + Math.random() * 0.22,
color
});
}
// Brush arc sweep
this.items.push({
kind: "brusharc",
x,
y,
radius: 24 + Math.random() * 14,
startAngle: -Math.PI * 0.75,
endAngle: Math.PI * 0.35,
life: 0,
maxLife: 0.26,
color
});
this.wake();
}
emitMangaSFX(x, y, text, color) {
const mode = this.getMode();
const finalText = this.textOverride || text;
if (mode === "enterprise" || !this.textEnabled || !finalText || finalText === "none") return;
const fillColor = this.vfxTextColor !== "auto" ? this.vfxTextColor : color;
const outline = this.vfxTextColor !== "auto"
? contrastInk(this.vfxTextColor)
: (document.documentElement.getAttribute("data-bw") === "dark" ? "#09090b" : "#ffffff");
this.items.push({
kind: "sfx",
x: x + (Math.random() - 0.5) * 14,
y: y - 16,
vy: -48,
tilt: (Math.random() - 0.5) * 0.26,
text: finalText,
life: 0,
maxLife: 0.6,
color: fillColor,
outline
});
this.wake();
}
emitImpact(x, y, color, { sfx = "", scale = 1, dirX = 0, sfxY = y - 4 } = {}) {
const mode = this.getMode();
if (mode === "enterprise") return;
if (mode === "elastic") {
this.emitShockwave(x, y, color, Math.round(52 * scale));
this.emitSmoke(x, y, color, dirX);
} else if (mode === "glitch") {
this.emitPixels(x, y, color, Math.round(12 * scale));
this.emitScanline(x, y, color, Math.round(96 * scale));
} else if (mode === "neon") {
this.emitShockwave(x, y, color, Math.round(58 * scale));
this.emitRays(x, y, color, Math.round(9 * scale), Math.round(52 * scale));
} else if (mode === "ink") {
this.emitInkSplatter(x, y, color, Math.round(13 * scale));
} else {
this.emitShockwave(x, y, color, Math.round(50 * scale));
this.emitBurst(x, y, color, {
count: Math.round(12 * scale),
speed: Math.round(210 * scale),
spread: dirX ? 1.8 : Math.PI * 2,
baseAngle: dirX < 0 ? Math.PI : 0
});
this.emitSlash(x, y, color, -0.28);
}
this.emitMangaSFX(x, sfxY, sfx, color);
}
render(dt) {
const ctx = this.ctx;
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
const next = [];
for (const p of this.items) {
p.life += dt;
if (p.life >= p.maxLife) continue;
const t = p.life / p.maxLife;
const easeOut = 1 - Math.pow(1 - t, 3);
const alpha = Math.max(0, 1 - Math.pow(t, 2));
ctx.save();
ctx.globalAlpha = alpha;
if (p.kind === "spark" || p.kind === "shard") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.rot += p.vrot * dt;
ctx.translate(p.x, p.y);
ctx.rotate(p.rot);
ctx.fillStyle = p.color;
if (p.kind === "shard") {
const s = p.size * (1 - t * 0.4);
ctx.beginPath();
ctx.moveTo(0, -s);
ctx.lineTo(s * 0.72, 0);
ctx.lineTo(0, s);
ctx.lineTo(-s * 0.72, 0);
ctx.closePath();
ctx.fill();
} else {
ctx.beginPath();
ctx.arc(0, 0, p.size * 0.5 * (1 - t * 0.5), 0, Math.PI * 2);
ctx.fill();
}
} else if (p.kind === "ring") {
const r = p.radius + (p.maxRadius - p.radius) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineWidth = Math.max(1, 3 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.stroke();
} else if (p.kind === "slash") {
ctx.translate(p.x, p.y);
ctx.rotate(p.angle);
const len = p.length * easeOut;
const th = 4.5 * (1 - t);
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.moveTo(-len, 0);
ctx.quadraticCurveTo(0, -th, len, 0);
ctx.quadraticCurveTo(0, th, -len, 0);
ctx.fill();
} else if (p.kind === "smoke") {
p.x += p.vx * dt;
p.y += p.vy * dt;
const r = p.size * (0.8 + easeOut * 1.25);
ctx.fillStyle = p.color;
ctx.globalAlpha = 0.24 * (1 - t);
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "pixel") {
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
const s = p.size * (1 - t * 0.35);
ctx.fillRect(Math.round(p.x - s / 2), Math.round(p.y - s / 2), s, s);
} else if (p.kind === "scanline") {
const w = p.width * (0.4 + easeOut * 0.8);
ctx.fillStyle = p.color;
ctx.fillRect(p.x - w / 2, p.y, w, 2);
} else if (p.kind === "ray") {
const inner = 12 + easeOut * 16;
const outer = inner + p.maxRadius * (1 - t * 0.35);
ctx.strokeStyle = p.color;
ctx.shadowColor = p.color;
ctx.shadowBlur = 10;
ctx.lineWidth = Math.max(1, 2.8 * (1 - t));
ctx.beginPath();
ctx.moveTo(p.x + Math.cos(p.angle) * inner, p.y + Math.sin(p.angle) * inner);
ctx.lineTo(p.x + Math.cos(p.angle) * outer, p.y + Math.sin(p.angle) * outer);
ctx.stroke();
} else if (p.kind === "inkblot") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * (1 - t * 0.45), 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "brusharc") {
const sweep = p.startAngle + (p.endAngle - p.startAngle) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineCap = "round";
ctx.lineWidth = Math.max(1.5, 6 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius * (0.85 + easeOut * 0.4), p.startAngle, sweep);
ctx.stroke();
} else if (p.kind === "sfx") {
p.y += p.vy * dt * (1 - t * 0.6);
const s = t < 0.18 ? 0.55 + (t / 0.18) * 0.65 : 1.2 - (t - 0.18) * 0.25;
ctx.translate(p.x, p.y);
ctx.rotate(p.tilt);
ctx.scale(s, s);
ctx.font = '900 19px "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif';
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.lineJoin = "round";
ctx.lineWidth = 4.5;
ctx.strokeStyle = p.outline;
ctx.strokeText(p.text, 0, 0);
ctx.fillStyle = p.color;
ctx.fillText(p.text, 0, 0);
}
ctx.restore();
next.push(p);
}
this.items = next;
}
}
const SakugaFX = new SakugaVFXEngine(document.getElementById("sakuga-vfx-canvas"));
window.SakugaFX = SakugaFX;
window.readAccent = readAccent;
window.contrastInk = contrastInk;
Attributes
| Name | What it does | Default |
|---|---|---|
length | Number of cells, 2 to 10. | 6 |
value | The code entered so far. | — |
label | Text above the cells. | Verification code |
mode | "numeric" accepts digits only; "text" accepts letters and digits. | numeric |
mask | Present to hide the characters like a password. | — |
error | Present to mark the code as wrong (red cells, aria-invalid). | — |
disabled | Present when the cells cannot be used. | — |
sfx | Sound-effect text when the code is complete. | ピッ! |
Keyboard and screen readers
- The cells are grouped (role="group") under the label, and each has a name like "Digit 2 of 6".
- Typing moves to the next cell; Backspace clears the cell, or steps back and clears the previous one when empty.
- ArrowLeft and ArrowRight move between cells; Home and End jump to the first and last.
- Pasting a full code fills every cell; the first cell asks the browser for one-time-code autofill.
- Fires change with { value, complete } and a separate complete event once every cell is filled; "Code complete" is announced politely.
Styling variables
Every look is a CSS variable: --kt-accent, --kt-accent-ink, --kt-radius-btn, --kt-surface-radius, --kt-surface-bg, --kt-border-w, --kt-comp-shadow and --font-sans. The
copied file sets them all from your choices.
FAQ
Kinetic OTP Input: questions answered
How do I use the Kinetic OTP Input?
Press Copy on the card to get a complete HTML file, or copy the HTML, CSS and JavaScript tabs into your own page. In your markup the element is written as <kt-kinetic-otp>.
Which attributes does <kt-kinetic-otp> accept?
length, value, label, mode, mask, error, disabled, sfx. Each one is described in the attributes table on this page.
Is the Kinetic OTP Input accessible?
The cells are grouped (role="group") under the label, and each has a name like "Digit 2 of 6". Typing moves to the next cell; Backspace clears the cell, or steps back and clears the previous one when empty. ArrowLeft and ArrowRight move between cells; Home and End jump to the first and last. Pasting a full code fills every cell; the first cell asks the browser for one-time-code autofill. Fires change with { value, complete } and a separate complete event once every cell is filled; "Code complete" is announced politely.
Can I change the Kinetic OTP Input colors, corners and font?
Yes. Use the options on this page: accent color, border radius, background, border, shadow and Google font. The copied code already contains your choices, and every one of them is a CSS variable you can edit later.