Build a  To Do List Using HTML, CSS, & JavaScript

Build a To Do List Using HTML, CSS, & JavaScript

 

In this tutorial, we will be building a To-Do List using HTML, CSS, and JavaScript. If you are a beginner and tired of studying from boring theoretical tutorials then you are in the right place because here we will practically build this To-Do from scratch.

The to-do list we’ll build in this tutorial will be pretty basic. A user can add a task, mark a task as completed, and delete an already added task. I’ll explain how to build each feature, but you must follow along by typing the code and running it on your end to get the most out of this tutorial.

Digital To-Do List in JavaScript [Source Codes]

To create this program [To Do List]. First, you need to create three files, HTML File, CSS File, and JavaScript File. After creating these files just paste the following codes into your files. You can also download the source code files of the Digital Clock from the given download buttom.

First, create an HTML file with the name of index.html and paste the given codes in your HTML file. Remember, you’ve to create a file with .html extension.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Javascript To Do List</title>
    <link rel="stylesheet" href="main.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css">
</head>
    <div class="container">
        <div class="header">
            <div class="clear">
                <h2 id="title">
                    To Do List App
                </h2>
                <i class="fas fa-sync-alt"></i>
            </div>
            <div id="date"></div>
        </div>
        <div class="content">
            <div id="list"></div>
            <div class="add-item">
                <input type="text" placeholder="Add a To-Do">
                <i class="fas fa-plus-circle" id="push"></i>
            </div>
        </div>
    </div>
    <script src="main.js"></script>
</body>
</html>

Second, create a CSS file with the name of style.css and paste the given codes in your CSS file. Remember, you’ve to create a file with .css extension.

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

* {
    margin0;
    padding0;
    box-sizingborder-box;
}

body {
    min-height100vh;
    font-family'Poppins'sans-serif;
    background#d1dfec;
}

.container {
    positionabsolute;
    width325px;
    background#15161a;
    padding2px;
    top50%;
    left50%;
    transformtranslate(-50%-50%);
    border-radius10px;
}

.header {
    positionrelative;
    height200px;
    padding20px;
}

.clear {
    padding0 10px;
    width100%;
    height180px;
    font-size30px;
    color#fff;
    text-alignright;
}

#title {
    positionabsolute;
    font-size25px;
    font-weight500;
    text-alignleft;
}

#date {
    width100%;
    font-size21px;
    font-weightbold;
    color#fff;
    text-aligncenter;
}

.content {
    height100%;
    min-height300px;
    margin-top50px;
}

#list {
    height90%;
    min-height290px;
    border-bottom2px solid #8052ec;
}

.add-item {
    height100%;
    min-height40px;
    padding8px;
    color#8052ec;
}

input[type=text] {
    width87%;
    height40px;
    displayinline;
    padding10px;
    bordernone;
    font-size18px;
    background#15161a;
}

input[type=text]::placeholder {
    color#fff;
}

.add-item .fas {
    displayinline-block;
    font-size34px;
    margin-top7px;
}

.fas {
    cursorpointer;
    transition.1s linear;
}

.fas:hover {
    transformscale(1.2);
}

.list {
    positionrelative;
    width100%;
    height50px;
    displayflex;
    align-itemscenter;
    justify-contentspace-between;
    margin-top10px;
    padding5px 20px;
}

.list span {
    margin0 0 0 20px;
    color#fff;
    cursorpointer;
}

.list button {
    width40px;
    height100%;
    bordernone;
    border-radius50px;
    background#8052ec;
    color#fff;
    outlinenone;
    cursorpointer;
}

.list::after {
    content"";
    positionabsolute;
    width20px;
    height20px;
    top15px;
    left15px;
    background#d1d3d4;
    font-size15px;
    text-aligncenter;
    border-radius50px;
}

.complete {
    text-decorationline-through;
    color#ccc;
}

.complete::after {
    content"\2713";
    positionabsolute;
    width20px;
    height20px;
    top15px;
    left15px;
    backgroundgreen;
    font-size15px;
    text-aligncenter;
    border-radius50px;
}

Last, create a JavaScript file with the name of script.js and paste the given codes in your JavaScript file. Remember, you’ve to create a file with .js extension.

var date = document.getElementById('date');
var clear = document.querySelector(".clear");
// show today date
const options = {weekday:'long',
                  month:'long',
                  day:'numeric'};

const today = new Date();
date.innerHTML = 
today.toDateString("en-us"options);

// clear list

clear.addEventListener('click'function() {
    var child = list.lastElementChild;
    while (child) {
        list.removeChild(child);
        child = list.lastElementChild;
    }
})

// list function

document.querySelector('#push').onclick =
function() {
    if (document.querySelector('.add-item input')
    .value.length == 0) {
        alert ("please anter a list");
    } else {
        document.querySelector('#list').
        innerHTML += `
        <div class="list">
        <span id="listname">
        ${document.querySelector('.add-item input').value}
        </span>
        <button class="delete">
        <i class="far fa-trash-alt"></i>
        </button>
        </div>`;

        var current_list = document.
        querySelectorAll('.delete');
        for (var i = 0i < current_list.lengthi++) {
            current_list[i].onclick = function () {
                this.parentNode.remove();
            }
        }

        var current_list = document.
        querySelectorAll('.list');
        for (var i = 0i < current_list.lengthi++) {
            current_list[i].onclick = function () {
                this.classList.toggle('complete');
            }
        }
        document.querySelector('.add-item input')
        .value = "";
    }
}

Download Source Code: Build a  To-Do List Using HTML, CSS, & JavaScript

That’s all, now you’ve successfully Create a To-Do List In HTML, CSS, Javascript. If your code does not work or you’ve faced any error/problem then please comment down or contact us from the contact page.

Here are a few helpful posts you might want to read, too:

Why learning code? 7 Essential Benefits From Learning Programming

6 Things To Know Before Learning Programming

How to Teach Yourself to Learn Code

If you enjoyed this post about the To-Do List in HTML, CSS, javascript just drop me a line in the comments below!

P.S. If you found this post helpful, please share it with others! Thanks for your support!