Input field Components

The Input component allows you to change the input size, add disabled, helper text, and floating label.

Sizes

User the size prop to change the input size. Choose one from 'sm:text-md' | 'text-sm' | 'sm:text-xs'. The default size is text-sm.

Examples

<script>
import { Input } from 'flowbite-svelte'
</script>
<Input
  class="mb-6"
  id="large-input"
  name="size"
  type="text"
  size="sm:text-md"
  value="large"
  placeholder="Write your text here."
  label="Large input"
  required
  />
<Input class="mb-6" placeholder="Base input" label="Base input"/>
<Input class="mb-6" size="sm:text-xs" placeholder="Small input" label="Small input"/>

Focus on load

To focus on an input field and a textarea field on load create a `ref` variable and bind it in an Input component. Add a `onMount` function as followings.

In the next example, when you reload/refresh the page, the First name field is focused on load.

If you want to use this on your website, your link to the page must have `rel="external"`.

<script>
import { onMount } from 'svelte';
let ref

onMount(() => {
  ref.focus();
});
</script>

<Input class="mb-6" placeholder="First name" label="First name" bind:ref/>
<Input class="mb-6" placeholder="Last name" label="Last name"/>

Disabled

Add the disabled prop to change the input to disabled.

<Input class="mb-6" disabled placeholder="disabled input" label="Disabled input"/>
<Input class="mb-6" disabled readonly placeholder="disabled readonly" label="Disabled readonly input"/>

Helper text

Use the helper prop to add your helper text. You can use HTML in the helper text.

You can add helper text in HTML.

<Input label="Email" id="email" name="email" required placeholder="Your email" helper="You can add helper text in <b>HTML</b>."/>

Icon input

With the Iconinput component, you can add Heroicons or Simple-icons. Use iconClass to modify the icon color.

<script>
  import { Iconinput } from 'flowbite-svelte'
</script>
<Iconinput id="email" type="email" name="email" placeholder="Your email" label="Border" icon={AtSymbolOutline} iconClass="h-4 w-4 mr-2 text-blue-500 dark:text-red-500"/>
<div class="py-4">
<Iconinput noBorder id="email" type="email" name="email" label="No border" icon={MailOutline} iconClass="h-4 w-4 mr-2 text-blue-500 dark:text-green-500"/>

Props

The component has the following props, type, and default values. See type-list page for type information.

Input

Name Type Default
type InputType 'text'
value string ''
name string ''
id string generateId()
label string ''
required boolean false
placeholder string ''
size 'sm:text-md' | 'text-sm' | 'sm:text-xs' 'text-sm'
inputClass string `bg-gray-50 border border-gray-300 text-gray-900 ${size} rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full ${padding} dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500`
labelClass string 'block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300'
disabled boolean false
readonly boolean false
helper string ''
helperClass string 'mt-2 text-sm text-gray-500 dark:text-gray-400'
ref HTMLElement null

Iconinput

Name Type Default
label string -
id string generateId()
type InputType -
value string ''
icon typeof SvelteComponent -
helper string ''
placeholder string ''
noBorder boolean false
labelClass string 'block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300'
inputClass string 'rounded-none rounded-r-lg bg-gray-50 border border-gray-300 text-gray-900 focus:ring-blue-500 focus:border-blue-500 block flex-1 min-w-0 w-full text-sm border-gray-300 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500'
spanClass string 'inline-flex items-center px-3 text-sm text-gray-900 bg-gray-200 rounded-l-md border border-r-0 border-gray-300 dark:bg-gray-600 dark:text-gray-400 dark:border-gray-600'
helperClass string 'mt-2 text-sm text-gray-500 dark:text-gray-400'
noBorderInputClass string 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500'
noBorderDivClass string 'flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none'
iconClass string 'h-4 w-4 mr-2'
iconSize number 18

Checkbox

File input

Floating label

Input

Radio

Range

Search

Select

Textarea

Toggle

References

Flowbite Forms