Component bindings let you connect data between a parent and child component so they stay in sync automatically.
Component bindings in Svelte
<Child bind:property={parentVariable} />The bind: directive connects a child component's property to a parent variable.
Changes in either the parent or child update the other automatically.
value property of the Input component to the name variable in the parent.<Input bind:value={name} />position property of Slider stays synced with sliderPos in the parent.<Slider bind:position={sliderPos} />checked state of the checkbox is bound to isChecked in the parent.<CustomCheckbox bind:checked={isChecked} />This example shows a parent component with a message variable bound to the text property of the Child component. The child has an input box bound to text. Typing in the input updates message in the parent, and changes to message update the input.
<script> import Child from './Child.svelte'; let message = 'Hello'; </script> <p>Parent message: {message}</p> <Child bind:text={message} /> <!-- Child.svelte --> <script> export let text; </script> <input bind:value={text} aria-label="Child input" />
Use bind: only on properties that the child component explicitly exports.
Bindings keep data in sync both ways without extra code.
Remember to add accessible labels like aria-label for inputs inside child components.
Component bindings connect parent and child data automatically.
Use bind:property to sync values both ways.
This makes UI updates simple and reactive without manual event handling.