Input

One native text input bound to Field behavior for labels, descriptions, errors and validation.

<tp-input>
Input
Default density Compact density Restart from the initial state Show the copyable source

Usage

Labels, descriptions and errors belong to tp-field; the Input owns the native editor. A standalone Input can take label for its accessible name, but a Field is the usual home. Optional prefix and suffix content belongs to tp-input-group.

Types

type keeps native editing, affordances and validation for every host-supported input type.

Types
Default density Compact density Restart from the initial state Show the copyable source

Code-like values

mono shows the value in the mono font and turns off spell checking, autocorrection and autocapitalization. Use it for identifiers, paths, expressions and keys, where a corrected character is a bug.

Mono
Default density Compact density Restart from the initial state Show the copyable source

Controlled value

default-value leaves the text to the Input. Supply value instead, before the first render, and every edit becomes a proposal: onValueChange receives it, and what you assign back to value is what commits. Here the owner rewrites each edit into a URL-safe handle.

Owner-shaped value
Default density Compact density Restart from the initial state Show the copyable source

Without an assignment the proposal is rejected and the committed text stays. Mode stays fixed for an instance lifetime. A rejected or canceled edit restores committed text and preserves selection within its bounds. Composition keeps the native draft until composition ends.

Validation

Native constraints such as required, pattern and minlength validate through the owning Field, which shows the error and wires aria-describedby. error and invalid set an explicit error from your own validation.

Error
Default density Compact density Restart from the initial state Show the copyable source

States

Disabled and read-only
Default density Compact density Restart from the initial state Show the copyable source

Disabled omits the value from form data. Read-only keeps it, along with selection and focus.

Native form reset restores an uncontrolled default with form-reset; controlled reset does not propose or replace owner state. State restoration restores uncontrolled strings. Enter uses the associated form’s default submitter; composition does not submit. File input retains its native file list and serializes files without duplicate participants.

Anatomy and customization

The native <input> is a real element in your tree: it renders into the Input’s light DOM (tp-input > input), shares the Input’s form owner and submits natively, so browser autofill and password managers classify and fill it like any form field. Customize semantic tokens, the presentation dictionary, partPresentation.input, or style tp-input > input directly; ::part(input) does not apply because the editor is not in the shadow root. Keep caret, selection, autofill and type-specific affordances visible.

Native form serialization follows the editable input’s current representation, including type sanitization, while the controlled owner value remains its supplied value. An empty named file input submits the native empty File; unnamed inputs do not contribute data.

Inline

Inline
Default density Compact density Restart from the initial state Show the copyable source

variant="inline" fits the Input into one row the height of a control, with label at the start and the value at the end, so it stacks with other inline controls such as an inline Select. A press on the label edits the value. Inside a Field, the Field’s label moves into the row.

A number value sits between a decrement and an increment arrow in place of the browser’s spin buttons. Hold an arrow to keep stepping; the Arrow keys step the focused value too, ten steps at a time with Shift. step sets how far each step moves, and precision how many decimals the value keeps and shows, which defaults to the decimals of step.

Number steps
Default density Compact density Restart from the initial state Show the copyable source

API Reference

Every element also accepts motion-policy.

Attributes

AttributePropertyTypeDefaultDescriptiontypetypestring'text'The native input type, such as email, password, search, url or tel; it sets the keyboard, autofill and built-in validation.minminstring''The lowest value a numeric or date type accepts.maxmaxstring''The highest value a numeric or date type accepts.stepstepstring''The granularity a numeric or date type accepts.patternpatternstring''A regular expression the whole value must match to be valid.precisionprecisionnumber | undefined—Decimal places of a number value: stepped and typed values are rounded to it, and the value shows that many decimals. Defaults to the decimals of step.variantvariantInputVariant'default'inline shows the label and the value in one compact control-height row, for stacked controls; an enclosing Field's label moves into the row.

Events

EventTypeDescriptiontp-value-changeTpValueChangeEvent<string>Cancelable proposal of new text before it commits; detail.value, detail.previousValue and the detail.reason for the change.tp-field-valueCustomEvent<{ value: string; previousValue: string; reason: ChangeReason; }>After new text commits, with the same value, previousValue and reason; the enclosing Field listens for it.

Slots

SlotDescriptiondefaultHolds the native input the element renders; leave it empty.

CSS parts

PartDescription::part(input-row)The row of an inline Input around its label and editor.::part(input-label)The label at the start of an inline Input's row.::part(input-stepper)The decrement and increment Buttons around the value at the end of an inline number Input's row.::part(input-decrement)The Button before the value that steps an inline number Input down.::part(input-increment)The Button after the value that steps an inline number Input up.::part(input)The native input, rendered in the page's own tree.

Components, widgets and patterns that use this one.

Show more