Input
Single-size text field — borderless, defined by a quiet fill that deepens on hover and focus. The neutral focus ring sits on top without shifting layout; aria-invalid flips that ring to destructive in one beat.
Usage
input.svelte
<script lang="ts">
import type { HTMLInputAttributes, HTMLInputTypeAttribute } from 'svelte/elements';
import { cn, type WithElementRef } from '$lib/utils.js';
type InputType = Exclude<HTMLInputTypeAttribute, 'file'>;
type Props = WithElementRef<
Omit<HTMLInputAttributes, 'type'> &
({ type: 'file'; files?: FileList } | { type?: InputType; files?: undefined })
>;
let {
ref = $bindable(null),
value = $bindable(),
type,
files = $bindable(),
class: className,
'data-slot': dataSlot = 'input',
...restProps
}: Props = $props();
</script>
{#if type === 'file'}
<input
bind:this={ref}
data-slot={dataSlot}
class={cn(
'h-9 w-full min-w-0 rounded-(--radius-control) bg-input/30 px-3 py-1 text-base transition-colors duration-(--motion-duration-fast) outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:bg-input/50 focus-visible:bg-input/50 focus-visible:ring-(length:--ring-width) focus-visible:ring-border disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-(length:--ring-width) aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:ring-destructive/40',
className
)}
type="file"
bind:files
bind:value
{...restProps}
/>
{:else}
<input
bind:this={ref}
data-slot={dataSlot}
class={cn(
'h-9 w-full min-w-0 rounded-(--radius-control) bg-input/30 px-3 py-1 text-base transition-colors duration-(--motion-duration-fast) outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:bg-input/50 focus-visible:bg-input/50 focus-visible:ring-(length:--ring-width) focus-visible:ring-border disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-(length:--ring-width) aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:ring-destructive/40',
className
)}
{type}
bind:value
{...restProps}
/>
{/if}
States
input.svelte
<script lang="ts">
import type { HTMLInputAttributes, HTMLInputTypeAttribute } from 'svelte/elements';
import { cn, type WithElementRef } from '$lib/utils.js';
type InputType = Exclude<HTMLInputTypeAttribute, 'file'>;
type Props = WithElementRef<
Omit<HTMLInputAttributes, 'type'> &
({ type: 'file'; files?: FileList } | { type?: InputType; files?: undefined })
>;
let {
ref = $bindable(null),
value = $bindable(),
type,
files = $bindable(),
class: className,
'data-slot': dataSlot = 'input',
...restProps
}: Props = $props();
</script>
{#if type === 'file'}
<input
bind:this={ref}
data-slot={dataSlot}
class={cn(
'h-9 w-full min-w-0 rounded-(--radius-control) bg-input/30 px-3 py-1 text-base transition-colors duration-(--motion-duration-fast) outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:bg-input/50 focus-visible:bg-input/50 focus-visible:ring-(length:--ring-width) focus-visible:ring-border disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-(length:--ring-width) aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:ring-destructive/40',
className
)}
type="file"
bind:files
bind:value
{...restProps}
/>
{:else}
<input
bind:this={ref}
data-slot={dataSlot}
class={cn(
'h-9 w-full min-w-0 rounded-(--radius-control) bg-input/30 px-3 py-1 text-base transition-colors duration-(--motion-duration-fast) outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:bg-input/50 focus-visible:bg-input/50 focus-visible:ring-(length:--ring-width) focus-visible:ring-border disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-(length:--ring-width) aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:ring-destructive/40',
className
)}
{type}
bind:value
{...restProps}
/>
{/if}
Types
input.svelte
<script lang="ts">
import type { HTMLInputAttributes, HTMLInputTypeAttribute } from 'svelte/elements';
import { cn, type WithElementRef } from '$lib/utils.js';
type InputType = Exclude<HTMLInputTypeAttribute, 'file'>;
type Props = WithElementRef<
Omit<HTMLInputAttributes, 'type'> &
({ type: 'file'; files?: FileList } | { type?: InputType; files?: undefined })
>;
let {
ref = $bindable(null),
value = $bindable(),
type,
files = $bindable(),
class: className,
'data-slot': dataSlot = 'input',
...restProps
}: Props = $props();
</script>
{#if type === 'file'}
<input
bind:this={ref}
data-slot={dataSlot}
class={cn(
'h-9 w-full min-w-0 rounded-(--radius-control) bg-input/30 px-3 py-1 text-base transition-colors duration-(--motion-duration-fast) outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:bg-input/50 focus-visible:bg-input/50 focus-visible:ring-(length:--ring-width) focus-visible:ring-border disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-(length:--ring-width) aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:ring-destructive/40',
className
)}
type="file"
bind:files
bind:value
{...restProps}
/>
{:else}
<input
bind:this={ref}
data-slot={dataSlot}
class={cn(
'h-9 w-full min-w-0 rounded-(--radius-control) bg-input/30 px-3 py-1 text-base transition-colors duration-(--motion-duration-fast) outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground hover:bg-input/50 focus-visible:bg-input/50 focus-visible:ring-(length:--ring-width) focus-visible:ring-border disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-(length:--ring-width) aria-invalid:ring-destructive/20 md:text-sm dark:aria-invalid:ring-destructive/40',
className
)}
{type}
bind:value
{...restProps}
/>
{/if}
File
File picker using the native input type.
input-file.svelte
<script lang="ts">
import { Input } from '$lib/components/ui/input';
</script>
<Input type="file" />With Label
Pair a Label with an Input for accessible form fields.
input-with-label.svelte
<script lang="ts">
import { Input } from '$lib/components/ui/input';
import { Label } from '$lib/components/ui/label';
</script>
<div class="grid w-full max-w-sm gap-1.5">
<Label for="picture">Picture</Label>
<Input id="picture" type="text" placeholder="Your name" />
</div>With Button
Side-by-side Input + Button for subscribe or search patterns.
input-with-button.svelte
<script lang="ts">
import { Input } from '$lib/components/ui/input';
import { Button } from '$lib/components/ui/button';
</script>
<div class="flex w-full max-w-sm items-center gap-2">
<Input type="email" placeholder="you@bloom.social" />
<Button type="submit">Subscribe</Button>
</div>API reference
Inherits every native HTMLInputElement attribute via spread. File inputs also bind the files FileList.
| Prop | Type | Default | Description |
|---|---|---|---|
HTMLInputTypeAttribute | 'text' | Any native input type. File uses a tailored set of file-styling selectors; everything else shares the same rounded pill. | |
string | number | string[] | undefined (bindable) | — | Two-way bindable value. | |
FileList | undefined (bindable) | — | Bindable FileList, only meaningful when type="file". | |
boolean | false | Disables input and drops the opacity to 50%. | |
'true' | 'false' | — | Flips the focus ring to destructive without changing layout. Pair with aria-describedby pointing at the error. | |
HTMLInputElement | null | null | Two-way-bindable element reference. | |
string | — | Merged onto the root via tailwind-merge. |