init to prod

Week 1 - Todo Lists and CSS

Sam Kamperis

Thursday, October 8, 2026

This week: a todo list

  • 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

  1. Type a task into the input.
  2. Select Add to put it in an array.
  3. Display each task with a remove button.
  4. 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"]);

  function addTodo() {
    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:

<link rel="stylesheet"
  href="https://www.w3schools.com/w3css/6/w3.css">

<div class="w3-container w3-padding">
  <div class="w3-card w3-padding w3-green">A task</div>
</div>

Try w3-container, w3-padding, w3-card and colour classes.

What changes in vanilla JavaScript?

  • Read the input with document.getElementById(...).
  • Add and remove items from the same kind of array.
  • Call a rendering function after changes to update the DOM.
  • In Svelte, the template and reactive state handle that update.

Try it yourself

  1. Open the week 1 examples and add and remove tasks.
  2. Change the colours and spacing using W3.CSS classes.
  3. Extend the Svelte example to reject empty or whitespace-only tasks.
  4. Compare how the Svelte and vanilla versions update the list.

Thank you! Any questions?