Build a list of tasks that users can add to and remove from.
Use Svelte state to keep the page in step with the data.
Add basic styling with the W3.CSS library.
Compare the Svelte approach with vanilla JavaScript.
From interaction to interface
Type a task into the input.
Select Add to put it in an array.
Display each task with a remove button.
Remove a task and update the displayed list.
The array is the data; the visible list is a representation of it.
State and input in Svelte
<script>let text =$state("");let todos =$state(["shopping","read a book"]);functionaddTodo() { todos.push(text); text =""; }</script><input bind:value={text} placeholder="Enter a task"><button onclick={addTodo}>Add</button>
bind:value keeps the input and text in sync. $state makes the data reactive.
Display and remove tasks
{#each todos as task, i}<div> Task {i + 1}: {task}<button onclick={()=> todos.splice(i, 1)}>Remove</button></div>{/each}
{#each} creates an interface for each array item.
Removing an item changes the array; Svelte updates the list.
Styling with W3.CSS
Load the stylesheet, then apply its classes to your markup: