HTML, CSS & JS Playground · Tutorial

How to build and test a small to-do list page

10 min readbeginnerUpdated

You want to practise web basics by building something real and small. This tutorial makes a to-do list where you can add tasks and tick them off, using the playground’s three editors, its live preview and its console, then saves the result as a single HTML file.

What you need

Steps

  1. Write the structure in HTML

    In the HTML tab, add a heading, a form with a labelled text input and an Add button, and an empty list. The label’s for matches the input’s id, so screen readers announce what the field is for.

    <form id="add">
      <label for="task">New task</label>
      <input id="task" autocomplete="off" required>
      <button>Add</button>
    </form>
    <ul id="list"></ul>
  2. Style it with CSS

    In the CSS tab, give the page a comfortable width and lay out the form in a row with flexbox. Add a .done class that crosses a task out. The preview updates as you type.

  3. Make it work with JavaScript

    In the JavaScript tab, listen for the form’s submit event. Call event.preventDefault() so the page doesn’t reload, create a list item with the input’s text, and add a click handler that toggles the done class.

    form.addEventListener('submit', (event) => {
      event.preventDefault();
      const li = document.createElement('li');
      li.textContent = input.value;
      li.addEventListener('click', () => li.classList.toggle('done'));
      list.append(li);
    });
  4. Check it in the console

    Add console.log('Added:', input.value) inside the handler. Type a task in the preview and press Enter: the message appears in the Console panel. If you misspell a variable, the console shows the error and its line number instead.

  5. Try it as a user

    Add a few tasks, click one to cross it out, and press Enter on an empty field. The required attribute stops empty tasks without any extra code.

  6. Save your work

    Press Download .html. The file contains all three parts and opens in any browser, even offline.

Try it yourself

Opens the HTML, CSS & JS Playground with this tutorial's sample loaded.

Try it now

Common mistakes

The page reloads when you press Add
Forms submit and reload by default. Call event.preventDefault() at the start of the submit handler.
Nothing happens and there’s no error
Check that the IDs in document.querySelector('#list') match the HTML exactly, including case. A null result means the element wasn’t found.
Using alert() to debug
Dialogs are blocked in the preview. Use console.log; its output appears under the preview.

Next steps

Go back to the HTML, CSS & JS Playground, or keep going with one of these:

FAQ

How do I keep the tasks after a reload?

Save the list to localStorage in your script. It works in the downloaded file. Inside the playground preview, storage is switched off for safety, so wrap it in try/catch while testing.

Can I add a framework like Vue or React?

Not from a CDN, because the preview can’t load other websites. Download the file and add the script tag there.