Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://kit.fontawesome.com/82bf97873e.js"></script>
    <title>To-Do</title>
</head>
<body>
  <div id="container">
  <section>
    <div id="icon">
      <i class="fas fa-tasks"></i>
    </div>
    <input type="text" />
    <div class="empty-list-note">
      <p>Got something to do?<p>
      <p>Type it out and hit ENTER!</p>
    </div>
    <ul>
    </ul>
  </section>
  </div>
  <div id="invisible"></div>
  </body>
</html>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Varela+Round&display=swap');

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
  border:none;
  background-image:none;
  background-color:transparent;
  -webkit-box-shadow: none;
  -moz-box-shadow: none;
  box-shadow: none;
  -moz-user-select: none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  font-family: 'Varela Round', sans-serif;
  font-size: 1em;
  color: #787878;
  transition: all 0.3s ease-in-out;
}

body {
  min-height: 100vh;
  background: linear-gradient(#6585ed,#349cff);
  
}

#container {
  position: absolute;
	top:0;
	bottom: 0;
	left: 0;
	right: 0; 	
	margin: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  align-content: center;
}

section {
  width: 350px;
  height: 400px; 
  padding: 1.8em;
  margin-top: 40px;
  border-radius: 0.5em;
  box-shadow: 0 3px 6px rgba(0,0,0,0.10), 0 3px 6px rgba(0,0,0,0.17);
  background-image: linear-gradient( #fdfbfb 0%, #ebedee 100%);  
}

#icon {
  width: 120px;
  height: 120px;
  margin-left: auto;
  margin-right: auto;
  margin-top: -80px;
  margin-bottom: 0.3em;
  -moz-border-radius: 60px;
  -webkit-border-radius: 60px;
  border-radius: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  align-content: center;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15), 0 3px 6px rgba(0,0,0,0.22);
  background-image: linear-gradient(to top, #ebedee 50%, #fff 100%);
}

i {
  font-size: 3.5rem;
}

input {
  width: 100%;
  border: 1px solid #eee;
  border-radius: 0.5em;
  height: 2rem;
  margin-top: 1em;
  margin-bottom: 1em;
  padding: 1em;
  background-color: white;
  color: #8f8f8f;
  box-shadow: 0 1px 3px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.17);
}

input:focus{
    outline: none;
}

.empty-list-note {
  font-size: 0.7em;
  text-align: center;
  padding: 1em;
}

p {
  margin: 0.1em 0;
  color: #c4c4c4;
}

.hide {
 display: none;
}

ul {
  padding: 0;
  margin-top: 5px;
  list-style-type:none;
  height: 230px;
  overflow:auto;
  overflow: -moz-scrollbars-none;
  -ms-overflow-style: none;
}

ul::-webkit-scrollbar { width: 0 !important }

li { 
  padding:0.8em 1em;
  margin-top: 0.5em;
  cursor:pointer;
  background:#e8e8e8;
  border-radius: 2rem;
}

li:first-child { 
  margin-top: 0
}

li:hover{
  text-decoration: line-through;
  color: #6585ed;
}

.bounce-in-fwd {
	-webkit-animation: bounce-in-fwd 1s ease-in-out both;
	        animation: bounce-in-fwd 1s ease-in-out both;
}

.bounce-in-bck {
	-webkit-animation: bounce-in-bck 1s ease-in-out reverse both;
	        animation: bounce-in-bck 1s ease-in-out reverse both;
}

.shake-horizontal {
	-webkit-animation: shake-horizontal 0.5s cubic-bezier(0.455, 0.030, 0.515, 0.955) both;
	        animation: shake-horizontal 0.5s cubic-bezier(0.455, 0.030, 0.515, 0.955) both;
}

@-webkit-keyframes bounce-in-fwd {
   0%{
    opacity: 0;
    -webkit-transform: scale(0.3) translate3d(0,0,0);
  }
  50%{
    opacity: 0.9;
    -webkit-transform: scale(1.01);
  }
  80%{
    opacity: 1;
    -webkit-transform: scale(0.89);
  }
  100%{
    opacity: 1;
    -webkit-transform: scale(1) translate3d(0,0,0);
  }
}

@keyframes bounce-in-fwd {
   0%{
    opacity: 0;
    transform: scale(0.3) translate3d(0,0,0);
  }
  50%{
    opacity: 0.9;
    transform: scale(1.01);
  }
  80%{
    opacity: 1;
    transform: scale(0.89);
  }
  100%{
    opacity: 1;
    transform: scale(1) translate3d(0,0,0);
  }
}

@-webkit-keyframes bounce-in-bck {
  0%{
    opacity: 0;
    -webkit-transform: scale(0.3) translate3d(0,0,0);
  }
  50%{
    opacity: 0.9;
    -webkit-transform: scale(1.01);
  }
  80%{
    opacity: 1;
    -webkit-transform: scale(0.89);
  }
  100%{
    opacity: 1;
    -webkit-transform: scale(1) translate3d(0,0,0);
  }
}

@keyframes bounce-in-bck {
      0%{
    opacity: 0;
    transform: scale(0.3) translate3d(0,0,0);
  }
  50%{
    opacity: 0.9;
    transform: scale(1.01);
  }
  80%{
    opacity: 1;
    transform: scale(0.89);
  }
  100%{
    opacity: 1;
    transform: scale(1) translate3d(0,0,0);
  }
}

/* ----------------------------------------------
 * Generated by Animista on 2019-4-7 0:8:49
 * w: http://animista.net, t: @cssanimista
 * ---------------------------------------------- */

/**
 * ----------------------------------------
 * animation bounce-in-fwd
 * ----------------------------------------
 */

@-webkit-keyframes shake-horizontal {
  0%,
  100% {
    -webkit-transform: translateX(0);
            transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70% {
    -webkit-transform: translateX(-10px);
            transform: translateX(-10px);
  }
  20%,
  40%,
  60% {
    -webkit-transform: translateX(10px);
            transform: translateX(10px);
  }
  80% {
    -webkit-transform: translateX(8px);
            transform: translateX(8px);
  }
  90% {
    -webkit-transform: translateX(-8px);
            transform: translateX(-8px);
  }
}
@keyframes shake-horizontal {
  0%,
  100% {
    -webkit-transform: translateX(0);
            transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70% {
    -webkit-transform: translateX(-10px);
            transform: translateX(-10px);
  }
  20%,
  40%,
  60% {
    -webkit-transform: translateX(10px);
            transform: translateX(10px);
  }
  80% {
    -webkit-transform: translateX(8px);
            transform: translateX(8px);
  }
  90% {
    -webkit-transform: translateX(-8px);
            transform: translateX(-8px);
  }
}


#invisible {
  display: inline-block;
  visibility: hidden;
}

              
            
!

JS

              
                // the textfield
const textField = document.querySelector("input");
// the add button
const addButton = document.querySelector("button");
// the list of todos
const todoList = document.querySelector("ul");
//the empty list note
const emptyNote = document.querySelector(".empty-list-note");
//todo character width limit
const cLimit = textField.clientWidth - 35;
//invisible div to check text width
const inv = document.querySelector("#invisible");

//adds todo to list
const addToDo = function(e) {
  // get the current text inside of the text field
  let newTodoText = textField.value;

  //check if enter key is pressed
  if (e.keyCode === 13) {
    //add text to invisible container (used to check character limit)
    inv.innerHTML = newTodoText;
    const currLength = inv.clientWidth;

    //check for valid value
    if (!newTodoText.trim() || newTodoText.length == 0 || currLength > cLimit) {
      
      // invalid todo
      textField.classList.add("shake-horizontal");
      setTimeout(() => {
        textField.classList.remove("shake-horizontal");
      }, 510);
      
    } else {
      //hide empty list note
      emptyNote.classList.add("hide");

      // create a new li element
      let newTodoItem = document.createElement("li");

      // add the text inside of the li element
      newTodoItem.appendChild(document.createTextNode(newTodoText));

      //add the li element to the ul
      todoList.appendChild(newTodoItem);

      newTodoItem.classList.add("bounce-in-fwd");

      //add delete event listener
      newTodoItem.addEventListener("click", () => {
        deleteToDo(newTodoItem);
      });

      //clear text field
      textField.value = "";
    }
  }
};

// deletes to do list element
const deleteToDo = function(todoItem) {
  todoItem.classList.remove("bounce-in-fwd");
  todoItem.classList.add("bounce-in-bck");

  setTimeout(() => {
    todoList.removeChild(todoItem);

    //add empty note again if list size is 0
    if (todoList.querySelectorAll("li").length == 0) {
      emptyNote.classList.remove("hide");
    }
  }, 1100);
};

window.addEventListener("keypress", e => {
  addToDo(e);
});

              
            
!
999px

Console