Use the Tailwind CSS form and input elements such as checkboxes, radios, textarea, text inputs to collect information from users with Flowbite
The Input component allows you to change the input size, add disabled, helper text, and floating label.
Input 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.
< script>
import { Label, Input } from 'flowbite-svelte' ;
</ script>
< div class = " mb-6" >
< Label for = " large-input" class = " block mb-2" > Large input</ Label>
< Input id = " large-input" size = " lg" placeholder = " Large input" />
</ div>
< div class = " mb-6" >
< Label for = " default-input" class = " block mb-2" > Default input</ Label>
< Input id = " default-input" placeholder = " Default input" />
</ div>
< div class = " mb-6" >
< Label for = " small-input" class = " block mb-2" > Small input</ Label>
< Input id = " small-input" size = " sm" placeholder = " Small input" />
</ div> Expand code Disabled # Get started with this example if you want to apply the disabled state to an input field. Add the disabled to change the input to disabled.
< script>
import { Label, Input } from 'flowbite-svelte' ;
</ script>
< Input id = " disabled-input" class = " mb-6" disabled value = " Disabled input" />
< Input id = " disabled-input-2" class = " mb-6" disabled readonly value = " Disabled readonly input" /> Helper text # Use the helper prop to add your helper text. You can use HTML in the helper text.
< script>
import { Label, Input, Helper } from 'flowbite-svelte' ;
</ script>
< Label class = " block mb-2" > Your email</ Label>
< Input label = " Email" id = " email" name = " email" required placeholder = " name@flowbite.com" />
< Helper class = " text-sm mt-2" >
We’ll never share your details. Read our < a href = " /" class = " font-medium text-primary-600 hover:underline dark:text-primary-500" > Privacy Policy </ a>
.
</ Helper> Input element with icon # With the Input component, you can add Heroicons or other icon sets .
< script>
import { Label, Input, ButtonGroup } from 'flowbite-svelte' ;
import { EnvelopeSolid } from 'flowbite-svelte-icons' ;
</ script>
< div class = " mb-6" >
< Label for = " input-group-1" class = " block mb-2" > Your Email</ Label>
< Input id = " email" type = " email" placeholder = " name@flowbite.com" >
< EnvelopeSolid slot = " left" class = " w-5 h-5 text-gray-500 dark:text-gray-400" />
</ Input>
</ div> Expand code Input element with addon # < script>
import { Label, Input, InputAddon, ButtonGroup } from 'flowbite-svelte' ;
import { UserCircleSolid } from 'flowbite-svelte-icons' ;
</ script>
< div class = " mb-6" >
< Label for = " website-admin" class = " block mb-2" > Username</ Label>
< ButtonGroup class = " w-full" >
< InputAddon>
< UserCircleSolid class = " w-4 h-4 text-gray-500 dark:text-gray-400" />
</ InputAddon>
< Input id = " website-admin" placeholder = " elonmusk" />
</ ButtonGroup>
</ div> Expand code Form validation # Use the following example to apply validation styles for success and error messages.
< script>
import { Label, Input, Helper } from 'flowbite-svelte' ;
</ script>
< div class = " mb-6" >
< Label for = " success" color = " green" class = " block mb-2" > Your name</ Label>
< Input id = " success" color = " green" placeholder = " Success input" />
< Helper class = " mt-2" color = " green" >
< span class = " font-medium" > Well done!</ span>
Some success message.
</ Helper>
</ div>
< div class = " mb-6" >
< Label for = ' error' color = ' red' class = ' block mb-2' > Your name</ Label>
< Input id = ' error' color = ' red' placeholder = " Error input" />
< Helper class = ' mt-2' color = ' red' > < span class = " font-medium" > Not so well done!</ span> Some error message.</ Helper>
</ div> Expand code Textarea # < script>
import { Textarea } from 'flowbite-svelte' ;
let textareaprops = {
id : 'message' ,
name : 'message' ,
label : 'Your message' ,
rows : 4 ,
placeholder : 'Leave a comment...'
} ;
</ script>
< Textarea { ... textareaprops} /> Expand code Select input # Get started with the default example of a select input component to get a single option selection.
< script>
import { Label, Select } from 'flowbite-svelte' ;
let selected;
let countries = [
{ value : 'us' , name : 'United States' } ,
{ value : 'ca' , name : 'Canada' } ,
{ value : 'fr' , name : 'France' }
] ;
</ script>
< Label>
Select an option
< Select class = " mt-2" items= { countries} bind: value={ selected} />
</ Label> Expand code MultiSelect # < script>
import { MultiSelect } from 'flowbite-svelte' ;
let selected = [ ] ;
let countries = [
{ value : 'us' , name : 'United States' } ,
{ value : 'ca' , name : 'Canada' } ,
{ value : 'fr' , name : 'France' } ,
{ value : 'jp' , name : 'Japan' } ,
{ value : 'en' , name : 'England' }
] ;
</ script>
< MultiSelect items= { countries} bind: value={ selected} /> Expand code Checkbox # < script>
import { Checkbox } from 'flowbite-svelte' ;
</ script>
< Checkbox> Default checkbox</ Checkbox>
< Checkbox checked > Checked state</ Checkbox> Radio buttons # < script>
import { Radio } from 'flowbite-svelte' ;
</ script>
< Radio name = " example" > Default radio</ Radio>
< Radio name = " example" checked= { true } > Checked state</ Radio> File upload # < script>
import { Label, Fileupload } from 'flowbite-svelte' ;
let fileuploadprops = {
id : 'user_avatar'
} ;
let fileuploadprops2 = {
id : 'user_avatar2'
} ;
</ script>
< Label class = " pb-2" > Upload file</ Label>
< Fileupload { ... fileuploadprops} /> Expand code Toggle Switch # < script>
import { Toggle } from 'flowbite-svelte' ;
</ script>
< Toggle> Toggle me</ Toggle>
< Toggle checked= { true } > Checked toggle</ Toggle>
< Toggle disabled > Disabled toggle</ Toggle>
< Toggle checked disabled > Disabled checked</ Toggle> Component data # The component has the following props, type, and default values. See types page for type information.
Checkbox
Name Type Default color? FormColorType custom? boolean inline? boolean group? string[] [] choices? CheckboxItem[] value? string | number 'on' checked? boolean undefined spacing? string groupLabelClass? string groupInputClass? string class? string required? boolean
CheckboxButton
Dropzone
Fileupload
Name Type Default files? FileList | undefined undefined inputClass? string 'border !p-0 dark:text-gray-400'
FloatingLabelInput
Name Type Default id? string generateId() style? 'filled' | 'outlined' | 'standard' type? InputType size? 'small' | 'default' color? 'base' | 'green' | 'red' value? any undefined
Helper
Name Type Default helperClass? string 'text-xs font-normal text-gray-500 dark:text-gray-300' color? 'gray' | 'green' | 'red' | 'disabled'
Input
Name Type Default type? InputType 'text' value? any undefined size? FormSizeType undefined clearable? boolean false defaultClass? string 'block w-full disabled:cursor-not-allowed disabled:opacity-50 rtl:text-right' color? 'base' | 'green' | 'red' floatClass? string 'flex absolute inset-y-0 items-center text-gray-500 dark:text-gray-400'
InputAddon
Name Type Default size? 'sm' | 'md' | 'lg' undefined
Label
Name Type Default color? 'gray' | 'green' | 'red' | 'disabled' defaultClass? string 'text-sm rtl:text-right font-medium block' show? boolean true
MultiSelect
Name Type Default items? SelectOptionType<any>[] value? (string | number)[] size? FormSizeType dropdownClass? string '' placeholder? string '' disabled? boolean false
NumberInput
Name Type Default value? number 0
Radio
Name Type Default color? FormColorType custom? boolean inline? boolean group? number | string | undefined undefined value? number | string '' spacing? string checked? boolean false
RadioButton
Name Type Default group string | number '' value string | number '' inline? boolean true pill? boolean false outline? boolean false size? SizeType | undefined undefined color? ButtonColorType | undefined undefined shadow? boolean false
Range
Name Type Default value? number 0 size? 'sm' | 'md' | 'lg'
Search
Name Type Default size? FormSizeType placeholder? string 'Search' value? any undefined
Select
Name Type Default items? SelectOptionType<any>[] [] value? any '' placeholder? string 'Choose option ...' underline? boolean false size? 'sm' | 'md' | 'lg' defaultClass? string 'text-gray-900 disabled:text-gray-400 bg-gray-50 border border-gray-300 rounded-lg focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:disabled:text-gray-500 dark:focus:ring-primary-500 dark:focus:border-primary-500' underlineClass? string 'text-gray-500 disabled:text-gray-400 bg-transparent border-0 border-b-2 border-gray-200 appearance-none dark:text-gray-400 dark:disabled:text-gray-500 dark:border-gray-700 focus:outline-none focus:ring-0 focus:border-gray-200 peer'
Textarea
Name Type Default value? any undefined wrappedClass? string 'block w-full text-sm border-0 px-0 bg-inherit dark:bg-inherit focus:outline-none focus:ring-0 disabled:cursor-not-allowed disabled:opacity-50' unWrappedClass? string 'p-2.5 text-sm focus:ring-primary-500 border-gray-300 focus:border-primary-500 dark:focus:ring-primary-500 dark:focus:border-primary-500 disabled:cursor-not-allowed disabled:opacity-50' innerWrappedClass? string 'py-2 px-4 bg-white dark:bg-gray-800' headerClass? string ''
export let footerClass: $$Props['footerClass'] = '' footerClass? string
Toggle
Name Type Default size? 'small' | 'default' | 'large' | 'custom' group? string[] [] value? string | number '' checked? boolean undefined customSize? string ''
References #