The process of creating a simple To-Do list using HTML, CSS, and JavaScript is very sample. Let's start step by step:
<!DOCTYPE html>
<html>
<head>
<title>To-Do List</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>To-Do List</h1>
<input id="taskInput" type="text" placeholder="Enter a task">
<button id="addTaskButton">Add Task</button>
<ul id="taskList"></ul>
<script src="script.js"></script>
</body>
</html>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
text-align: center;
}
input[type="text"] {
width: 300px;
padding: 5px;
margin-right: 10px;
}
button {
padding: 5px 10px;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 5px;
}
// Get references to the HTML elements
var taskInput = document.getElementById("taskInput");
var addTaskButton = document.getElementById("addTaskButton");
var taskList = document.getElementById("taskList");
// Add event listener to the "Add Task" button
addTaskButton.addEventListener("click", function() {
var task = taskInput.value;
if (task !== "") {
// Create a new list item
var listItem = document.createElement("li");
listItem.innerHTML = task;
// Add the list item to the task list
taskList.appendChild(listItem);
// Clear the input field
taskInput.value = "";
}
});
That's it! You've created a basic To-Do list using HTML, CSS, and JavaScript. You can now open the HTML file in a web browser and start adding tasks to your list.