A simple To-Do List App built with HTML, CSS, and JavaScript. It allows users to:
- ✅ Add new tasks
- ✅ Mark tasks as completed
- ✅ Delete tasks
- ✅ Works without any external libraries
Features
- Add unlimited tasks.
- Click a task to mark it as completed.
- Delete tasks individually.
- Press Enter to add a task quickly.
- Responsive and beginner-friendly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To-Do List App</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>📝 To-Do List</h1>
<div class="input-box">
<input type="text" id="taskInput" placeholder="Enter a task...">
<button onclick="addTask()">Add</button>
</div>
<ul id="taskList"></ul>
</div>
<script src="script.js"></script>
</body>
</html>
style.css
*{
margin:0;
padding:0;
box-sizing:border-box;
font-family:Arial, Helvetica, sans-serif;
}
body{
background:#f4f4f4;
display:flex;
justify-content:center;
align-items:center;
height:100vh;
}
.container{
background:#fff;
width:400px;
padding:25px;
border-radius:10px;
box-shadow:0 5px 15px rgba(0,0,0,.2);
}
h1{
text-align:center;
margin-bottom:20px;
}
.input-box{
display:flex;
gap:10px;
}
input{
flex:1;
padding:10px;
border:1px solid #ccc;
border-radius:5px;
}
button{
padding:10px 18px;
border:none;
background:#007BFF;
color:#fff;
cursor:pointer;
border-radius:5px;
}
button:hover{
background:#0056b3;
}
ul{
margin-top:20px;
list-style:none;
}
li{
display:flex;
justify-content:space-between;
align-items:center;
background:#eee;
margin-bottom:10px;
padding:10px;
border-radius:5px;
}
.completed{
text-decoration:line-through;
color:gray;
}
.delete-btn{
background:red;
color:white;
border:none;
padding:5px 10px;
border-radius:4px;
cursor:pointer;
}
.delete-btn:hover{
background:darkred;
}
script.js
const taskInput = document.getElementById("taskInput");
const taskList = document.getElementById("taskList");
function addTask(){
if(taskInput.value.trim()===""){
alert("Please enter a task.");
return;
}
const li = document.createElement("li");
const span = document.createElement("span");
span.textContent = taskInput.value;
// Mark completed
span.addEventListener("click", function(){
span.classList.toggle("completed");
});
// Delete button
const deleteBtn = document.createElement("button");
deleteBtn.textContent = "Delete";
deleteBtn.className = "delete-btn";
deleteBtn.onclick = function(){
li.remove();
};
li.appendChild(span);
li.appendChild(deleteBtn);
taskList.appendChild(li);
taskInput.value="";
}
// Add task by pressing Enter
taskInput.addEventListener("keypress", function(e){
if(e.key==="Enter"){
addTask();
}
});
Tags
coding-tutorials
