MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
To-Do List with Local Storage0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
14.1Quiz App14.2To-Do List with Local Storage14.3Product Filter App
HomeTutorialsJavaScript for IntermediateTo-Do List with Local Storage
Product Filter App

To-Do List with Local Storage

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

In this project, you will build an enterprise-grade To-Do Task Manager featuring persistent localStorage synchronization, task filtering (All, Active, Completed), inline editing, and empty-state handling.


1. Project Specifications

  1. 1
    State Persistence: All tasks are persisted to localStorage as JSON.
  2. 2
    Task Schema: Each task is an object { id: string, text: string, completed: boolean, createdAt: number }.
  3. 3
    Filtering: Dynamic filter buttons for "All", "Active", and "Completed".
  4. 4
    Action Capabilities: Add task, toggle completion, delete task, and "Clear Completed".
  5. 5
    DOM Performance: Efficient event delegation on the list container.

2. HTML Markup (index.html)

1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8" />
5 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6 <title>TaskFlow: Persistent Task Manager</title>
7 <link rel="stylesheet" href="style.css" />
8</head>
9<body>
10 <main class="app-card">
11 <header class="app-header">
12 <h1>TaskFlow</h1>
13 <p>Organize your day with local persistence</p>
14 </header>
15 
16 <form id="todo-form" class="todo-form">
17 <input type="text" id="todo-input" placeholder="What needs to be done?" required autofocus />
18 <button type="submit" class="btn-add">Add Task</button>
19 </form>
20 
21 <div class="filters-row">
22 <div class="filter-group">
23 <button class="filter-btn active" data-filter="all">All</button>
24 <button class="filter-btn" data-filter="active">Active</button>
25 <button class="filter-btn" data-filter="completed">Completed</button>
26 </div>
27 <button id="btn-clear-completed" class="btn-text">Clear Completed</button>
28 </div>
29 
30 <ul id="todo-list" class="todo-list"></ul>
31 
32 <footer class="app-footer">
33 <span id="items-left">0 items remaining</span>
34 </footer>
35 </main>
36 
37 <script src="app.js"></script>
38</body>
39</html>

3. Styling the App (style.css)

1:root {
2 --primary: #3b82f6;
3 --bg: #0f172a;
4 --card: #1e293b;
5 --text: #f8fafc;
6 --text-muted: #94a3b8;
7 --border: #334155;
8 --danger: #ef4444;
9}
10 
11body {
12 background: var(--bg);
13 color: var(--text);
14 font-family: system-ui, -apple-system, sans-serif;
15 margin: 0;
16 display: flex;
17 justify-content: center;
18 padding: 2rem 1rem;
19}
20 
21.app-card {
22 background: var(--card);
23 border-radius: 1rem;
24 max-width: 550px;
25 width: 100%;
26 padding: 2rem;
27 box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
28}
29 
30.todo-form {
31 display: flex;
32 gap: 0.5rem;
33 margin: 1.5rem 0;
34}
35 
36.todo-form input {
37 flex: 1;
38 padding: 0.75rem 1rem;
39 border-radius: 0.5rem;
40 border: 1px solid var(--border);
41 background: #0f172a;
42 color: var(--text);
43 font-size: 1rem;
44}
45 
46.btn-add {
47 background: var(--primary);
48 color: white;
49 border: none;
50 padding: 0.75rem 1.5rem;
51 border-radius: 0.5rem;
52 cursor: pointer;
53 font-weight: 600;
54}
55 
56.filters-row {
57 display: flex;
58 justify-content: space-between;
59 align-items: center;
60 padding-bottom: 1rem;
61 border-bottom: 1px solid var(--border);
62}
63 
64.filter-btn {
65 background: transparent;
66 border: 1px solid transparent;
67 color: var(--text-muted);
68 padding: 0.25rem 0.75rem;
69 border-radius: 0.25rem;
70 cursor: pointer;
71}
72 
73.filter-btn.active {
74 border-color: var(--primary);
75 color: var(--primary);
76 font-weight: 600;
77}
78 
79.btn-text {
80 background: none;
81 border: none;
82 color: var(--text-muted);
83 cursor: pointer;
84 font-size: 0.85rem;
85}
86 
87.btn-text:hover { color: var(--danger); }
88 
89.todo-list {
90 list-style: none;
91 padding: 0;
92 margin: 1rem 0;
93 display: flex;
94 flex-direction: column;
95 gap: 0.5rem;
96}
97 
98.todo-item {
99 display: flex;
100 align-items: center;
101 gap: 0.75rem;
102 background: #0f172a;
103 padding: 0.75rem 1rem;
104 border-radius: 0.5rem;
105 border: 1px solid var(--border);
106}
107 
108.todo-item.completed span {
109 text-decoration: line-through;
110 color: var(--text-muted);
111}
112 
113.todo-item span { flex: 1; word-break: break-word; }
114 
115.btn-del {
116 background: none;
117 border: none;
118 color: var(--danger);
119 cursor: pointer;
120 font-size: 1.1rem;
121}
122 
123.app-footer {
124 font-size: 0.85rem;
125 color: var(--text-muted);
126 padding-top: 1rem;
127 border-top: 1px solid var(--border);
128}

4. Application Logic (app.js)

1const STORAGE_KEY = 'taskflow_todos_v1';
2 
3// App State
4let todos = JSON.parse(localStorage.getItem(STORAGE_KEY)) || [];
5let activeFilter = 'all';
6 
7// DOM Selectors
8const form = document.querySelector('#todo-form');
9const input = document.querySelector('#todo-input');
10const todoList = document.querySelector('#todo-list');
11const itemsLeft = document.querySelector('#items-left');
12const clearCompletedBtn = document.querySelector('#btn-clear-completed');
13const filterButtons = document.querySelectorAll('.filter-btn');
14 
15function saveAndRender() {
16 localStorage.setItem(STORAGE_KEY, JSON.stringify(todos));
17 render();
18}
19 
20function render() {
21 todoList.innerHTML = '';
22 
23 const filteredTodos = todos.filter(todo => {
24 if (activeFilter === 'active') return !todo.completed;
25 if (activeFilter === 'completed') return todo.completed;
26 return true;
27 });
28 
29 filteredTodos.forEach(todo => {
30 const li = document.createElement('li');
31 li.className = `todo-item ${todo.completed ? 'completed' : ''}`;
32 li.dataset.id = todo.id;
33 
34 const checkbox = document.createElement('input');
35 checkbox.type = 'checkbox';
36 checkbox.checked = todo.completed;
37 checkbox.className = 'toggle-check';
38 
39 const textSpan = document.createElement('span');
40 textSpan.textContent = todo.text;
41 
42 const delBtn = document.createElement('button');
43 delBtn.className = 'btn-del';
44 delBtn.innerHTML = '&times;';
45 delBtn.setAttribute('aria-label', 'Delete task');
46 
47 li.append(checkbox, textSpan, delBtn);
48 todoList.appendChild(li);
49 });
50 
51 const remaining = todos.filter(t => !t.completed).length;
52 itemsLeft.textContent = `${remaining} ${remaining === 1 ? 'item' : 'items'} remaining`;
53}
54 
55// Add Todo
56form.addEventListener('submit', (e) => {
57 e.preventDefault();
58 const text = input.value.trim();
59 if (!text) return;
60 
61 todos.push({
62 id: 'todo_' + Date.now(),
63 text,
64 completed: false,
65 createdAt: Date.now()
66 });
67 
68 input.value = '';
69 saveAndRender();
70});
71 
72// Event Delegation on List (Toggle & Delete)
73todoList.addEventListener('click', (e) => {
74 const itemEl = e.target.closest('.todo-item');
75 if (!itemEl) return;
76 const id = itemEl.dataset.id;
77 
78 if (e.target.classList.contains('toggle-check')) {
79 todos = todos.map(t => t.id === id ? { ...t, completed: !t.completed } : t);
80 saveAndRender();
81 } else if (e.target.classList.contains('btn-del')) {
82 todos = todos.filter(t => t.id !== id);
83 saveAndRender();
84 }
85});
86 
87// Clear Completed
88clearCompletedBtn.addEventListener('click', () => {
89 todos = todos.filter(t => !t.completed);
90 saveAndRender();
91});
92 
93// Filter Tabs
94filterButtons.forEach(btn => {
95 btn.addEventListener('click', () => {
96 filterButtons.forEach(b => b.classList.remove('active'));
97 btn.classList.add('active');
98 activeFilter = btn.dataset.filter;
99 render();
100 });
101});
102 
103// Initial Render
104render();

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why is Event Delegation used on the todoList element instead of attaching listeners to every item?
Question 2
What function deserializes tasks stored in localStorage back into a JavaScript array?
Question 3
What happens when the user clicks the "Clear Completed" button?
Question 4
How is a task's strike-through appearance achieved when marked as completed?
Question 5
What is the benefit of generating unique IDs using 'todo_' + Date.now()?
Next Lesson

Product Filter App

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Quiz AppProduct Filter App

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext