API
Input
Text inputs of every type, with optional icons.
Installation
pnpm dlx zazz-ui add inputnpx zazz-ui add inputyarn dlx zazz-ui add inputbunx zazz-ui add inputAlso adds fields, which it depends on. Run zazz-ui init first if the project has no zazz/ folder yet.
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Paint the right theme (background, form controls, scrollbars) before CSS loads -->
<meta name="color-scheme" content="light dark">
<!-- Zazz styles: base layers, then fields, input in cascade order -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_layers.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_variables.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_shadows.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_breakpoints.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_reset.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_typography.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_view-transitions.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/fields/fields.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/primitives/input/input.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-sm.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-md.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-lg.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-xl.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-2xl.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-disabled.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-active.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-visible.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-focus-within.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-hover.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-checked.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-current.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-open.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-stuck.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_properties-starting.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-sm.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-md.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-lg.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-xl.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-2xl.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-disabled.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-active.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-visible.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-focus-within.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-hover.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-checked.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-current.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-open.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-stuck.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-tier-starting.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-flow.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-grid.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-spacing.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-margin.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sizing.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-typography.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-color.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-effects.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-box.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-pseudo.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_defaults.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/_utilities-sr.css">
<!-- Import map: bare specifiers in Zazz scripts resolve to pinned, SRI-checked files -->
<script type="importmap">
{
"imports": {
"signal-polyfill": "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js"
},
"integrity": {
"https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js": "sha384-0OqM7OXGT6Oz1z98u/geiFn/FUyz4iWexkXHCvbIGXRRDXl6bp6IKc0j78AQ6DEK"
}
}
</script>
<!-- Polyfill: Interest Invokers (interestfor) — native in Chromium only -->
<script type="module" src="https://cdn.jsdelivr.net/npm/invokers@2.2.2/dist/esm/production/interest.js" integrity="sha384-hR2BVNtsS7fIIMwOm+f7MY0JZfuByGhQQfevCBB6evFATKzBsTw0JzH/RxD94z2T" crossorigin="anonymous"></script>
<!-- Zazz behavior: side-effect modules by tag; the rest via module imports -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.14.2/src/base/dialog-lifecycle.js"></script>
<!-- Theme: apply the persisted (or preferred) scheme before first paint -->
<script>
(() => {
try {
// A stored choice pins the scheme with data-theme; with no choice the
// page follows the system scheme.
const storedTheme = localStorage.getItem("theme");
if (storedTheme === "dark" || storedTheme === "light") {
document.documentElement.dataset.theme = storedTheme;
}
} catch {
/* no storage access: follow the system scheme */
}
})();
</script>A <head> that loads the base layers and input with its dependencies from jsDelivr, pinned to 0.14.2. To load the whole kit in two requests, see the CDN install.
Examples
Default
We'll never sell or share your email address.
Please enter a valid email address.
<div data-ui="field">
<label data-field-slot="label" for="f-name">Name</label>
<input
data-ui="input"
id="f-name"
name="name"
type="text"
inputmode="text"
placeholder="Ada Lovelace"
autocomplete="name"
autocapitalize="words"
enterkeyhint="next"
/>
</div>
<div data-ui="field">
<label data-field-slot="label" for="f-email">Email</label>
<input
data-ui="input"
id="f-email"
name="email"
type="email"
inputmode="email"
required
placeholder="you@example.com"
autocomplete="email"
autocapitalize="off"
spellcheck="false"
enterkeyhint="next"
aria-describedby="f-email-hint"
/>
<div data-field-slot="description">
<span data-field-slot="hint" id="f-email-hint"
>We'll never sell or share your email address.</span
>
<span data-field-slot="error" role="alert">Please enter a valid email address.</span>
</div>
</div>
<div data-ui="field">
<label data-field-slot="label" for="f-phone">Phone</label>
<input
data-ui="input"
id="f-phone"
name="phone"
type="tel"
inputmode="tel"
placeholder="+1 (555) 012-3456"
autocomplete="tel"
enterkeyhint="next"
/>
</div>
<div data-ui="field">
<label data-field-slot="label" for="f-date">Datetime</label>
<input
data-ui="input"
id="f-date"
name="date"
type="datetime-local"
inputmode="none"
autocomplete="off"
/>
</div>/**
* input.css — Text input ([data-ui~="input"])
*
* @layer variables, components
* @requires _layers.css, _variables.css, _properties.css (--_*-resolved, --_focus-shadow), fields.css, _reset.css
* @uses ::-webkit-calendar-picker-indicator — date/time picker chrome (WebKit)
* @uses mask — calendar icon (not background-image, for color: currentColor)
* @uses @supports (-webkit-touch-callout: none) — iOS-only width fix for temporal
* inputs (webkit.org/b/301648)
* @uses corner-shape — superellipse corners; unsupported browsers keep plain
* rounded corners
* @uses --_touch-min (touch screens) — the field grows to the touch floor,
* and each inline side gains half of what the height grew
* @tokens --ui-input-* (@layer variables; surface colors and height read the
* --ui-field-* family directly)
*/
@layer variables {
:root {
--ui-input-w: 100%;
--ui-input-min-w: 16ch;
--ui-input-pl: var(--ui-field-px);
--ui-input-pr: var(--ui-field-px);
--ui-input-py: var(--ui-field-py);
--ui-input-font-size: var(--ui-field-font-size);
--ui-input-leading: var(--ui-field-leading);
--ui-input-border-width: var(--ui-field-border-width);
--ui-input-border-style: var(--ui-field-border-style);
--ui-input-border-color: var(--ui-field-border-color);
--ui-input-radius: var(--ui-field-radius);
--ui-input-corner-shape: var(--ui-field-corner-shape);
--ui-input-calendar-picker-color: currentColor;
--ui-input-calendar-picker-icon-size: calc(var(--spacing) * 4);
--ui-input-calendar-picker-size: calc(var(--spacing) * 6);
--ui-input-calendar-picker-radius: var(--ui-field-inset-radius);
--ui-input-calendar-picker-corner-shape: var(--ui-field-corner-shape);
--ui-input-calendar-picker-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Crect width='256' height='256' fill='none'/%3E%3Crect x='40' y='40' width='176' height='176' rx='8' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='176' y1='24' x2='176' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='80' y1='24' x2='80' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='40' y1='88' x2='216' y2='88' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3C/svg%3E");
}
}
@layer ui.components {
/* ===========================================================================
TEXT INPUTS — data-ui="input"
- One identity for every text-like type (text, search, email, number, date, …);
the type only changes the picker/keyboard, not the box.
- Shares the --ui-field-* tokens defined in fields.css so it aligns with the select,
the textarea, and [data-ui~="button"].
=========================================================================== */
:where([data-ui~="input"]) {
/* dual-mode metrics go through the registered typed pair */
--_w-len: var(--_w-resolved, var(--ui-input-w));
--_w-num: var(--_w-resolved, var(--ui-input-w));
inline-size: calc(var(--_w-len) + var(--_w-num) * var(--spacing));
--_min-w-len: var(--_min-w-resolved, var(--ui-input-min-w));
--_min-w-num: var(--_min-w-resolved, var(--ui-input-min-w));
min-inline-size: calc(var(--_min-w-len) + var(--_min-w-num) * var(--spacing));
--_h-len: var(--_h-resolved, var(--ui-field-h));
--_h-num: var(--_h-resolved, var(--ui-field-h));
/* never shorter than one line plus --ui-input-py and the border above and below,
so a small --spacing can't squeeze the text against the border. The browser
centers the text in the box; a --py utility replaces --ui-input-py here and
also pads the block axis, so the line still fits. */
--_py-len: var(--_py-resolved, var(--ui-input-py));
--_py-num: var(--_py-resolved, var(--ui-input-py));
block-size: max(
calc(var(--_h-len) + var(--_h-num) * var(--spacing)),
var(--_touch-min),
calc(
1lh + 2 *
(
var(--_py-len) + var(--_py-num) * var(--spacing) +
var(--_border-width-resolved, var(--ui-input-border-width))
)
)
);
/* half of what the touch floor added to the height, on each inline side */
--_touch-px: max(
0px,
(var(--_touch-min) - calc(var(--_h-len) + var(--_h-num) * var(--spacing))) / 2
);
--_pl-len: var(--_pl-resolved, var(--ui-input-pl));
--_pl-num: var(--_pl-resolved, var(--ui-input-pl));
padding-inline-start: calc(var(--_pl-len) + var(--_pl-num) * var(--spacing) + var(--_touch-px));
--_pr-len: var(--_pr-resolved, var(--ui-input-pr));
--_pr-num: var(--_pr-resolved, var(--ui-input-pr));
padding-inline-end: calc(var(--_pr-len) + var(--_pr-num) * var(--spacing) + var(--_touch-px));
font-size: var(--_font-size-resolved, var(--ui-input-font-size));
line-height: var(--_leading-resolved, var(--ui-input-leading));
color: var(--_text-resolved, var(--ui-field-text));
background-color: var(--_bg-resolved, var(--ui-field-bg));
border-width: var(--_border-width-resolved, var(--ui-input-border-width));
border-style: var(--_border-style-resolved, var(--ui-input-border-style));
border-color: var(--_border-color-resolved, var(--ui-input-border-color));
--_radius-len: var(--_radius-resolved, var(--ui-input-radius));
--_radius-num: var(--_radius-resolved, var(--ui-input-radius));
border-radius: calc(
var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
);
corner-shape: var(--_corner-shape-resolved, var(--ui-input-corner-shape));
/* The ring is published to --_focus-shadow so a --shadow utility keeps
it; the transparent outline twin keeps focus visible in forced-colors */
--_ring-offset-width: 0px;
--_ring-width: 0px;
--_focus-in: max(0, -1 * sign(var(--_focus-ring-w, 1px)));
--_ring-fill: color-mix(in oklch, var(--ui-field-ring-color) var(--ring-opacity), transparent);
--_focus-shadow:
0 0 0 calc(var(--_ring-offset-width) * (1 - var(--_focus-in))) var(--ring-offset-shadow-color),
0 0 0 calc((var(--_ring-offset-width) + var(--_ring-width)) * (1 - var(--_focus-in)))
var(--_ring-fill, var(--ring-shadow-color)),
inset 0 0 0 calc(var(--_ring-offset-width) * var(--_focus-in)) var(--ring-offset-shadow-color),
inset 0 0 0 calc((var(--_ring-offset-width) + var(--_ring-width)) * var(--_focus-in))
var(--_ring-fill, var(--ring-shadow-color));
box-shadow: var(--_focus-shadow, 0 0 #0000), var(--_shadow-resolved, 0 0 #0000);
outline: abs(var(--_focus-ring-w, var(--outline-width))) var(--outline-style) transparent;
outline-offset: calc(
var(--outline-offset) - var(--_focus-in) *
(2 * var(--outline-offset) + abs(var(--_focus-ring-w, var(--outline-width))))
);
transition: var(--default-transition);
}
@media (hover: hover) {
:where([data-ui~="input"]):hover {
border-color: var(--_border-color-resolved, var(--ui-field-border-color--hover));
background-color: var(--_bg-resolved, var(--ui-field-bg--hover));
}
}
:where([data-ui~="input"]):focus-within {
background-color: var(--_bg-resolved, var(--ui-field-bg--focus-within));
border-color: var(--_border-color-resolved, var(--ui-field-border-color--focus-within));
--_ring-offset-width: var(--ring-offset-width);
--_ring-width: abs(var(--_focus-ring-w, var(--ring-width)));
outline-color: transparent;
}
:where([data-ui~="input"])[type="date"],
:where([data-ui~="input"])[type="time"],
:where([data-ui~="input"])[type="datetime-local"] {
--ui-input-pr: calc(var(--spacing) * 1.5);
}
/* iOS WebKit adds a temporal input's padding and border on top of its inline size,
whatever box-sizing says (webkit.org/b/301648), so a full-width field overflows;
-webkit-touch-callout is iOS-only, so the correction lands there alone. The
padding includes the touch-target widening (--_touch-px) on both sides. */
@supports (-webkit-touch-callout: none) {
:where([data-ui~="input"]):is(
[type="date"],
[type="time"],
[type="datetime-local"],
[type="month"],
[type="week"]
) {
inline-size: calc(
var(--_w-len) + var(--_w-num) * var(--spacing) -
(var(--_pl-len) + var(--_pl-num) * var(--spacing)) -
(var(--_pr-len) + var(--_pr-num) * var(--spacing)) - 2 * var(--_touch-px) - 2 *
var(--_border-width-resolved, var(--ui-input-border-width))
);
}
}
/* Native date/time controls keep their picker indicator tinted to the text */
:where([data-ui~="input"])::-webkit-calendar-picker-indicator {
cursor: pointer;
-webkit-appearance: none;
margin: 0;
padding: 0;
inline-size: var(--ui-input-calendar-picker-size);
block-size: var(--ui-input-calendar-picker-size);
border-radius: var(--ui-input-calendar-picker-radius);
corner-shape: var(--ui-input-calendar-picker-corner-shape);
transition:
opacity var(--default-transition-duration) var(--default-transition-timing-function),
display var(--default-transition-duration) var(--default-transition-timing-function)
allow-discrete;
mask: var(--ui-input-calendar-picker-mask) no-repeat center /
var(--ui-input-calendar-picker-icon-size);
background-size: var(--ui-input-calendar-picker-icon-size);
background-color: var(--ui-input-calendar-picker-color);
background-repeat: no-repeat;
background-position: center;
}
:where([data-ui~="input"])::-webkit-calendar-picker-indicator:is(:hover) {
opacity: 0.5;
}
}
/* Disabled and committed-invalid states; an invalid control remaps the
--ui-field-* family on itself. */
@layer ui.components {
:where([data-ui~="input"]):disabled {
opacity: 0.5;
cursor: not-allowed;
}
:where([data-ui~="input"]):user-invalid {
--ui-field-bg: var(--color-destructive);
--ui-field-bg--hover: oklch(from var(--color-destructive) calc(l - 0.025) c h);
--ui-field-border-color: var(--color-destructive-foreground);
--ui-field-border-color--hover: var(--color-destructive-foreground);
--ui-field-border-color--focus-within: var(--color-destructive-foreground);
--ui-field-ring-color: var(--color-destructive-foreground);
border-color: var(--color-destructive-foreground);
}
}Icon leading
<label data-ui="input-group">
<input data-ui="input" type="text" name="query" placeholder="Placeholder" />
<span data-input-group-slot="addon">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<line x1="4" y1="6" x2="20" y2="6" />
<line x1="4" y1="12" x2="20" y2="12" />
<line x1="4" y1="18" x2="20" y2="18" />
</svg>
</span>
</label>/**
* input.css — Text input ([data-ui~="input"])
*
* @layer variables, components
* @requires _layers.css, _variables.css, _properties.css (--_*-resolved, --_focus-shadow), fields.css, _reset.css
* @uses ::-webkit-calendar-picker-indicator — date/time picker chrome (WebKit)
* @uses mask — calendar icon (not background-image, for color: currentColor)
* @uses @supports (-webkit-touch-callout: none) — iOS-only width fix for temporal
* inputs (webkit.org/b/301648)
* @uses corner-shape — superellipse corners; unsupported browsers keep plain
* rounded corners
* @uses --_touch-min (touch screens) — the field grows to the touch floor,
* and each inline side gains half of what the height grew
* @tokens --ui-input-* (@layer variables; surface colors and height read the
* --ui-field-* family directly)
*/
@layer variables {
:root {
--ui-input-w: 100%;
--ui-input-min-w: 16ch;
--ui-input-pl: var(--ui-field-px);
--ui-input-pr: var(--ui-field-px);
--ui-input-py: var(--ui-field-py);
--ui-input-font-size: var(--ui-field-font-size);
--ui-input-leading: var(--ui-field-leading);
--ui-input-border-width: var(--ui-field-border-width);
--ui-input-border-style: var(--ui-field-border-style);
--ui-input-border-color: var(--ui-field-border-color);
--ui-input-radius: var(--ui-field-radius);
--ui-input-corner-shape: var(--ui-field-corner-shape);
--ui-input-calendar-picker-color: currentColor;
--ui-input-calendar-picker-icon-size: calc(var(--spacing) * 4);
--ui-input-calendar-picker-size: calc(var(--spacing) * 6);
--ui-input-calendar-picker-radius: var(--ui-field-inset-radius);
--ui-input-calendar-picker-corner-shape: var(--ui-field-corner-shape);
--ui-input-calendar-picker-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Crect width='256' height='256' fill='none'/%3E%3Crect x='40' y='40' width='176' height='176' rx='8' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='176' y1='24' x2='176' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='80' y1='24' x2='80' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='40' y1='88' x2='216' y2='88' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3C/svg%3E");
}
}
@layer ui.components {
/* ===========================================================================
TEXT INPUTS — data-ui="input"
- One identity for every text-like type (text, search, email, number, date, …);
the type only changes the picker/keyboard, not the box.
- Shares the --ui-field-* tokens defined in fields.css so it aligns with the select,
the textarea, and [data-ui~="button"].
=========================================================================== */
:where([data-ui~="input"]) {
/* dual-mode metrics go through the registered typed pair */
--_w-len: var(--_w-resolved, var(--ui-input-w));
--_w-num: var(--_w-resolved, var(--ui-input-w));
inline-size: calc(var(--_w-len) + var(--_w-num) * var(--spacing));
--_min-w-len: var(--_min-w-resolved, var(--ui-input-min-w));
--_min-w-num: var(--_min-w-resolved, var(--ui-input-min-w));
min-inline-size: calc(var(--_min-w-len) + var(--_min-w-num) * var(--spacing));
--_h-len: var(--_h-resolved, var(--ui-field-h));
--_h-num: var(--_h-resolved, var(--ui-field-h));
/* never shorter than one line plus --ui-input-py and the border above and below,
so a small --spacing can't squeeze the text against the border. The browser
centers the text in the box; a --py utility replaces --ui-input-py here and
also pads the block axis, so the line still fits. */
--_py-len: var(--_py-resolved, var(--ui-input-py));
--_py-num: var(--_py-resolved, var(--ui-input-py));
block-size: max(
calc(var(--_h-len) + var(--_h-num) * var(--spacing)),
var(--_touch-min),
calc(
1lh + 2 *
(
var(--_py-len) + var(--_py-num) * var(--spacing) +
var(--_border-width-resolved, var(--ui-input-border-width))
)
)
);
/* half of what the touch floor added to the height, on each inline side */
--_touch-px: max(
0px,
(var(--_touch-min) - calc(var(--_h-len) + var(--_h-num) * var(--spacing))) / 2
);
--_pl-len: var(--_pl-resolved, var(--ui-input-pl));
--_pl-num: var(--_pl-resolved, var(--ui-input-pl));
padding-inline-start: calc(var(--_pl-len) + var(--_pl-num) * var(--spacing) + var(--_touch-px));
--_pr-len: var(--_pr-resolved, var(--ui-input-pr));
--_pr-num: var(--_pr-resolved, var(--ui-input-pr));
padding-inline-end: calc(var(--_pr-len) + var(--_pr-num) * var(--spacing) + var(--_touch-px));
font-size: var(--_font-size-resolved, var(--ui-input-font-size));
line-height: var(--_leading-resolved, var(--ui-input-leading));
color: var(--_text-resolved, var(--ui-field-text));
background-color: var(--_bg-resolved, var(--ui-field-bg));
border-width: var(--_border-width-resolved, var(--ui-input-border-width));
border-style: var(--_border-style-resolved, var(--ui-input-border-style));
border-color: var(--_border-color-resolved, var(--ui-input-border-color));
--_radius-len: var(--_radius-resolved, var(--ui-input-radius));
--_radius-num: var(--_radius-resolved, var(--ui-input-radius));
border-radius: calc(
var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
);
corner-shape: var(--_corner-shape-resolved, var(--ui-input-corner-shape));
/* The ring is published to --_focus-shadow so a --shadow utility keeps
it; the transparent outline twin keeps focus visible in forced-colors */
--_ring-offset-width: 0px;
--_ring-width: 0px;
--_focus-in: max(0, -1 * sign(var(--_focus-ring-w, 1px)));
--_ring-fill: color-mix(in oklch, var(--ui-field-ring-color) var(--ring-opacity), transparent);
--_focus-shadow:
0 0 0 calc(var(--_ring-offset-width) * (1 - var(--_focus-in))) var(--ring-offset-shadow-color),
0 0 0 calc((var(--_ring-offset-width) + var(--_ring-width)) * (1 - var(--_focus-in)))
var(--_ring-fill, var(--ring-shadow-color)),
inset 0 0 0 calc(var(--_ring-offset-width) * var(--_focus-in)) var(--ring-offset-shadow-color),
inset 0 0 0 calc((var(--_ring-offset-width) + var(--_ring-width)) * var(--_focus-in))
var(--_ring-fill, var(--ring-shadow-color));
box-shadow: var(--_focus-shadow, 0 0 #0000), var(--_shadow-resolved, 0 0 #0000);
outline: abs(var(--_focus-ring-w, var(--outline-width))) var(--outline-style) transparent;
outline-offset: calc(
var(--outline-offset) - var(--_focus-in) *
(2 * var(--outline-offset) + abs(var(--_focus-ring-w, var(--outline-width))))
);
transition: var(--default-transition);
}
@media (hover: hover) {
:where([data-ui~="input"]):hover {
border-color: var(--_border-color-resolved, var(--ui-field-border-color--hover));
background-color: var(--_bg-resolved, var(--ui-field-bg--hover));
}
}
:where([data-ui~="input"]):focus-within {
background-color: var(--_bg-resolved, var(--ui-field-bg--focus-within));
border-color: var(--_border-color-resolved, var(--ui-field-border-color--focus-within));
--_ring-offset-width: var(--ring-offset-width);
--_ring-width: abs(var(--_focus-ring-w, var(--ring-width)));
outline-color: transparent;
}
:where([data-ui~="input"])[type="date"],
:where([data-ui~="input"])[type="time"],
:where([data-ui~="input"])[type="datetime-local"] {
--ui-input-pr: calc(var(--spacing) * 1.5);
}
/* iOS WebKit adds a temporal input's padding and border on top of its inline size,
whatever box-sizing says (webkit.org/b/301648), so a full-width field overflows;
-webkit-touch-callout is iOS-only, so the correction lands there alone. The
padding includes the touch-target widening (--_touch-px) on both sides. */
@supports (-webkit-touch-callout: none) {
:where([data-ui~="input"]):is(
[type="date"],
[type="time"],
[type="datetime-local"],
[type="month"],
[type="week"]
) {
inline-size: calc(
var(--_w-len) + var(--_w-num) * var(--spacing) -
(var(--_pl-len) + var(--_pl-num) * var(--spacing)) -
(var(--_pr-len) + var(--_pr-num) * var(--spacing)) - 2 * var(--_touch-px) - 2 *
var(--_border-width-resolved, var(--ui-input-border-width))
);
}
}
/* Native date/time controls keep their picker indicator tinted to the text */
:where([data-ui~="input"])::-webkit-calendar-picker-indicator {
cursor: pointer;
-webkit-appearance: none;
margin: 0;
padding: 0;
inline-size: var(--ui-input-calendar-picker-size);
block-size: var(--ui-input-calendar-picker-size);
border-radius: var(--ui-input-calendar-picker-radius);
corner-shape: var(--ui-input-calendar-picker-corner-shape);
transition:
opacity var(--default-transition-duration) var(--default-transition-timing-function),
display var(--default-transition-duration) var(--default-transition-timing-function)
allow-discrete;
mask: var(--ui-input-calendar-picker-mask) no-repeat center /
var(--ui-input-calendar-picker-icon-size);
background-size: var(--ui-input-calendar-picker-icon-size);
background-color: var(--ui-input-calendar-picker-color);
background-repeat: no-repeat;
background-position: center;
}
:where([data-ui~="input"])::-webkit-calendar-picker-indicator:is(:hover) {
opacity: 0.5;
}
}
/* Disabled and committed-invalid states; an invalid control remaps the
--ui-field-* family on itself. */
@layer ui.components {
:where([data-ui~="input"]):disabled {
opacity: 0.5;
cursor: not-allowed;
}
:where([data-ui~="input"]):user-invalid {
--ui-field-bg: var(--color-destructive);
--ui-field-bg--hover: oklch(from var(--color-destructive) calc(l - 0.025) c h);
--ui-field-border-color: var(--color-destructive-foreground);
--ui-field-border-color--hover: var(--color-destructive-foreground);
--ui-field-border-color--focus-within: var(--color-destructive-foreground);
--ui-field-ring-color: var(--color-destructive-foreground);
border-color: var(--color-destructive-foreground);
}
}Icon trailing
<label data-ui="input-group">
<input data-ui="input" type="search" name="q" placeholder="Search…" aria-label="Search" />
<span data-input-group-slot="addon" data-input-group-align="inline-end">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="11" cy="11" r="8" />
<line x1="21" y1="21" x2="16.65" y2="16.65" />
</svg>
</span>
</label>/**
* input.css — Text input ([data-ui~="input"])
*
* @layer variables, components
* @requires _layers.css, _variables.css, _properties.css (--_*-resolved, --_focus-shadow), fields.css, _reset.css
* @uses ::-webkit-calendar-picker-indicator — date/time picker chrome (WebKit)
* @uses mask — calendar icon (not background-image, for color: currentColor)
* @uses @supports (-webkit-touch-callout: none) — iOS-only width fix for temporal
* inputs (webkit.org/b/301648)
* @uses corner-shape — superellipse corners; unsupported browsers keep plain
* rounded corners
* @uses --_touch-min (touch screens) — the field grows to the touch floor,
* and each inline side gains half of what the height grew
* @tokens --ui-input-* (@layer variables; surface colors and height read the
* --ui-field-* family directly)
*/
@layer variables {
:root {
--ui-input-w: 100%;
--ui-input-min-w: 16ch;
--ui-input-pl: var(--ui-field-px);
--ui-input-pr: var(--ui-field-px);
--ui-input-py: var(--ui-field-py);
--ui-input-font-size: var(--ui-field-font-size);
--ui-input-leading: var(--ui-field-leading);
--ui-input-border-width: var(--ui-field-border-width);
--ui-input-border-style: var(--ui-field-border-style);
--ui-input-border-color: var(--ui-field-border-color);
--ui-input-radius: var(--ui-field-radius);
--ui-input-corner-shape: var(--ui-field-corner-shape);
--ui-input-calendar-picker-color: currentColor;
--ui-input-calendar-picker-icon-size: calc(var(--spacing) * 4);
--ui-input-calendar-picker-size: calc(var(--spacing) * 6);
--ui-input-calendar-picker-radius: var(--ui-field-inset-radius);
--ui-input-calendar-picker-corner-shape: var(--ui-field-corner-shape);
--ui-input-calendar-picker-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Crect width='256' height='256' fill='none'/%3E%3Crect x='40' y='40' width='176' height='176' rx='8' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='176' y1='24' x2='176' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='80' y1='24' x2='80' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='40' y1='88' x2='216' y2='88' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3C/svg%3E");
}
}
@layer ui.components {
/* ===========================================================================
TEXT INPUTS — data-ui="input"
- One identity for every text-like type (text, search, email, number, date, …);
the type only changes the picker/keyboard, not the box.
- Shares the --ui-field-* tokens defined in fields.css so it aligns with the select,
the textarea, and [data-ui~="button"].
=========================================================================== */
:where([data-ui~="input"]) {
/* dual-mode metrics go through the registered typed pair */
--_w-len: var(--_w-resolved, var(--ui-input-w));
--_w-num: var(--_w-resolved, var(--ui-input-w));
inline-size: calc(var(--_w-len) + var(--_w-num) * var(--spacing));
--_min-w-len: var(--_min-w-resolved, var(--ui-input-min-w));
--_min-w-num: var(--_min-w-resolved, var(--ui-input-min-w));
min-inline-size: calc(var(--_min-w-len) + var(--_min-w-num) * var(--spacing));
--_h-len: var(--_h-resolved, var(--ui-field-h));
--_h-num: var(--_h-resolved, var(--ui-field-h));
/* never shorter than one line plus --ui-input-py and the border above and below,
so a small --spacing can't squeeze the text against the border. The browser
centers the text in the box; a --py utility replaces --ui-input-py here and
also pads the block axis, so the line still fits. */
--_py-len: var(--_py-resolved, var(--ui-input-py));
--_py-num: var(--_py-resolved, var(--ui-input-py));
block-size: max(
calc(var(--_h-len) + var(--_h-num) * var(--spacing)),
var(--_touch-min),
calc(
1lh + 2 *
(
var(--_py-len) + var(--_py-num) * var(--spacing) +
var(--_border-width-resolved, var(--ui-input-border-width))
)
)
);
/* half of what the touch floor added to the height, on each inline side */
--_touch-px: max(
0px,
(var(--_touch-min) - calc(var(--_h-len) + var(--_h-num) * var(--spacing))) / 2
);
--_pl-len: var(--_pl-resolved, var(--ui-input-pl));
--_pl-num: var(--_pl-resolved, var(--ui-input-pl));
padding-inline-start: calc(var(--_pl-len) + var(--_pl-num) * var(--spacing) + var(--_touch-px));
--_pr-len: var(--_pr-resolved, var(--ui-input-pr));
--_pr-num: var(--_pr-resolved, var(--ui-input-pr));
padding-inline-end: calc(var(--_pr-len) + var(--_pr-num) * var(--spacing) + var(--_touch-px));
font-size: var(--_font-size-resolved, var(--ui-input-font-size));
line-height: var(--_leading-resolved, var(--ui-input-leading));
color: var(--_text-resolved, var(--ui-field-text));
background-color: var(--_bg-resolved, var(--ui-field-bg));
border-width: var(--_border-width-resolved, var(--ui-input-border-width));
border-style: var(--_border-style-resolved, var(--ui-input-border-style));
border-color: var(--_border-color-resolved, var(--ui-input-border-color));
--_radius-len: var(--_radius-resolved, var(--ui-input-radius));
--_radius-num: var(--_radius-resolved, var(--ui-input-radius));
border-radius: calc(
var(--_radius-len) + var(--_radius-num) * var(--spacing) * var(--radius-multiplier)
);
corner-shape: var(--_corner-shape-resolved, var(--ui-input-corner-shape));
/* The ring is published to --_focus-shadow so a --shadow utility keeps
it; the transparent outline twin keeps focus visible in forced-colors */
--_ring-offset-width: 0px;
--_ring-width: 0px;
--_focus-in: max(0, -1 * sign(var(--_focus-ring-w, 1px)));
--_ring-fill: color-mix(in oklch, var(--ui-field-ring-color) var(--ring-opacity), transparent);
--_focus-shadow:
0 0 0 calc(var(--_ring-offset-width) * (1 - var(--_focus-in))) var(--ring-offset-shadow-color),
0 0 0 calc((var(--_ring-offset-width) + var(--_ring-width)) * (1 - var(--_focus-in)))
var(--_ring-fill, var(--ring-shadow-color)),
inset 0 0 0 calc(var(--_ring-offset-width) * var(--_focus-in)) var(--ring-offset-shadow-color),
inset 0 0 0 calc((var(--_ring-offset-width) + var(--_ring-width)) * var(--_focus-in))
var(--_ring-fill, var(--ring-shadow-color));
box-shadow: var(--_focus-shadow, 0 0 #0000), var(--_shadow-resolved, 0 0 #0000);
outline: abs(var(--_focus-ring-w, var(--outline-width))) var(--outline-style) transparent;
outline-offset: calc(
var(--outline-offset) - var(--_focus-in) *
(2 * var(--outline-offset) + abs(var(--_focus-ring-w, var(--outline-width))))
);
transition: var(--default-transition);
}
@media (hover: hover) {
:where([data-ui~="input"]):hover {
border-color: var(--_border-color-resolved, var(--ui-field-border-color--hover));
background-color: var(--_bg-resolved, var(--ui-field-bg--hover));
}
}
:where([data-ui~="input"]):focus-within {
background-color: var(--_bg-resolved, var(--ui-field-bg--focus-within));
border-color: var(--_border-color-resolved, var(--ui-field-border-color--focus-within));
--_ring-offset-width: var(--ring-offset-width);
--_ring-width: abs(var(--_focus-ring-w, var(--ring-width)));
outline-color: transparent;
}
:where([data-ui~="input"])[type="date"],
:where([data-ui~="input"])[type="time"],
:where([data-ui~="input"])[type="datetime-local"] {
--ui-input-pr: calc(var(--spacing) * 1.5);
}
/* iOS WebKit adds a temporal input's padding and border on top of its inline size,
whatever box-sizing says (webkit.org/b/301648), so a full-width field overflows;
-webkit-touch-callout is iOS-only, so the correction lands there alone. The
padding includes the touch-target widening (--_touch-px) on both sides. */
@supports (-webkit-touch-callout: none) {
:where([data-ui~="input"]):is(
[type="date"],
[type="time"],
[type="datetime-local"],
[type="month"],
[type="week"]
) {
inline-size: calc(
var(--_w-len) + var(--_w-num) * var(--spacing) -
(var(--_pl-len) + var(--_pl-num) * var(--spacing)) -
(var(--_pr-len) + var(--_pr-num) * var(--spacing)) - 2 * var(--_touch-px) - 2 *
var(--_border-width-resolved, var(--ui-input-border-width))
);
}
}
/* Native date/time controls keep their picker indicator tinted to the text */
:where([data-ui~="input"])::-webkit-calendar-picker-indicator {
cursor: pointer;
-webkit-appearance: none;
margin: 0;
padding: 0;
inline-size: var(--ui-input-calendar-picker-size);
block-size: var(--ui-input-calendar-picker-size);
border-radius: var(--ui-input-calendar-picker-radius);
corner-shape: var(--ui-input-calendar-picker-corner-shape);
transition:
opacity var(--default-transition-duration) var(--default-transition-timing-function),
display var(--default-transition-duration) var(--default-transition-timing-function)
allow-discrete;
mask: var(--ui-input-calendar-picker-mask) no-repeat center /
var(--ui-input-calendar-picker-icon-size);
background-size: var(--ui-input-calendar-picker-icon-size);
background-color: var(--ui-input-calendar-picker-color);
background-repeat: no-repeat;
background-position: center;
}
:where([data-ui~="input"])::-webkit-calendar-picker-indicator:is(:hover) {
opacity: 0.5;
}
}
/* Disabled and committed-invalid states; an invalid control remaps the
--ui-field-* family on itself. */
@layer ui.components {
:where([data-ui~="input"]):disabled {
opacity: 0.5;
cursor: not-allowed;
}
:where([data-ui~="input"]):user-invalid {
--ui-field-bg: var(--color-destructive);
--ui-field-bg--hover: oklch(from var(--color-destructive) calc(l - 0.025) c h);
--ui-field-border-color: var(--color-destructive-foreground);
--ui-field-border-color--hover: var(--color-destructive-foreground);
--ui-field-border-color--focus-within: var(--color-destructive-foreground);
--ui-field-ring-color: var(--color-destructive-foreground);
border-color: var(--color-destructive-foreground);
}
}Attributes
| Attribute | Kind | Values | Notes |
|---|---|---|---|
data-ui="input" | Identity | free value | Identity token in data-ui. |
Requires: fields.
Hooks
Set a hook on :root, on a subtree, or inline on one element. A state hook (--…--hover) themes that state only; the primitive keeps its other states.
| Hook | Default | State |
|---|---|---|
--ui-input-border-color | var(--ui-field-border-color) | — |
--ui-input-border-style | var(--ui-field-border-style) | — |
--ui-input-border-width | var(--ui-field-border-width) | — |
--ui-input-calendar-picker-color | currentColor | — |
--ui-input-calendar-picker-corner-shape | var(--ui-field-corner-shape) | — |
--ui-input-calendar-picker-icon-size | calc(var(--spacing) * 4) | — |
--ui-input-calendar-picker-mask | url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Crect width='256' height='256' fill='none'/%3E%3Crect x='40' y='40' width='176' height='176' rx='8' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='176' y1='24' x2='176' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='80' y1='24' x2='80' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='40' y1='88' x2='216' y2='88' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3C/svg%3E") | — |
--ui-input-calendar-picker-radius | var(--ui-field-inset-radius) | — |
--ui-input-calendar-picker-size | calc(var(--spacing) * 6) | — |
--ui-input-corner-shape | var(--ui-field-corner-shape) | — |
--ui-input-font-size | var(--ui-field-font-size) | — |
--ui-input-leading | var(--ui-field-leading) | — |
--ui-input-min-w | 16ch | — |
--ui-input-pl | var(--ui-field-px) | — |
--ui-input-pr | var(--ui-field-px) | — |
--ui-input-py | var(--ui-field-py) | — |
--ui-input-radius | var(--ui-field-radius) | — |
--ui-input-w | 100% | — |