Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentCheckbox
Managercreate_checkbox_manager

svelte

<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Checkbox, create_checkbox_manager } from "sveltekit-ui"

  const manager = create_checkbox_manager({
    label: "Email me product updates",
    name: "product_updates",
    val: false,
  })
</script>

<Checkbox {manager} />
<p>Updates {manager.val ? "enabled" : "disabled"}</p>

API reference

Configure the manager, call its methods, and read its reactive state.

19 entries in configuration

PropertyTypeDefaultDescription
typestring checkboxthe display variant: 'checkbox', 'toggle', or 'dark_theme'
valany nullthe current value of the checkbox, which can match on_val or off_val
on_valany truethe value considered 'checked'
off_valany falsethe value considered 'unchecked'
labelstring nulllabel text displayed beside the checkbox
namestring checkboxthe input name attribute
colorstring var(--primary-t)the base color for the checked state or toggle
is_requiredboolean falsemarks the input as required
is_read_onlyboolean falsemakes the checkbox read-only if true
is_disabledboolean falsedisables the checkbox if true
is_loadingboolean falsedisplays a loading spinner if true
sizenumber 2.4base size in rem for the checkbox or toggle
mlnumber 0margin-left in rem
mrnumber 0margin-right in rem
mtnumber 0margin-top in rem
mbnumber 0margin-bottom in rem
error_messagestring nullan error message displayed next to the checkbox
on_changefunction nullcallback fired when the checkbox toggles, receiving new value
on_hover_changefunction nullcallback fired on pointerenter/leave, receiving true or false