bind:value for Text Inputs
Keep text input values in sync with component variables automatically.
What bind:value Does
The bind:value directive creates a two-way connection between a variable and a form input.
Basic Example
Bind a let variable to a text input. Typing updates the variable; programmatic changes update the field.
<script>
let name = "";
</script>
<input bind:value={name} />
<p>Hello {name}</p>All lessons in this course
- bind:value for Text Inputs
- bind:checked for Checkboxes
- bind:group for Radio and Checkbox Groups
- bind:this for DOM Element References