Projects › Beginner
To-Do App with Filters
Add, edit, complete and delete tasks, filter them and keep them after a refresh — the classic way to master the DOM.
Level: Beginner · Time: 2–3 days · Tech stack: HTML, CSS, JavaScript
Features to build
- Add, edit (double-click), complete and delete tasks
- Filters: All / Active / Completed + "clear completed"
- Tasks survive a refresh (localStorage)
- Drag to reorder
- Keyboard friendly
What you will learn
- DOM manipulation
- Event delegation
- State → render pattern
- localStorage and JSON
Step-by-step guide
1. Keep one source of truth
Store tasks in an array and re-render the list from it after every change — don't edit the DOM by hand in many places.
let tasks = JSON.parse(localStorage.getItem('tasks') || '[]');
let filter = 'all';
const save = () => localStorage.setItem('tasks', JSON.stringify(tasks));
2. Render
function render() {
const shown = tasks.filter(t => filter === 'all' || (filter === 'done') === t.done);
list.innerHTML = shown.map(t => `
<li data-id="${t.id}" class="${t.done ? 'done' : ''}">
<input type="checkbox" ${t.done ? 'checked' : ''}> <span>${escapeHtml(t.text)}</span>
<button class="del" aria-label="Delete">×</button>
</li>`).join('');
counter.textContent = `${tasks.filter(t => !t.done).length} left`;
}
Always escape user text before putting it into innerHTML (or use textContent) to avoid XSS.
3. One listener for the whole list (event delegation)
list.addEventListener('click', (e) => {
const id = e.target.closest('li')?.dataset.id;
if (e.target.matches('.del')) tasks = tasks.filter(t => t.id !== id);
if (e.target.matches('input')) tasks = tasks.map(t => t.id === id ? { ...t, done: !t.done } : t);
save(); render();
});
4. Add tasks
Use a <form> so Enter works: on submit, tasks.push({ id: crypto.randomUUID(), text, done: false }), clear the input, save and render.
5. Edit and reorder
Double-click a task to swap the <span> with an <input>; save on Enter or blur. For reordering, use the HTML Drag and Drop API (draggable="true", dragover, drop) and reorder the array.
6. Finish
Add empty-state text, focus styles, and deploy on Netlify or GitHub Pages.
Level it up
- Due dates and priority colours
- Rewrite it in React with useReducer
- Sync tasks to a backend (Express + MongoDB)
On your resume
- Developed a to-do app in vanilla JavaScript with filters, inline editing, drag-and-drop ordering and offline persistence via localStorage.