A text input component for forms and user data entry with built-in styling and accessibility features.

Basic
Invalid
With Label
With Description

Choose a unique username for your account.

Disabled
Input Types
With Select
With Button
With Native Select
Form

We'll never share your email with anyone.

Installation

Install the dependencies

pnpm add cn github:sveltery/base

Copy the component

Copy the following files into src/lib/components/ui/input.

src/lib/components/ui/input/Input.svelte
<script lang="ts">
  import { Input as Primitive } from '@sveltery/base/input';
  import type { InputProps } from '@sveltery/base/input';
  import { cn } from 'cn';
  let { class: classProp, value = $bindable(), ...props }: InputProps = $props();
</script>
<Primitive data-slot="input" {...props} class={cn('dark:bg-input/30 border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 h-8 rounded-lg border bg-transparent px-2.5 py-1 text-base transition-colors file:h-6 file:text-sm file:font-medium focus-visible:ring-3 aria-invalid:ring-3 md:text-sm w-full min-w-0 outline-none file:inline-flex file:border-0 file:bg-transparent file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50', classProp)} bind:value />
src/lib/components/ui/input/index.ts
export { default as Input } from './Input.svelte';

Update the import paths

Change the imports to match your project setup.

Usage

<script lang="ts">
  import { Input } from '$lib/components/ui/input';
  let email = $state('');
</script>
<Input type="email" name="email" placeholder="Email" bind:value={email} />

Forms

Input renders a real <input>, so it submits its name and value with the form. Use bind:value to share the value, or defaultValue to give an unbound input its starting value.

<form method="POST">
  <Input name="email" type="email" defaultValue="me@example.com" />
  <button type="submit">Save</button>
</form>

API reference

Input is styled on top of the Sveltery Base Input primitive, which owns its behavior and its integration with Base fields and forms. See the Base UI Input documentation for the behavior it ports.