OTP Input
A one-time code field: one real input drawn as cells. Digits rise into place, paste and SMS autofill just work, and the cells turn to ink once complete.
View codeA textarea whose label folds up, whose height eases to fit the text, and whose ring fills as you near the limit, with the characters left in the last fifth.
With your AI
Say it to your AI. It gets the exact code below, not its best guess, and knows where it goes.
Use the Kodza Textarea for the message in my contact form.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-textarea" data-max="280">
<label class="kodza-textarea__box">
<textarea class="kodza-textarea__input" name="message" rows="2" placeholder=" " maxlength="280" required minlength="10" data-error="Ten characters at least. Bugs need context."></textarea>
<span class="kodza-textarea__label">What broke?</span>
</label>
<p class="kodza-textarea__foot">
<span class="kodza-textarea__note"><span class="kodza-textarea__hint">Steps to reproduce are a love language.</span><span class="kodza-textarea__error" aria-live="polite"></span></span>
<span class="kodza-textarea__count" aria-hidden="true"><svg viewBox="0 0 20 20"><circle class="kodza-textarea__ring-track" cx="10" cy="10" r="8"/><circle class="kodza-textarea__ring" cx="10" cy="10" r="8" pathLength="1"/></svg><span class="kodza-textarea__left"></span></span>
</p>
</div>
<div class="kodza-textarea">
<label class="kodza-textarea__box">
<textarea class="kodza-textarea__input" name="notes" rows="2" placeholder=" " disabled>Release notes are locked until Friday. Not on our watch.</textarea>
<span class="kodza-textarea__label">Release notes</span>
</label>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Textarea
A textarea in the Text Field box: the label folds up as you type, the height eases to fit
the text instead of jumping (no scrollbar, no handle), and a ring fills as you near the
limit (data-max, or maxlength); the characters left show up in the last fifth, and the ring
firms up at zero. The hint gives way to the error (data-error) without anything moving.
Everything is tuned with the --kz-textarea-* variables. */
.kodza-textarea {
--kz-textarea-bg: #ffffff;
--kz-textarea-fg: #0a0a0a;
--kz-textarea-muted: rgba(10, 10, 10, 0.6);
--kz-textarea-line: rgba(10, 10, 10, 0.14);
--kz-textarea-line-hover: rgba(10, 10, 10, 0.3);
--kz-textarea-soft: rgba(10, 10, 10, 0.06);
--kz-textarea-error: #0a0a0a;
--kz-textarea-radius: 12px;
--kz-textarea-pad: 16px;
--kz-textarea-ease: cubic-bezier(0.22, 1, 0.36, 1);
display: grid;
gap: 8px;
width: 100%;
max-width: 460px;
color: var(--kz-textarea-fg);
}
.kodza-textarea__box {
position: relative;
display: block;
padding: 28px var(--kz-textarea-pad) 12px;
border-radius: var(--kz-textarea-radius);
background: var(--kz-textarea-bg);
box-shadow: inset 0 0 0 1px var(--kz-textarea-line);
cursor: text;
transition: box-shadow 0.25s ease;
}
.kodza-textarea__box:hover {
box-shadow: inset 0 0 0 1px var(--kz-textarea-line-hover);
}
.kodza-textarea__box:focus-within {
box-shadow: inset 0 0 0 1.5px var(--kz-textarea-fg), 0 0 0 4px var(--kz-textarea-soft);
}
.kodza-textarea__input {
display: block;
width: 100%;
min-height: 44px;
margin: 0;
padding: 0;
overflow: hidden;
border: 0;
background: none;
color: inherit;
font: inherit;
font-size: 15px;
line-height: 22px;
outline: none;
resize: none;
}
/* The label: in the box at rest, folded up once focused or filled */
.kodza-textarea__label {
position: absolute;
top: 18px;
left: var(--kz-textarea-pad);
color: var(--kz-textarea-muted);
font-size: 15px;
line-height: 1;
pointer-events: none;
transform-origin: left top;
transition: transform 0.35s var(--kz-textarea-ease);
}
.kodza-textarea__box:focus-within .kodza-textarea__label,
.kodza-textarea__input:not(:placeholder-shown) ~ .kodza-textarea__label {
transform: translateY(-8px) scale(0.8);
}
/* The foot: hint or error on the left, the counter on the right */
.kodza-textarea__foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin: 0;
padding: 0 2px;
font-size: 13px;
line-height: 1.4;
}
.kodza-textarea__note {
display: grid;
min-width: 0;
overflow: hidden;
}
.kodza-textarea__hint,
.kodza-textarea__error {
grid-area: 1 / 1;
transition: opacity 0.25s ease, transform 0.4s var(--kz-textarea-ease);
}
.kodza-textarea__hint {
color: var(--kz-textarea-muted);
}
.kodza-textarea__error {
display: flex;
align-items: center;
gap: 6px;
color: var(--kz-textarea-error);
font-weight: 500;
opacity: 0;
transform: translateY(100%);
}
.kodza-textarea__error::before {
content: "";
flex: none;
width: 14px;
height: 14px;
background: currentColor;
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='none' stroke='black' stroke-width='1.5'/%3E%3Cpath d='M8 4.5v4.2M8 10.9v.1' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='none' stroke='black' stroke-width='1.5'/%3E%3Cpath d='M8 4.5v4.2M8 10.9v.1' stroke='black' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__box {
box-shadow: inset 0 0 0 1.5px var(--kz-textarea-error);
}
.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__hint {
opacity: 0;
transform: translateY(-100%);
}
.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__error {
opacity: 1;
transform: none;
}
/* The counter: a ring that fills, and the characters left near the end */
.kodza-textarea__count {
display: flex;
flex: none;
align-items: center;
gap: 6px;
font-family: ui-monospace, "SF Mono", Menlo, monospace;
font-size: 12px;
font-variant-numeric: tabular-nums;
color: var(--kz-textarea-muted);
}
.kodza-textarea__count svg {
width: 20px;
height: 20px;
transform: rotate(-90deg);
transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.kodza-textarea__count circle {
fill: none;
stroke-width: 2.4;
}
.kodza-textarea__ring-track {
stroke: var(--kz-textarea-soft);
}
.kodza-textarea__ring {
stroke: var(--kz-textarea-muted);
stroke-dasharray: 1;
stroke-dashoffset: calc(1 - var(--kz-used, 0));
stroke-linecap: round;
transition: stroke-dashoffset 0.2s ease, stroke 0.2s ease;
}
.kodza-textarea.is-near .kodza-textarea__ring {
stroke: var(--kz-textarea-fg);
}
.kodza-textarea.is-full .kodza-textarea__count svg {
transform: rotate(-90deg) scale(1.15);
}
.kodza-textarea__left {
display: inline-grid;
min-width: 2ch;
overflow: hidden;
text-align: right;
opacity: 0;
transform: translateX(4px);
transition: opacity 0.2s ease, transform 0.3s var(--kz-textarea-ease);
}
.kodza-textarea__left > span {
grid-area: 1 / 1;
}
.kodza-textarea.is-near .kodza-textarea__left {
color: var(--kz-textarea-fg);
opacity: 1;
transform: none;
}
/* Disabled */
.kodza-textarea__box:has(.kodza-textarea__input:disabled) {
background: var(--kz-textarea-soft);
box-shadow: none;
color: var(--kz-textarea-muted);
cursor: not-allowed;
}
.kodza-textarea__input:disabled {
cursor: not-allowed;
}
@media (prefers-reduced-motion: reduce) {
.kodza-textarea__box,
.kodza-textarea__label,
.kodza-textarea__hint,
.kodza-textarea__error,
.kodza-textarea__count svg,
.kodza-textarea__ring,
.kodza-textarea__left {
transition-duration: 0.01ms !important;
}
}
/* Theming example — on a dark background:
.dark-section .kodza-textarea {
--kz-textarea-bg: #161616;
--kz-textarea-fg: #f2f2f0;
--kz-textarea-muted: rgba(242, 242, 240, 0.62);
--kz-textarea-line: rgba(255, 255, 255, 0.14);
--kz-textarea-line-hover: rgba(255, 255, 255, 0.3);
--kz-textarea-soft: rgba(255, 255, 255, 0.07);
--kz-textarea-error: #f2f2f0;
}
*/
/* kodza-guard 9a05c8f203cf — generated by Kodza, do not edit.
Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
component. :not(#_) is always true and weighs as much as an id, so these lines win over
theme rules made of classes and tags. Customise the component through its --kz-* variables. */
/* What the browser gives, where the component sets it only in some states: at the lowest weight, so its own rules below put it back */
:where(.kodza-textarea__box):not(#_) {
color: revert;
}
/* What the browser gives, on everything the component leaves to it */
.kodza-textarea:not(#_),
.kodza-textarea__label:not(#_),
.kodza-textarea__note:not(#_),
.kodza-textarea__hint:not(#_),
.kodza-textarea__error:not(#_),
.kodza-textarea__count:not(#_),
.kodza-textarea__ring-track:not(#_),
.kodza-textarea__ring:not(#_),
.kodza-textarea__left:not(#_),
.kodza-textarea__left span:where(:not([class*="kodza-"])):not(#_) {
box-sizing: revert;
}
.kodza-textarea__box:not(#_) {
border: revert;
margin: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-textarea__input:not(#_) {
border-radius: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
white-space: revert;
}
.kodza-textarea__foot:not(#_) {
border: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-weight: revert;
font-style: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-textarea__count svg:where(:not([class*="kodza-"])):not(#_) {
border: revert;
margin: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-size: revert;
font-weight: revert;
font-style: revert;
line-height: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-textarea__count svg:where(:not([class*="kodza-"])):not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-textarea__count svg:where(:not([class*="kodza-"])):not(#_):where([hidden]) {
display: none;
}
.kodza-textarea__error:not(#_)::before {
box-sizing: revert;
}
/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */
.kodza-textarea:not(#_) {
width: min(100%, 460px);
}
.kodza-textarea__box:not(#_) {
position: relative;
display: block;
padding: 28px var(--kz-textarea-pad) 12px;
border-radius: var(--kz-textarea-radius);
background: var(--kz-textarea-bg);
box-shadow: inset 0 0 0 1px var(--kz-textarea-line);
transition: box-shadow 0.25s ease;
}
.kodza-textarea__box:hover:not(#_) {
box-shadow: inset 0 0 0 1px var(--kz-textarea-line-hover);
}
.kodza-textarea__box:focus-within:not(#_) {
box-shadow: inset 0 0 0 1.5px var(--kz-textarea-fg), 0 0 0 4px var(--kz-textarea-soft);
}
.kodza-textarea__input:not(#_) {
display: block;
width: 100%;
min-height: 44px;
margin: 0;
padding: 0;
overflow: hidden;
border: 0;
background: none;
color: inherit;
font: inherit;
font-size: 15px;
line-height: 22px;
outline: none;
resize: none;
}
.kodza-textarea__foot:not(#_) {
display: flex;
margin: 0;
padding: 0 2px;
font-size: 13px;
line-height: 1.4;
}
.kodza-textarea:has(.kodza-textarea__input[aria-invalid="true"]) .kodza-textarea__box:not(#_) {
box-shadow: inset 0 0 0 1.5px var(--kz-textarea-error);
}
.kodza-textarea__count svg:not(#_) {
transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.kodza-textarea__box:has(.kodza-textarea__input:disabled):not(#_) {
background: var(--kz-textarea-soft);
box-shadow: none;
color: var(--kz-textarea-muted);
}
.kodza-textarea__input:disabled:not(#_) {
cursor: not-allowed;
}
@media (prefers-reduced-motion: reduce) {
.kodza-textarea__box:not(#_),
.kodza-textarea__count svg:not(#_) {
transition-duration: 0.01ms !important;
}
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Textarea
// Grows the textarea to fit its text (the height eases instead of jumping), fills the counter
// ring, shows the characters left in the last fifth, and writes the error (data-error, or the
// browser's own) when the text is invalid: judged when the visitor leaves, then live.
(() => {
const SELECTOR = '.kodza-textarea';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
let uid = 0;
// One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
function mount(root, signal) {
const input = root.querySelector('.kodza-textarea__input');
const hint = root.querySelector('.kodza-textarea__hint');
const error = root.querySelector('.kodza-textarea__error');
const left = root.querySelector('.kodza-textarea__left');
if (!input) return;
const max = Number(root.dataset.max) || (input.maxLength > 0 ? input.maxLength : 0);
const id = `kodza-textarea-${++uid}`;
const described = [];
if (hint) described.push((hint.id = `${id}-hint`));
if (error) described.push((error.id = `${id}-error`));
if (described.length) input.setAttribute('aria-describedby', described.join(' '));
// The height follows the text, easing from the old height to the new one
let height = 0;
let growing = null;
const fit = (animate) => {
const from = input.offsetHeight;
input.style.height = 'auto';
const to = Math.max(input.scrollHeight, 44);
input.style.height = `${to}px`;
if (animate && !reduceMotion && height && Math.abs(to - from) > 1) {
growing?.cancel();
growing = input.animate([{ height: `${from}px` }, { height: `${to}px` }], { duration: 220, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' });
}
height = to;
};
// The characters left roll to their new number
if (left) left.replaceChildren(Object.assign(document.createElement('span'), { textContent: '' }));
const roll = (text) => {
const prev = left.lastElementChild;
if (prev.textContent === String(text)) return;
const span = Object.assign(document.createElement('span'), { textContent: text });
left.append(span);
if (reduceMotion || !root.classList.contains('is-near')) return prev.remove();
const timing = { duration: 220, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' };
prev.animate([{ transform: 'none' }, { transform: 'translateY(-110%)' }], { ...timing, fill: 'forwards' }).finished.then(() => prev.remove());
span.animate([{ transform: 'translateY(110%)' }, { transform: 'none' }], timing);
};
const count = () => {
if (!max) return;
const used = Math.min(1, input.value.length / max);
root.style.setProperty('--kz-used', used.toFixed(3));
root.classList.toggle('is-near', used >= 0.8);
root.classList.toggle('is-full', used >= 1);
if (left) roll(max - input.value.length);
};
const check = () => {
if (!error) return;
const bad = !input.validity.valid;
error.textContent = bad ? input.dataset.error || input.validationMessage : '';
input.setAttribute('aria-invalid', String(bad));
};
input.addEventListener('input', () => {
fit(true);
count();
if (input.getAttribute('aria-invalid') === 'true') check();
}, { signal });
input.addEventListener('blur', check, { signal });
window.addEventListener('resize', () => fit(false), { signal });
document.fonts?.ready.then(() => fit(false));
fit(false);
count();
}
// Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
// event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
// markup back. For themes and apps that swap content without a page load.
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
const init = (scope) => find(scope).forEach((root) => {
if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
const controller = new AbortController();
instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
mount(root, controller.signal);
root.classList.add('is-ready');
});
const destroy = (scope) => find(scope).forEach((root) => {
const instance = instances.get(root);
if (!instance) return;
instances.delete(root);
instance.controller.abort();
[...root.attributes].forEach((a) => root.removeAttribute(a.name));
instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
root.innerHTML = instance.html;
});
document.addEventListener('kodza:init', (event) => init(event.detail?.root));
document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
init();
// Loaded in <head>, the script runs before the markup exists: once more when it is parsed
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
'use client';
// Kodza — Textarea, for React. From https://kodza.dev/components/textarea/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: textarea.css and textarea.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './textarea.css';
export type TextareaProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars" | "max"> & {
/** data-max on the root (default: 280) */
max?: "280";
/** Settings, as CSS variables on the root */
vars?: {
/** default: #ffffff */
"--kz-textarea-bg"?: string | number;
/** default: #0a0a0a */
"--kz-textarea-fg"?: string | number;
/** default: rgba(10, 10, 10, 0.6) */
"--kz-textarea-muted"?: string | number;
/** default: rgba(10, 10, 10, 0.14) */
"--kz-textarea-line"?: string | number;
/** default: rgba(10, 10, 10, 0.3) */
"--kz-textarea-line-hover"?: string | number;
/** default: rgba(10, 10, 10, 0.06) */
"--kz-textarea-soft"?: string | number;
/** default: #0a0a0a */
"--kz-textarea-error"?: string | number;
/** default: 12px */
"--kz-textarea-radius"?: string | number;
/** default: 16px */
"--kz-textarea-pad"?: string | number;
/** default: cubic-bezier(0.22, 1, 0.36, 1) */
"--kz-textarea-ease"?: string | number;
};
className?: string;
};
export function Textarea({ max = "280", vars, className, style, ...rest }: TextareaProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-textarea", className].filter(Boolean).join(' ');
// Everything the markup is made of: when it changes, React gets a fresh element (see the top)
const key = JSON.stringify([classes, max, vars, style, rest]);
// Starts the script on this element once React has rendered it, stops it when it goes
useEffect(() => {
const root = ref.current;
let live = true;
// @ts-ignore: a plain script, no types to find
import('./textarea.js').then(() => {
if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
});
return () => {
live = false;
document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
};
}, [key]);
return (
<div key={key} {...rest} className={classes} data-max={max} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<label className="kodza-textarea__box">
<textarea className="kodza-textarea__input" name="message" rows={2} placeholder=" " maxLength={280} required minLength={10} data-error="Ten characters at least. Bugs need context." />
{' '}
<span className="kodza-textarea__label">What broke?</span>
</label>
<p className="kodza-textarea__foot">
<span className="kodza-textarea__note">
<span className="kodza-textarea__hint">Steps to reproduce are a love language.</span>
<span className="kodza-textarea__error" aria-live="polite" />
</span>
{' '}
<span className="kodza-textarea__count" aria-hidden="true">
<svg viewBox="0 0 20 20">
<circle className="kodza-textarea__ring-track" cx="10" cy="10" r="8" />
<circle className="kodza-textarea__ring" cx="10" cy="10" r="8" pathLength="1" />
</svg>
<span className="kodza-textarea__left" />
</span>
</p>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.