Build a Simple To-Do List App in JavaScript (Beginner Step-by-Step Project)
Build a Simple To-Do List App in JavaScript (Beginner Step-by-Step Project)
After learning the basics of HTML, CSS, and JavaScript, the best way to improve your skills is by building a real project.
In this beginner-friendly guide, you will learn how to create a simple To-Do List web app where users can:
- Add tasks
- Mark tasks as completed
- Delete tasks
This is one of the most popular beginner JavaScript projects and a great step toward becoming a real web developer.
What You Will Learn in This Project
- How HTML, CSS, and JavaScript work together
- How to handle button clicks
- How to change the page using JavaScript
- How to manage a list of items
Step 1: Create the HTML Structure
First, create an index.html file and add this basic structure:
<!DOCTYPE html>
<html>
<head>
<title>To-Do List App</title>
</head>
<body>
<h1>My To-Do List</h1>
<input type="text" id="taskInput" placeholder="Enter a task">
<button onclick="addTask()">Add Task</button>
<ul id="taskList"></ul>
</body>
</html>
This creates:
- A heading
- An input box
- An Add button
- An empty list for tasks
Step 2: Add Simple CSS Styling
Inside the <head>, add this style:
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f2f2f2;
}
input {
padding: 8px;
width: 200px;
}
button {
padding: 8px 12px;
margin-left: 5px;
cursor: pointer;
}
li {
margin: 10px;
cursor: pointer;
}
</style>
Now the app looks clean and simple.
Step 3: Add JavaScript Functionality
Below the list, add this JavaScript code:
<script>
function addTask() {
let input = document.getElementById("taskInput");
let taskText = input.value;
if (taskText === "") return;
let li = document.createElement("li");
li.textContent = taskText;
li.onclick = function() {
li.style.textDecoration = "line-through";
};
let deleteBtn = document.createElement("button");
deleteBtn.textContent = "Delete";
deleteBtn.onclick = function() {
li.remove();
};
li.appendChild(deleteBtn);
document.getElementById("taskList").appendChild(li);
input.value = "";
}
</script>
How This JavaScript Works
- Gets the text from the input box
- Creates a new list item
- Adds a click effect to mark the task complete
- Creates a delete button
- Adds the task to the list
- Clears the input field
This shows how JavaScript can change the web page dynamically.
Step 4: Test Your To-Do List App
- Save the file as index.html.
- Open it in your browser.
- Type a task and click Add Task.
- Click a task to mark it complete.
- Click Delete to remove it.
🎉 Congratulations! You built your first real JavaScript project.
Ideas to Improve This Project
Try adding:
- Save tasks in localStorage
- A clear all button
- Different colors for completed tasks
- A counter showing total tasks
Improving projects is the best way to learn programming.
Common Beginner Mistakes
1. Forgetting to Link JavaScript
Make sure the <script> is inside the HTML file.
2. Empty Task Added
We used this line to stop empty tasks:
if (taskText === "") return;
3. Not Practicing Enough
Projects only help if you try them yourself.
What to Build Next?
- Calculator app
- Weather app using API
- Notes app
- Simple game
Each project makes you a stronger developer.
Final Thoughts
Building a To-Do List app is a big step in your coding journey. You are no longer just learning theory—you are creating real software.
Keep building small projects again and again. That is the fastest way to become confident in programming.
Stay consistent, keep coding, and your skills will grow every single day. 🚀
Comments
Post a Comment