To Do List
Home
Snippets
To Do List
HTML
CSS
JS
<div class="todo-box"> <h3>My To-Do List</h3> <input type="text" id="taskInput" placeholder="Add a task..." onkeypress="handleKey(event)"> <ul id="taskList"></ul> </div>
body { font-family: sans-serif; background: #f0f4f8; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .todo-box { background: #ffffff; padding: 16px; border-radius: 10px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); width: 260px; box-sizing: border-box; } .todo-box h3 { margin: 0 0 12px; text-align: center; color: #1e293b; } input[type="text"] { width: 100%; padding: 8px; font-size: 14px; border: 1px solid #ccc; border-radius: 6px; margin-bottom: 10px; box-sizing: border-box; } ul { list-style: none; padding: 0; margin: 0; } li { padding: 6px 10px; margin-bottom: 6px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; cursor: pointer; font-size: 14px; transition: all 0.2s; } li.done { text-decoration: line-through; color: #6b7280; background: #e2e8f0; }
function handleKey(event) { if (event.key === 'Enter') { const input = document.getElementById('taskInput'); const text = input.value.trim(); if (!text) return; const li = document.createElement('li'); li.textContent = text; li.onclick = () => li.classList.toggle('done'); li.ondblclick = () => li.remove(); document.getElementById('taskList').appendChild(li); input.value = ''; } }
Ad #1
Ad #2
Scroll to Top