<button class="grid-list without-text">
    <div class="icon">
        <div class="dots">
            <i></i><i></i><i></i><i></i>
        </div>
        <div class="lines">
            <i></i><i></i><i></i><i></i>
        </div>
    </div>
</button>

<button class="grid-list">
    <div class="icon">
        <div class="dots">
            <i></i><i></i><i></i><i></i>
        </div>
        <div class="lines">
            <i></i><i></i><i></i><i></i>
        </div>
    </div>
    <div class="text">
        <span>Grid</span>
        <span>List</span>
    </div>
</button>

<!-- dribbble - twitter -->
<a class="dribbble" href="https://dribbble.com/ai" target="_blank"><img src="https://cdn.dribbble.com/assets/dribbble-ball-mark-2bd45f09c2fb58dbbfb44766d5d1d07c5a12972d602ef8b32204d28fa3dda554.svg" 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>
.grid-list {
    --color: #F6F8FF;
    --background: #2B3044;
    --background-hover: #1E2235;
    --icon-color: #BBC1E1;
    padding: 6px 12px 6px 8px;
    margin: 0;
    display: flex;
    outline: none;
    position: relative;
    border: none;
    border-radius: 9px;
    background: var(--b, var(--background));
    cursor: pointer;
    -webkit-appearence: none;
    -webkit-tap-highlight-color: transparent;
    transform: scale(var(--scale, 1)) translateZ(0);
    transition: transform .15s, background .4s;
    &:active {
        --scale: .95;
    }
    &:hover {
        --b: var(--background-hover);
    }
    &.without-text {
        --background: #275EFE;
        --background-hover: #1548DB;
        --icon-color: #FFFFFF;
        padding: 6px;
    }
    .icon {
        width: 24px;
        height: 24px;
        position: relative;
        i {
            position: absolute;
            left: var(--left, 4px);
            top: var(--top, 4px);
            display: block;
            border-radius: 2px;
            width: var(--width, 7px);
            height: var(--height, 7px);
            background: var(--icon-color);
            animation: var(--name, var(--dots-name, none)) var(--duration, var(--dots-duration, .5s)) var(--easing, var(--dots-easing, linear)) forwards var(--delay, var(--dots-delay, 0s));
        }
        .dots {
            i {
                &:nth-child(1) {
                    --x-middle: -8px;
                    --y-middle: 10px;
                    --x-end: -2px;
                    --y-end: 12px;
                    --x-back: 10px;
                    --y-back: 7px;
                    --x-back-end: 9px;
                    --y-back-end: 0;
                }
                &:nth-child(2) {
                    --left: 13px;
                    --x-middle: -12px;
                    --y-middle: 5px;
                    --x-end: -11px;
                    --y-end: 7px;
                    --x-back: -3px;
                    --y-back: 1px;
                    --x-back-end: -9px;
                    --y-back-end: 0;
                }
                &:nth-child(3) {
                    --top: 13px;
                    --x-middle: 4px;
                    --y-middle: -5px;
                    --x-end: -2px;
                    --y-end: -7px;
                    --x-back: -5px;
                    --y-back: 0px;
                    --x-back-end: 9px;
                    --y-back-end: 0;
                }
                &:nth-child(4) {
                    --left: 13px;
                    --top: 13px;
                    --x-middle: 0;
                    --y-middle: -10px;
                    --x-end: -11px;
                    --y-end: -12px;
                    --x-back: -14px;
                    --y-back: -8px;
                    --x-back-end: -9px;
                    --y-back-end: 0;
                }
            }
        }
        .lines {
            --name: var(--lines-name, none);
            --duration: var(--lines-duration, .15s);
            --easing: var(--lines-easing, linear);
            --delay: var(--lines-delay, 0s);
            i {
                --left: 9px;
                --top: 3px;
                --height: 2px;
                --width: 11px;
                transform: translateY(20%) translateZ(0) scaleX(0);
                &:nth-child(2) {
                    --top: 8px;
                }
                &:nth-child(3) {
                    --top: 13px;
                }
                &:nth-child(4) {
                    --top: 18px;
                }
            }
        }
    }
    .text {
        margin-left: 4px;
        position: relative;
        line-height: 24px;
        font-weight: 600;
        font-size: 14px;
        min-width: 28px;
        color: var(--color);
        span {
            --y-default: 0;
            --o-default: 1;
            --y-active: -12px;
            --o-active: 0;
            display: block;
            opacity: var(--o-default);
            transform: translateY(var(--y-default)) translateZ(0);
            animation: var(--span-name, none) .4s ease forwards;
            &:last-child {
                --y-default: 12px;
                --o-default: 0;
                --y-active: 0;
                --o-active: 1;
                position: absolute;
                left: 0;
                top: 0;
            }
        }
    }
    &.animation {
        --span-name: text;
        --dots-name: back;
        --lines-name: scale-down;
        .lines {
            i {
                transform-origin: 0 50%;
                &:nth-child(3),
                &:nth-child(4) {
                    transform-origin: 100% 50%;
                }
            }
        }
        &.active {
            --span-name: text-active;
            --dots-name: move;
            --lines-name: scale;
            --lines-duration: .15s;
            --lines-delay: .3s;
            .lines {
                i {
                    transform-origin: 100% 50%;
                    &:nth-child(3),
                    &:nth-child(4) {
                        transform-origin: 0 50%;
                    }
                }
            }
        }
    }
}

@keyframes text {
    0% {
        opacity: var(--o-active);
        transform: translateY(var(--y-active)) translateZ(0);
    }
    100% {
        opacity: var(--o-default);
        transform: translateY(var(--y-default)) translateZ(0);
    }
}

@keyframes text-active {
    0% {
        opacity: var(--o-default);
        transform: translateY(var(--y-default)) translateZ(0);
    }
    100% {
        opacity: var(--o-active);
        transform: translateY(var(--y-active)) translateZ(0);
    }
}

@keyframes move {
    50% {
        transform: translate(var(--x-middle, 0), var(--y-middle, 0)) scale(.4);
    }
    100% {
        transform: translate(var(--x-end, 0), var(--y-end, 0)) scale(.4);
    }
}

@keyframes back {
    0%,
    15% {
        transform: translate(var(--x-end, 0), var(--y-end, 0)) scale(.4);
    }
    50% {
        transform: translate(var(--x-back, 0), var(--y-back, 0)) scale(.5);
    }
    100% {
        transform: translate(var(--x-back-end, 0), var(--y-back-end, 0)) scale(1);
    }
}

@keyframes scale {
    100% {
        transform: translateY(20%) translateZ(0) scaleX(1);
    }
}

@keyframes scale-down {
    0% {
        transform: translateY(20%) translateZ(0) scaleX(1);
    }
    100% {
        transform: translateY(20%) translateZ(0) scaleX(0);
    }
}

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

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

// Center & dribbble
body {
    min-height: 100vh;
    display: flex;
    font-family: 'Inter', Arial;
    justify-content: center;
    align-items: center;
    background: #ECEFFC;
    .without-text {
        margin-right: 20px;
    }
    .dribbble {
        position: fixed;
        display: block;
        right: 20px;
        bottom: 20px;
        img {
            display: block;
            height: 28px;
        }
    }
    .twitter {
        position: fixed;
        display: block;
        right: 64px;
        bottom: 14px;
        svg {
            width: 32px;
            height: 32px;
            fill: #1da1f2;
        }
    }
}
View Compiled
document.querySelectorAll('.grid-list').forEach(button => button.addEventListener('click', toggle));

function toggle() {
    let btn = this;
    btn.classList.add('animation');
    btn.classList.toggle('active');
    let newElem = btn.cloneNode(true);
    btn.parentNode.replaceChild(newElem, btn);
    newElem.addEventListener('click', toggle);
}

External CSS

  1. https://fonts.googleapis.com/css?family=Inter:400,500,600,700&amp;display=swap

External JavaScript

This Pen doesn't use any external JavaScript resources.