Skip to content

Input

The Input component provides text inputs with built-in label, hint, and error handling.

---
import Input from '@/components/ui/Input.astro';
---
<Input name="email" type="email" placeholder="you@example.com" />
<Input
label="Email"
name="email"
type="email"
hint="We'll never share your email"
/>
<Input
label="Password"
name="password"
type="password"
error="Must be at least 8 characters"
/>
<!-- Leading icon -->
<Input
label="Search"
name="search"
leadingIcon="search"
placeholder="Search..."
/>
<!-- Trailing icon -->
<Input
label="Amount"
name="amount"
trailingIcon="dollar-sign"
/>
<!-- Both icons -->
<Input
label="Website"
name="website"
leadingIcon="globe"
trailingIcon="external-link"
/>
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />

For inputs on dark backgrounds:

<section class="bg-surface-invert p-8">
<Input
variant="invert"
label="Email"
name="email"
placeholder="you@example.com"
/>
</section>
PropTypeDefaultDescription
labelstringLabel text
errorstringError message
hintstringHelper text
size'sm' | 'md' | 'lg''md'Input size
variant'default' | 'invert''default'Color variant
leadingIconstringIcon at start
trailingIconstringIcon at end
namestringInput name
typestring'text'Input type
placeholderstringPlaceholder text
requiredbooleanfalseRequired field
disabledbooleanfalseDisabled state
  • Label is properly associated with input
  • Error messages are announced
  • Required fields are marked
  • Focus states are visible
<form class="space-y-4">
<Input
label="Email"
name="email"
type="email"
required
/>
<Input
label="Password"
name="password"
type="password"
required
/>
<Button type="submit" fullWidth>Sign In</Button>
</form>
<Input
name="search"
leadingIcon="search"
placeholder="Search..."
size="lg"
/>
<div class="flex gap-2">
<Input
name="email"
type="email"
placeholder="Enter your email"
class="flex-1"
/>
<Button type="submit">Subscribe</Button>
</div>