<button class="add-remove-button">
    <div></div>
</button>

<!-- twitter / dribbble -->
<a class="dribbble" href="https://dribbble.com/shots/8804079-Add-Remove-Animation" target="_blank"><img src="https://dribbble.com/assets/logo-small-2x-9fe74d2ad7b25fba0f50168523c15fda4c35534f9ea0b1011179275383035439.png" alt=""></a>
<a class="twitter" target="_blank" href="https://twitter.com/aaroniker_me"><svg xmlns="http://www.w3.org/2000/svg" width="72" height="72" viewBox="0 0 72 72"><path d="M67.812 16.141a26.246 26.246 0 0 1-7.519 2.06 13.134 13.134 0 0 0 5.756-7.244 26.127 26.127 0 0 1-8.313 3.176A13.075 13.075 0 0 0 48.182 10c-7.229 0-13.092 5.861-13.092 13.093 0 1.026.118 2.021.338 2.981-10.885-.548-20.528-5.757-26.987-13.679a13.048 13.048 0 0 0-1.771 6.581c0 4.542 2.312 8.551 5.824 10.898a13.048 13.048 0 0 1-5.93-1.638c-.002.055-.002.11-.002.162 0 6.345 4.513 11.638 10.504 12.84a13.177 13.177 0 0 1-3.449.457c-.846 0-1.667-.078-2.465-.231 1.667 5.2 6.499 8.986 12.23 9.09a26.276 26.276 0 0 1-16.26 5.606A26.21 26.21 0 0 1 4 55.976a37.036 37.036 0 0 0 20.067 5.882c24.083 0 37.251-19.949 37.251-37.249 0-.566-.014-1.134-.039-1.694a26.597 26.597 0 0 0 6.533-6.774z"></path></svg></a>
.add-remove-button {
    --color: #fff;
    --duration: 1s;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    outline: none;
    cursor: pointer;
    position: relative;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    &:before,
    &:after,
    div:before,
    div:after {
        content: '';
        top: var(--t, 12px);
        left: var(--l, 18px);
        width: 4px;
        height: 16px;
        border-radius: 2px;
        margin: -8px 0 0 -2px;
        background: var(--color);
        position: absolute;
        transform: rotate(var(--r, 0));
        animation: var(--n, move) var(--duration) ease forwards;
        animation-play-state: var(--p, paused);
    }
    &:after {
        --d: -1;
        --t: 24px;
    }
    div {
        --m: -1;
        --r-a: 180deg;
        --t: 18px;
        --r: 90deg;
        --x: 1px;
        --y: 5px;
        &:before {
            --l: 12px;
        }
        &:after {
            --d: -1;
            --l: 24px;
        }
    }
    &.active {
        --p: running;
        &.inactive {
            --n: move-back;
        }
    }
}

@keyframes move {
    0% {
        transform: rotate(var(--r, 0));
    }
    50% {
        transform: rotate(calc(-45deg * var(--m, 1) + var(--r-a, 0deg)));
    }
    100% {
        transform: translate(calc(var(--x, -5px) * var(--d, 1)), calc(var(--y, 1px) * var(--d, 1))) rotate(calc(-45deg * var(--m, 1) + var(--r-a, 0deg)));
    }
}

@keyframes move-back {
    0% {
        transform: translate(calc(var(--x, -5px) * var(--d, 1)), calc(var(--y, 1px) * var(--d, 1))) rotate(calc(-45deg * var(--m, 1) + calc(var(--r-a, 0deg))));
    }
    50% {
        transform: translate(calc(var(--x, -5px) * var(--d, 1) * .7), calc(var(--y, 1px) * var(--d, 1) * .7))  rotate(var(--r, 0));
    }
    100% {
        transform: rotate(var(--r, 0));
    }
}

html {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

* {
    box-sizing: inherit;
    &:before,
    &:after {
        box-sizing: inherit;
    }
}

// dribbble & twitter
body {
    min-height: 100vh;
    font-family: 'Roboto', Arial;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #275EFE;
    font-family: 'Roboto', Arial, sans-serif;
    .dribbble {
        position: fixed;
        display: block;
        right: 20px;
        bottom: 20px;
        img {
            display: block;
            width: 76px;
        }
    }
    .twitter {
        position: fixed;
        display: block;
        right: 112px;
        bottom: 14px;
        svg {
            width: 24px;
            height: 24px;
            fill: white;
        }
    }
}
View Compiled
document.querySelectorAll('.add-remove-button').forEach(button => {
    button.addEventListener('click', e => {
        if(button.classList.contains('inactive')) {
            button.classList.remove('active', 'inactive');
            button.classList.add('active');
        } else {
            if(button.classList.contains('active')) {
                button.classList.add('inactive');
            }
        }
        if(!button.classList.contains('active')) {
            button.classList.add('active');
        }
    });
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.