Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <link href='https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css' rel='stylesheet'>

<body>
    <div class="main">
        <h1 class="title">TODO</h1>
        <div class="input__section">
            <div class="form__input_container">
                <div class="input__container">
                    <input type="text" class="todo_input" autofocus="true" placeholder="watch movie, visit friends,..">
                    <i class="add__todo bx bx-plus"></i>
                </div>
            </div>
        </div>
        <ul class="todo__lists"></ul>
    </div></script>
</body>
              
            
!

CSS

              
                
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400&display=swap');

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* --------- VARIABLES ---------- */
:root {
    --primary-color: rgb();
    --second-color: rgb();
    --green-color: rgb(0, 199, 175);
    --red-color: rgb(255, 98, 163);
    --indigo-color: rgb(111, 101, 243);
    --indigo-gray: rgb(171, 177, 200);
    --indigo-gray-alt: rgb(162, 168, 195);
    --dark-color: rgb(58, 57, 78);
    --dark-gray: rgb(188, 187, 194);
    --white-color: #FAFAFF;
    --gray-color: rgb(230, 230, 230);
    --blue-white-color: rgb(241, 239, 255);
}
/* ----------- GENERAL --------- */
body {
    position: relative;
    font-family: 'Poppins', sans-serif;
    color: var(--dark-color);
    background-color: rgb(78, 103, 216);
}
.bx {
    cursor: pointer;
    font-size: 1.5em;
}
li {
    text-decoration: none;
}
/* ----------- MAIN ----------- */
.title {
    color: var(--white-color);
    font-weight: 400;
    text-align: center;
    margin: 1em 0;
}
.main {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 0);
}
/* ------------ TODO INPUT FORM ------- */
.form__input_container {
    display: flex;
    align-items: center;
    justify-content: center;
}
.input__container {
    position: relative;
}
.todo_input {
    background-color: var(--white-color);
    color: var(--dark-color);
    height: 2.5em;
    width: 20em;
    font-size: 18px;
    font-family: 'Poppins', sans-serif;
    padding: 0 .2em;
    border: none;
    outline: none;
    border: thin solid rgba(46, 36, 190, 0.74);
    border-radius: 2px;
}
.bx-plus {
    position: absolute;
    top: 50%;
    left: 90%;
    border-radius: 50%;
    padding: .25em;
    background-color: rgba(200, 198, 212, 0.37);
    transform: translate(-50%, -50%);
    transition: 200ms background-color;
}
.bx-plus:hover {
    background-color: rgba(171, 165, 202, 0.37);
}

/*----------- TODO LISTS -----------*/
.todo__lists {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    margin-top: 1em;
}
.todo__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: .5em 0;
    border: thin solid var(--white-color);
    border-radius: 2px;
    background-color: var(--white-color);
    transition: 200ms transform, 200ms opacity;
}
.delete_todo_item_animation {
    transform: translateX(-20rem);
    opacity: 0;
}
.todo {
    font-size: 18px;
    font-weight: 400;
    margin-left: .3em;
}
.complete_todo_item {
    text-decoration: line-through;
    opacity: .5;
}
.action__buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: .5em;
}
.action__btn {
    cursor: pointer;
    padding: .60em;
    border-radius: 2px;
    color: var(--white-color);
    transition: 200ms background-color;
}
.bx-check,
.bx-trash {
    pointer-events: none;
}
.complete {
    background-color: var(--green-color);
}
.complete:hover {
    background-color: rgb(8, 173, 154);
}
.delete {
    background-color: var(--red-color);
}
.delete:hover {
    background-color: rgb(235, 72, 139);
}
/* ---------- MEDIA QUERIES --------- */
@media screen and (max-width: 480px){
    .todo_input {
        height: 2.5em;
        width: 15em;
    }
}
@media screen and (min-width: 481px){
    .todo_input {
        height: 2.5em;
        width: 25em;
    }
    .bx-plus {
        left: 95%;
    }
}
@media screen and (min-width: 768px){
    .todo_input {
        height: 2.5em;
        width: 32em;
    }
    .bx-plus {
        left: 96%;
        transform: translate(-50%, -50%);
    }
}
@media screen and (min-width: 1024px){
    .todo_input {
        height: 2.5em;
        width: 40em;
    }
    .bx-plus {
        left: 97%;
        transform: translate(-50%, -50%);
    }
}
              
            
!

JS

              
                
const todoListItems = document.querySelector('.todo__lists');
const todoItem = document.querySelectorAll('.todo__item');

const newTodo = document.querySelector('.todo_input');

// Add Todo function
function addTodo() {
    // Todo input
    if(newTodo.value !== ''){
        // Create a Todo Item Div
        const todoItemDiv = document.createElement('li');
        // Add classes to it
        todoItemDiv.className = "todo__item";

        // Create a Todo Div
        const todoDiv = document.createElement('div');
        // Add classes to it
        todoDiv.className = "todo";
        todoDiv.appendChild(document.createTextNode(newTodo.value));

        // Add text node with todo input value
        todoItemDiv.appendChild(todoDiv);

        // ============== create action buttons container =============

        const actionButtonsContainer = document.createElement('div');
        // Add class to it
        actionButtonsContainer.className = "action__buttons";

        // ---------- COMPLETE BUTTON ------------ 

        // Create complete and check icon button
        const completeButton = document.createElement('div');
        const bxCheckIcon = document.createElement('i');

        // Add classes to complete and check button
        completeButton.className = "action__btn complete";
        bxCheckIcon.className = "bx bx-check";

        // Append check icon to complete button.
        completeButton.appendChild(bxCheckIcon);

        actionButtonsContainer.appendChild(completeButton);

        // ---------- DELETE BUTTON ------------ 

        // Create complete and check icon button
        const deleteButton = document.createElement('div');
        const bxTrashIcon = document.createElement('i');

        // Add classes to complete and check button
        deleteButton.className = "action__btn delete";
        bxTrashIcon.className = "bx bx-trash";

        // Append check icon to complete button.
        deleteButton.appendChild(bxTrashIcon);
        
        actionButtonsContainer.appendChild(deleteButton);

        // Append complete button to todo itemDiv
        todoItemDiv.appendChild(actionButtonsContainer);

        todoListItems.appendChild(todoItemDiv);
        newTodo.value = '';

        // Focus input
        // ....

    }else {
        alert("The input is empty!");
    }
}

// -------- ADD TODO -------
const addTodoButton = document.querySelector('.add__todo');

addTodoButton.addEventListener('click', (e) => {
    // e.preventDefault(); // To prevent initial behavior.
    addTodo()
    console.log(todoItem);
})

// ---- COMPLETE TODO ---- 
todoListItems.addEventListener('click', (e) => {
    if(e.target.classList.contains('complete') || e.target.classList.contains('bx-check')){
        var completeButton = e.target.parentElement;
        if(completeButton.parentElement.classList.contains('complete_todo_item')){
            completeButton.parentElement.classList.remove('complete_todo_item');
        }else {
            completeButton.parentElement.classList.add('complete_todo_item');
        }
    }
})

// ---- DELETE TODO ---- 
todoListItems.addEventListener('click', (e) => {
    if(e.target.classList.contains('delete') || e.target.classList.contains('bx-trash')){
        var delButton = e.target.parentElement;
        delButton.parentElement.classList.add('delete_todo_item_animation');
        delButton.parentElement.addEventListener('transitionend', () => {
            delButton.parentElement.remove();
        })
    }
})


// Add todo to local storage

function storeTodoInLocalStorage(todoItemToBeStolen){
    if(typeof(Storage) !== "undefined"){
        localStorage.setItem("todos_stored", todoItemToBeStolen)
    }else {
    
    }
}
              
            
!
999px

Console