Animated Button
Home
Snippets
Animated Button
HTML
CSS
JS
<button class="button"> <span class="text">Button</span> <div class="overlay"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-right"> <path d="M5 12h14" /> <path d="m12 5 7 7-7 7" /> </svg> </div> </button>
* { margin: 0; padding: 0; box-sizing: border-box; } body { height: 100dvh; background: #121212; display: grid; place-items: center; } button { appearance: none; background: transparent; border: none; cursor: pointer; isolation: isolate; } .button { background: #efefef; font-size: 16px; line-height: 1.5; font-weight: 500; width: 240px; border-radius: 9999rem; position: relative; display: flex; justify-content: center; align-items: center; position: relative; isolation: isolate; overflow: hidden; &>span.text { color: #121212; width: 100%; text-align: left; padding-block: 12px; padding-left: 24px; z-index: 2; transition: all 200ms ease; } &>div.overlay { background: #242424; color: #ededed; width: 48px; height: calc(100% - 2px); display: flex; justify-content: flex-end; align-items: center; padding: 12px; border-radius: inherit; position: absolute; right: 1px; z-index: 1; transition: all 400ms ease; } &:is(:hover, :focus) { &>span.text { color: #ededed; } &>div.overlay { width: calc(100% - 2px); transition: width 200ms ease; } } }
//javascript
Ad #1
Ad #2
Scroll to Top