Sun Aug 07 2022

Animated Checkbox

CSS2564 views

File Name: animated-checkbox.html

<!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>Animated Checkbox</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet"> 
    <style>
        * {
            margin: 0;
            padding: 0;
            font-family: 'Poppins', sans-serif;
        }

        body {
            background-color: #292929;
        }

        section {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100vh;
        }

        .checkbox {
            display: flex;
            align-items: center;
        }        

        input[type=checkbox] {
            appearance: none;
            width: 20px;
            height: 20px;
            border-radius: 5px;
            background-color: #fff;
            margin-right: 8px;
            position: relative;
        }

        input[type=checkbox]::before {
            content: '';
            position: absolute;
            width: 0;
            height: 3px;
            background-color: #f00;
            transform: translate(8px, 13px) rotate(-45deg);
            transform-origin: left;
            transition: 150ms all linear;
            transition-delay: 0ms;
        }

        input[type=checkbox]::after {
            content: '';
            position: absolute;
            width: 0;
            height: 3px;
            background-color: #f00;
            transform: translate(1px, 8px) rotate(45deg);
            transform-origin: left;
            transition: 150ms all linear;
            transition-delay: 150ms;
        }

        input[type=checkbox]:checked::before {
            width: 14px;
            transition-delay: 150ms;
        }

        input[type=checkbox]:checked::after {
            width: 10px;
            transition-delay: 0ms;
        }

        label {
            font-size: 20px;
            color: #fff;
            cursor: pointer;
        }
        
    </style>
</head>
<body>
    <section>
        <div class="checkbox">
            <input type="checkbox" name="" id="nodejs" />
            <label for="nodejs">Nodejs Tutorial</label>
        </div>
    </section>
</body>
</html>

Result Screenshot(s)

Animated CheckboxWorking Sample0

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.