Svelte Input Fields - Bitblue

Get started with a collection of input fields built with Tailwind CSS to start accepting data from the user based on multiple sizes, variants, and input types

The input field is an important part of the form element that can be used to create interactive controls to accept data from the user based on multiple input types, such as text, email, number, password, URL, phone number, and more.

For validated forms, prefer FormInput inside a parent Form. FormInput requires Form context and accepts name + label plus all Input props.

Setup

pnpm add @cailabs/components.forms
<script>
	import { Input, Label } from '@cailabs/components.forms';
</script>

See Installation.

Default input

<script>
	import { Input, Label } from '.';
</script>

<form>
	<div class="mb-6 grid gap-6 md:grid-cols-2">
		<div>
			<Label for="first_name" class="mb-2">First name</Label>
			<Input type="text" id="first_name" placeholder="John" required />
		</div>
	</div>
</form>

Sizes

size accepts sm | md (default) | lg.

<script>
	import { Input } from '.';
</script>

<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />

Colors

Theme colors: default (default), tinted, primary, secondary, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.

<script>
	import { Input } from '.';
</script>

<Input color="default" placeholder="Default" />
<Input color="primary" placeholder="Primary" />
<Input color="green" placeholder="Green" />
<Input color="red" placeholder="Red" />

Clearable

This example shows how to create an input field where the user can remove the text with one click.

<script>
	import { Input } from '.';
</script>

<Input clearable value="Clearable input" />

Clear event

<script>
	import { Input } from '.';
</script>

<Input
	clearable
	clearableOnClick={() => {
		alert('Clicked close button!');
	}}
	class="my-4"
/>

Left and right snippets

Use left / right snippets for icons or adornments. Adjust input padding with classes like ps-8.

<script>
	import { Input, Label } from '.';
</script>

<Label class="space-y-2">
	<div>Small input - left icon</div>
	<Input type="email" placeholder="name@flowbite.com" size="sm" class="ps-8">
		{#snippet left()}
			<iconify-icon icon="mynaui:envelope-solid"></iconify-icon>
		{/snippet}
	</Input>
</Label>

Combobox

Pass data (string array) for suggestions. Use onSelect when a suggestion is chosen. Optional: maxSuggestions, comboClass, comboItemClass.

<script>
	import { Input } from '.';
	const carMakers = ['Toyota', 'Ford', 'Honda', 'Chevrolet'];
</script>

<Input data={carMakers} placeholder="Type to search cars..." />
<Input data={carMakers} clearable placeholder="Clearable" onSelect={(item) => console.log(item)} />

Events

Native-style handlers: oninput, onfocus, onblur, onkeydown. Combobox selection uses onSelect. Clear button uses clearableOnClick.

<script>
	import { Input } from '.';
	let value = $state('');
</script>

<Input
	bind:value
	oninput={(e) => console.log('input', e)}
	onfocus={() => console.log('focus')}
	onblur={() => console.log('blur')}
	onkeydown={(e) => console.log('keydown', e.key)}
/>

Accessibility

  • Pair with Label using matching for / id.
  • Use aria-describedby with Helper for hints or errors.
  • Disabled inputs use native disabled and reduced opacity styling.
  • Clear button is keyboard-reachable when clearable is set.

Props

PropTypeDefaultDescription
valuestring | number | string[]—Bindable value
typenative input typetextHTML type
sizesm | md | lgmdControl size
colortheme colordefaultBorder/focus/bg token
left / rightSnippet—Leading / trailing adornments
leftClass / rightClassClassValue—Classes for adornment slots
divClass / wrapperClassClassValue—Wrapper classes
childrenSnippet—Custom input render (advanced)
elementRefHTMLInputElement—Bindable input element
clearablebooleanfalseShow clear button
clearableOnClick() => void—Extra clear callback
clearableClass / clearableSvgClassClassValue—Clear button styling
clearableColorCloseButton color—Clear icon color
datastring[]—Combobox suggestion list
maxSuggestionsnumber—Max combobox items
onSelect(item: string) => void—Combobox selection
comboClass / comboItemClassClassValue—Combobox list styling
oninput / onfocus / onblur / onkeydownevent handlers—Input events
classClassValue—Extra input classes
...restHTML input attrs—placeholder, required, disabled, name, etc.

FormInput

FormInput extends InputProps with name (required), label?, and contextKey?. Must be a child of Form.


© 2026 Bitblue is a registered trademark. All Rights Reserved.