Skip to main content

Create a stylish animated to do list with HTML, CSS, Javascript

Creating a stylish animated to-do list is a fun and simple project that can be done with HTML, CSS, and JavaScript. Follow this guide to create your own to-do list with the ability to add and remove tasks dynamically.

Step 1: Setting Up the HTML

First, create the basic HTML structure for the to-do list. Here’s the HTML setup:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Stylish Animated To-Do List</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>

  <div class="todo-list">
    <h2>To-Do List</h2>
    <ul>
      <li class="task">Task 1 <span class="close">×</span></li>
      <li class="task">Task 2 <span class="close">×</span></li>
      <li class="task">Task 3 <span class="close">×</span></li>
    </ul>
    <input type="text" id="taskInput" placeholder="New task...">
    <button id="addBtn">Add</button>
  </div>

  <script src="script.js"></script>
</body>
</html>

Step 2: Styling with CSS

Next, style the to-do list to make it visually appealing. Here’s the CSS you need:

body {
  font-family: Arial, sans-serif;
  background-color: rgb(83, 23, 250);
}

.todo-list {
  max-width: 400px;
  margin: 150px auto;
  padding: 20px;
  border-radius: 10px;
  background-color: #f6a801;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
  text-align: center;
  color: #333;
}

ul {
  list-style-type: none;
  padding: 0;
}

.task {
  margin-bottom: 10px;
  padding: 10px;
  background-color: #fff;
  border-radius: 5px;
  position: relative;
  transition: background-color 0.3s;
}

.task:hover {
  background-color: #f0f0f0;
}

.close {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  color: #999;
  cursor: pointer;
  font-weight: bold;
}

.close:hover {
  color: #666;
}

input[type="text"] {
  width: 70%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin-right: 10px;
}

button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  background-color: #4CAF50;
  color: #fff;
  cursor: pointer;
}

button:hover {
  background-color: #45a049;
}

Step 3: Adding Functionality with JavaScript

Finally, add JavaScript to control the to-do list. This script will manage adding and removing tasks:

document.getElementById("addBtn").addEventListener("click", function() {
  var inputValue = document.getElementById("taskInput").value;
  if (inputValue === '') {
    alert("You must write something!");
  } else {
    var li = document.createElement("li");
    li.className = "task";
    li.textContent = inputValue;
    document.querySelector(".todo-list ul").appendChild(li);
    document.getElementById("taskInput").value = "";

    var span = document.createElement("span");
    span.className = "close";
    span.textContent = "×";
    li.appendChild(span);

    var close = document.getElementsByClassName("close");
    for (var i = 0; i < close.length; i++) {
      close[i].addEventListener("click", function() {
        var div = this.parentElement;
        div.style.display = "none";
      });
    }
  }
});

With this code, you now have a functional to-do list. You can add new tasks and remove them by clicking the close button. Feel free to modify the styles and functionality to suit your preferences.

Conclusion

Creating a stylish animated to-do list is a straightforward project that helps you understand the basics of HTML, CSS, and JavaScript. This guide provides a simple example that you can build upon. Happy coding!

---

Comments

Popular posts from this blog

Creating a Simple Car Racing Game with HTML, CSS, Javascript

In this post, we will create a simple car racing game using HTML, CSS, and JavaScript. This game will feature a player car, an opponent car, and a score counter. The player can move their car left and right to avoid collisions with the opponent car. Let's dive into the code! HTML Structure The HTML structure consists of a game area that contains the road, player car, opponent car, and score display: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Car Racing Game</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="gameArea"> <div class="road"></div> <div class="playerCar"></div> <div class="opponentCar"></div...

Pac-Man Game in HTML, CSS, and JavaScript

In this tutorial, we will create a classic Pac-Man game using HTML, CSS, and JavaScript. Follow the steps to build the game board, Pac-Man, and implement the game logic. HTML Structure First, we need to set up the HTML structure for our Pac-Man game. This includes the game board and score display: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Pac-Man Game</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Pac-Man Game</h1> <div id="game-board"></div> <div id="score-display">Score: 0</div> <script src="script.js"></script> </body> </html> CSS Styling Next, we add some CSS to style the game board, walls, dot...

Creating an Interactive Tic Tac Toe Game

In this tutorial, we'll walk through the steps to create a dynamic Tic Tac Toe game using HTML, CSS, and JavaScript. This classic game is a great way to practice your web development skills and learn more about interactive web applications. HTML Structure We'll start with the HTML structure, which includes the game board, a reset button, and a status display: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tic Tac Toe</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h1>Tic Tac Toe</h1> <div id="board" class="board"></div> <button id="reset">Reset Game</button> <div id=...