elements
Demos UI Feed Discuss Install
Style System
  • Style
  • Themes
  • Behaviors
Forms
  • Button
  • ButtonGroup
  • Checkbox
  • ColorPicker
  • Combobox
  • Field
  • FileUpload
  • Input
  • InputGroup
  • InputOTP
  • Label
  • NativeSelect
  • NumberInput
  • PasswordInput
  • RadioGroup
  • Select
  • Slider
  • Switch
  • TagsInput
  • Textarea
  • Toggle
  • ToggleGroup
Overlays
  • AlertDialog
  • Command
  • ContextMenu
  • Dialog
  • Drawer
  • DropdownMenu
  • HoverCard
  • Menubar
  • NavigationMenu
  • Popover
  • Sheet
  • Toast
  • Tooltip
Display
  • Accordion
  • Alert
  • AspectRatio
  • Avatar
  • Badge
  • Breadcrumb
  • Card
  • Collapsible
  • Empty
  • Item
  • Kbd
  • Pagination
  • Progress
  • Separator
  • Skeleton
  • Spinner
  • Table
  • Tabs
  • Tree
Layout
  • Carousel
  • Resizable
  • ScrollArea
  • Sidebar
Dates
  • Calendar
  • DatePicker
  • DateRangePicker
  • TimePicker
Data
  • AreaChart
  • BarChart
  • Chart
  • DataTable
  • Kanban
  • LineChart
  • PieChart
  • RadarChart
  • RadialChart
  • VirtualList
Chat
  • Attachment
  • Message
  • MessageList
  • PromptInput
Elements UI / Forms / PasswordInput

PasswordInput

A password field with a button that shows and hides what was typed.

Basic

The toggle shows and hides the password. Focus and the caret stay in the input.

value: hunter2, visible: false, toggles: 0
Code
<PasswordInput value={state.password} visible={state.visible}
               attrs={{ "aria-label": "Password" }}
               onVisibilityChange={() => state.toggles++} />

Usage

import { PasswordInput } from "@elements/ui/password-input";

<PasswordInput value={form.password} attrs={{ "aria-label": "Password" }} />
<PasswordInput value={form.next} autocomplete="new-password" visible={ui.reveal} />
<PasswordInput value={form.apiKey} ignorePasswordManagers />

Examples

Controlled visibility

visible is two-way: set it from anywhere.

visible: false
Code
<PasswordInput value={state.revealed} visible={state.reveal} />
<Button onclick={() => state.reveal = !state.reveal}>Toggle from outside</Button>

New password with strength

autocomplete=new-password asks a manager to suggest one. The meter is page code: a real app might score with a strength estimation package.

At least 8 characters.

StrengthEmpty
Code
<Field label="New password" description="At least 8 characters.">
  <PasswordInput value={state.next} autocomplete="new-password" attrs={{ minlength: 8 }} />
</Field>
<div class="meter" data-score={score(state.next)}>...</div>

Ignore password managers

For API keys and PINs: managers that honor the attributes leave the field alone.

Code
<PasswordInput value={state.apiKey} ignorePasswordManagers placeholder="sk-..." />

Sizes

Heights follow the control tokens; the toggle stays square.

Code
<PasswordInput value={state.small} size="sm" />
<PasswordInput value={state.large} size="lg" />

Disabled and read-only

A read-only password can still be revealed.

Code
<PasswordInput value={state.locked} disabled />
<PasswordInput value={state.fixed} readonly />

Validation

invalid marks the input and the root; the Field shows the error under it, in a line it always reserves.

Password must be at least 8 characters.
Code
<Field label="Password" error={state.weak.length < 8 ? "Password must be at least 8 characters." : ""}>
  <PasswordInput value={state.weak} invalid={state.weak.length < 8} />
</Field>

In a form

name submits the value. Reset restores it and hides it; required blocks an empty submit.

not submitted
Code
<form onsubmit={(e) => submit(e)}>
  <PasswordInput value={state.password} name="password" required />
  <Button type="reset">Reset</Button>
  <Button type="submit" variant="primary">Sign in</Button>
</form>

Custom icons and labels

The visibleIcon and hiddenIcon slots replace the eye; showLabel and hideLabel rename the toggle.

Code
<PasswordInput value={state.pin} showLabel="Show PIN" hideLabel="Hide PIN">
  <Icon slot="visibleIcon" name="shield" />
  <Icon slot="hiddenIcon" name="star" />
</PasswordInput>
Reference PasswordInput in the manual Every part, attribute, slot, key and data attribute.
Prev NumberInputNext RadioGroup
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026