Forms

Password input

Enters a password, with a way to check what was typed.

Installation

npx sinaui add password-input

Examples

Signing in

The eye shows and hides the password without moving the cursor. Turn on Caps Lock while typing to see the warning.

<script lang="ts">
	import PasswordInput from '#lib/ui/PasswordInput.svelte';
</script>

<PasswordInput label="Password" name="password" required />

Choosing a new password

Password managers offer to suggest one, and a meter shows how strong it is.

At least 12 characters, mixing letters, numbers and symbols.

<script lang="ts">
	import PasswordInput from '#lib/ui/PasswordInput.svelte';

	let password = $state('');
</script>

<PasswordInput
	label="New password"
	bind:value={password}
	isNew
	hint="At least 12 characters, mixing letters, numbers and symbols."
/>

With requirements

Each requirement ticks off as it's met, including ones a simple pattern can't express, like not using your own name. The confirm field says when the two don't match.

  • At least 12 characters, not yet met
  • An uppercase and a lowercase letter, not yet met
  • A number, not yet met
  • A symbol, like ! or #, not yet met
  • Not your name, not yet met
  • No character 3 times in a row, not yet met

<script lang="ts">
	import PasswordInput from '#lib/ui/PasswordInput.svelte';

	const name = 'Maryam al-Ijliya';
	let password = $state('');
	let confirm = $state('');
	let confirmTouched = $state(false);

	const rules = [
		{ label: 'At least 12 characters', test: (v: string) => v.length >= 12 },
		{
			label: 'An uppercase and a lowercase letter',
			test: (v: string) => /[a-z]/.test(v) && /[A-Z]/.test(v)
		},
		{ label: 'A number', test: (v: string) => /\d/.test(v) },
		{ label: 'A symbol, like ! or #', test: (v: string) => /[^A-Za-z0-9\s]/.test(v) },
		{
			label: 'Not your name',
			test: (v: string) =>
				!!v &&
				!name
					.toLowerCase()
					.split(/[\s-]+/)
					.some((part) => part.length > 2 && v.toLowerCase().includes(part))
		},
		{ label: 'No character 3 times in a row', test: (v: string) => !!v && !/(.)\1\1/.test(v) }
	];

	// Mismatch is shown once they've left the confirm field, then updates live.
	const mismatch = $derived(
		confirmTouched && confirm !== password ? "The passwords don't match." : undefined
	);
</script>

<div class="stack">
	<PasswordInput label="New password" bind:value={password} isNew {rules} />
	<PasswordInput
		label="Confirm password"
		bind:value={confirm}
		autocomplete="new-password"
		error={mismatch}
		onblur={() => (confirmTouched = true)}
	/>
</div>

<style>
	.stack {
		display: grid;
		gap: 1rem;
		inline-size: min(100%, 24rem);
	}
</style>

Props

PropTypeDefault
labelstring (required)
valuestring, bindable''
isNewbooleanfalse
rules{ label, test(value) }[]
hint, errorstring

Other input attributes (name, required, minlength) pass through.

Accessibility

  • The show button is a toggle: screen readers hear “Show password, toggle button, pressed” or not pressed.
  • The Caps Lock warning and the strength are announced when they change.
  • Requirements are part of the field's description, each read as met or not yet met; “All requirements met” is announced once they are.
  • Autofill hints (current-password or new-password) let password managers fill or suggest.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme