Svelte provides specialized binding directives for checkboxes and radio groups: bind:checked for checkboxes and bind:group for radio buttons. This allows two-way binding between the input state and a variable.
Here, the isSubscribed variable automatically updates when the checkbox is toggled, and the checkbox reflects any changes to isSubscribed.
All radio buttons bound to the same group variable automatically stay in sync. Selecting one radio button updates the variable, and changing the variable updates the selected radio button.
Use bind:checked for single checkboxes or arrays for multiple checkboxes.
Use bind:group to link a set of radio buttons to a single variable.
Bindings create two-way synchronization automatically.
Combine bindings with reactive statements ($:) to react to changes dynamically.
Ensure all radio buttons in a group share the same bind:group variable.