index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>To-Do List</title>
</head>
<body>
<div class="todo-container">
<h1>To-Do List</h1>
<div id="app">
<input type="text" id="taskInput" placeholder="Add a new task">
<button onclick="addTask()">Add Task</button>
<ul id="taskList"></ul>
</div>
</div>
<script src="app.js"></script>
</body>
</html>
style.css
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f8f8f8;
}
.todo-container {
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
ul {
list-style: none;
padding: 0;
}
li {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
border-bottom: 1px solid #ddd;
}
button {
margin-top: 10px;
padding: 8px 12px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
app.js
function addTask() {
const taskInput = document.getElementById('taskInput');
const taskList = document.getElementById('taskList');
if (taskInput.value.trim() === '') {
alert('Please enter a task.');
return;
}
const taskItem = document.createElement('li');
taskItem.innerHTML = `
<span>${taskInput.value}</span>
<button onclick="removeTask(this)">Remove</button>
`;
taskList.appendChild(taskItem);
taskInput.value = '';
}
function removeTask(button) {
const taskItem = button.parentElement;
taskItem.remove();
}