*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    transition: .4s;
}

.input{
    visibility: hidden;
}

.label{
    position: absolute;
    width: 80px;
    height: 40px;
    border-radius: 20px;
    background: lightgray;
    cursor: pointer;
}

.circle{
    width: 34px;
    background-color: rgb(255, 255, 255);
    height: 34px;
    border-radius: 50%;
    top: 3px;
    position: absolute;
    left: 3px;
    animation: toggleOff .4s linear backwards;
}

.input:checked + .label{
    background-color: rgb(255, 255, 255);
}

.input:checked + .label .circle{
    animation: toggleOn .4s linear forwards;  
    background-color: rgb(0, 0, 0);  
}

@keyframes toggleOn {
    0%{
        transform: translateX(0);
    }
    100%{
        transform: translateX(40px);
    }
}

@keyframes toggleOff {
    0%{
        transform: translateX(40px);
    }
    100%{
        transform: translateX(0);
    }
}