A Kanban board is three columns — To Do, Doing, Done — and cards you move between them. It is the simplest project management tool that exists, and building one teaches you drag and drop, state management, and persistence in a single project.
What you are building
A three-column board where you add tasks, drag them between columns, and everything is saved in localStorage.
The HTML: three columns, one list each
<div class="board">
<div class="column" data-status="todo">
<h2>To Do</h2>
<ul class="card-list"></ul>
<input class="new-task" placeholder="Add a task..." />
</div>
<div class="column" data-status="doing">
<h2>Doing</h2>
<ul class="card-list"></ul>
</div>
<div class="column" data-status="done">
<h2>Done</h2>
<ul class="card-list"></ul>
</div>
</div>
The JavaScript: tasks carry their status
let tasks = JSON.parse(localStorage.getItem('tasks')) || [];
function save() {
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function render() {
document.querySelectorAll('.column').forEach((column) => {
const list = column.querySelector('.card-list');
list.innerHTML = '';
tasks
.filter((t) => t.status === column.dataset.status)
.forEach((task) => {
const li = document.createElement('li');
li.textContent = task.title;
li.draggable = true;
li.dataset.id = task.id;
list.appendChild(li);
});
});
}
// Add a task to the To Do column
document.querySelector('[data-status="todo"] .new-task')
.addEventListener('keydown', (e) => {
if (e.key !== 'Enter' || !e.target.value.trim()) return;
tasks.push({ id: Date.now(), title: e.target.value.trim(), status: 'todo' });
e.target.value = '';
save();
render();
});
// Move a task by dropping it on another column
document.querySelectorAll('.column').forEach((column) => {
column.addEventListener('dragover', (e) => e.preventDefault());
column.addEventListener('drop', (e) => {
const id = Number(e.dataTransfer.getData('text/plain'));
const task = tasks.find((t) => t.id === id);
if (task) {
task.status = column.dataset.status;
save();
render();
}
});
});
document.addEventListener('dragstart', (e) => {
if (e.target.dataset.id) {
e.dataTransfer.setData('text/plain', e.target.dataset.id);
}
});
render();
The key design choice: the task's status lives in the data, not in the DOM. Dragging a card changes task.status, and render() rebuilds the columns from the data. That means saving is trivial — you just save the array.
The one thing to remember
Give every task a stable id — Date.now() works fine for a small app. If you identify tasks by their title or their position in a list, two tasks with the same title will break your drag and drop in confusing ways.
Top comments (0)