<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To-Do Board with Drag & Drop</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.app {
max-width: 1200px;
margin: 0 auto;
}
h1 {
text-align: center;
color: white;
margin-bottom: 30px;
font-size: 2.5em;
text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.add-task {
display: flex;
gap: 10px;
margin-bottom: 30px;
}
#newTask {
flex: 1;
padding: 15px;
font-size: 16px;
border: none;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.add-btn {
padding: 15px 25px;
background: #4CAF50;
color: white;
border: none;
border-radius: 8px;
font-size: 16px;
cursor: pointer;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
.add-btn:hover {
transform: translateY(-2px);
}
.board {
display: flex;
gap: 20px;
flex-wrap: wrap;
}
.column {
flex: 1;
min-width: 300px;
background: rgba(255,255,255,0.1);
backdrop-filter: blur(10px);
padding: 20px;
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
transition: all 0.3s ease;
}
.column h2 {
color: white;
margin-bottom: 20px;
font-size: 1.5em;
text-align: center;
}
.tasks {
min-height: 200px;
display: flex;
flex-direction: column;
gap: 12px;
}
.task {
background: white;
padding: 16px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
cursor: grab;
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.2s ease;
user-select: none;
}
.task:active {
cursor: grabbing;
transform: rotate(2deg);
}
.task.dragging {
opacity: 0.5;
transform: rotate(5deg);
}
.task span {
flex: 1;
font-size: 16px;
}
.delete-btn {
background: #f44336;
color: white;
border: none;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
transition: background 0.2s;
}
.delete-btn:hover {
background: #d32f2f;
}
.column.drag-over {
background: rgba(33, 150, 243, 0.2) !important;
border: 2px dashed #2196F3;
transform: scale(1.02);
}
@media (max-width: 768px) {
.board {
flex-direction: column;
}
.column {
min-width: auto;
}
}
</style>
</head>
<body>
<div class="app">
<h1>🧠 To-Do Board</h1>
<div class="add-task">
<input id="newTask" placeholder="Enter a new task..." maxlength="100">
<button class="add-btn" onclick="addTask()">Add Task</button>
</div>
<div class="board">
<div class="column" id="todo-col">
<h2>To Do</h2>
<div class="tasks" id="todo-tasks"></div>
</div>
<div class="column" id="doing-col">
<h2>In Progress</h2>
<div class="tasks" id="doing-tasks"></div>
</div>
<div class="column" id="done-col">
<h2>Done</h2>
<div class="tasks" id="done-tasks"></div>
</div>
</div>
</div>
<script>
let tasks = {
todo: [],
doing: [],
done: []
};
let nextId = 1;
let draggedTask = null;
function load() {
const saved = localStorage.getItem('todoboard');
if (saved) {
const parsed = JSON.parse(saved);
tasks = parsed.tasks || tasks;
nextId = parsed.nextId || 1;
// Ensure nextId is always greater than max existing ID
let maxId = 0;
Object.values(tasks).forEach(col => {
col.forEach(t => {
if (t.id > maxId) maxId = t.id;
});
});
nextId = Math.max(nextId, maxId + 1);
}
render();
}
function save() {
localStorage.setItem('todoboard', JSON.stringify({ tasks, nextId }));
}
function addTask() {
const input = document.getElementById('newTask');
const text = input.value.trim();
if (!text) return;
tasks.todo.push({ id: nextId++, text });
input.value = '';
render();
save();
}
function deleteTask(id) {
const taskId = parseInt(id);
for (let col of ['todo', 'doing', 'done']) {
const idx = tasks[col].findIndex(t => t.id === taskId);
if (idx !== -1) {
tasks[col].splice(idx, 1);
render();
save();
return;
}
}
}
function render() {
['todo', 'doing', 'done'].forEach(col => {
const container = document.getElementById(col + '-tasks');
container.innerHTML = '';
tasks[col].forEach(task => {
const div = document.createElement('div');
div.className = 'task';
div.draggable = true;
div.dataset.id = task.id;
div.dataset.col = col;
div.innerHTML = `
<span>${escapeHtml(task.text)}</span>
<button class="delete-btn" onclick="deleteTask(${task.id})">Delete</button>
`;
container.appendChild(div);
});
});
}
function escapeHtml(text) {
const map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
return text.replace(/[&<>"']/g, m => map[m]);
}
// Drag and Drop Event Listeners
document.addEventListener('dragstart', e => {
const task = e.target.closest('.task');
if (task) {
draggedTask = task;
task.classList.add('dragging');
}
});
document.addEventListener('dragend', e => {
const task = e.target.closest('.task');
if (task) {
task.classList.remove('dragging');
draggedTask = null;
}
// Remove drag-over from all columns
document.querySelectorAll('.column').forEach(col => col.classList.remove('drag-over'));
});
document.addEventListener('dragover', e => {
e.preventDefault();
});
document.addEventListener('dragenter', e => {
const col = e.target.closest('.column');
if (col && draggedTask) {
col.classList.add('drag-over');
}
});
document.addEventListener('dragleave', e => {
const col = e.target.closest('.column');
if (col && draggedTask) {
col.classList.remove('drag-over');
}
});
document.addEventListener('drop', e => {
e.preventDefault();
if (!draggedTask) return;
const tasksContainer = e.target.closest('.tasks');
if (!tasksContainer) return;
const newCol = tasksContainer.id.split('-')[0];
const taskId = parseInt(draggedTask.dataset.id);
// Remove from old column
let taskObj;
for (let col of ['todo', 'doing', 'done']) {
const idx = tasks[col].findIndex(t => t.id === taskId);
if (idx !== -1) {
taskObj = tasks[col].splice(idx, 1)[0];
break;
}
}
if (taskObj) {
// Append to end of new column (simple reordering)
tasks[newCol].push(taskObj);
render();
save();
}
// Remove drag-over
document.querySelectorAll('.column').forEach(col => col.classList.remove('drag-over'));
});
// Enter key to add task
document.getElementById('newTask').addEventListener('keypress', e => {
if (e.key === 'Enter') {
addTask();
}
});
// Initialize
window.addEventListener('load', load);
</script>
</body>
</html>
Features Included:
- Kanban-style columns: To Do, In Progress, Done
- Drag & Drop: Move tasks between columns and reorder within (appends to end for simplicity, with smooth visuals)
- Local Storage: Persists tasks, IDs across sessions
- Add Tasks: Input + button or Enter key (adds to To Do)
- Delete Tasks: Per-task delete button
- Responsive Design: Works on mobile/desktop
- Visual Feedback: Drag opacity, column highlights, hover effects
- Single HTML File: Copy-paste to use instantly
Open in browser, drag tasks around, refresh—data persists! 🚀