CSS Draw Border Button
A border that draws itself around the button, one side after another, on hover.
HTML
<button class="btn-draw">Hover me</button>
CSS
.btn-draw {
position: relative;
padding: 14px 32px;
border: 0;
background: transparent;
box-shadow: inset 0 0 0 2px #e2e8f0;
color: #0f172a;
font: 600 16px/1 system-ui, sans-serif;
cursor: pointer;
}
.btn-draw::before,
.btn-draw::after {
content: "";
position: absolute;
box-sizing: border-box;
width: 0;
height: 0;
border: 2px solid transparent;
}
.btn-draw::before {
top: 0;
left: 0;
}
.btn-draw::after {
right: 0;
bottom: 0;
}
.btn-draw:hover::before,
.btn-draw:hover::after,
.btn-draw:focus-visible::before,
.btn-draw:focus-visible::after {
width: 100%;
height: 100%;
}
/* Top, then right... */
.btn-draw:hover::before,
.btn-draw:focus-visible::before {
border-top-color: #6366f1;
border-right-color: #6366f1;
transition: width 0.2s ease-out, height 0.2s ease-out 0.2s;
}
/* ...then bottom, then left */
.btn-draw:hover::after,
.btn-draw:focus-visible::after {
border-bottom-color: #6366f1;
border-left-color: #6366f1;
transition: border-color 0s 0.4s, width 0.2s ease-out 0.4s, height 0.2s ease-out 0.6s;
}
.btn-draw:focus-visible {
outline: none;
}
About this CSS Draw Border Button
This CSS Draw Border Button is 58 lines of pure CSS (1.1 KB) with no JavaScript and no dependencies. It uses transitions, box shadows and keyboard focus styles. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#e2e8f0#0f172a#6366f1
How to use this draw border button
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.btn-drawclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.