# Draw Border Button

> A border that draws itself around the button, one side after another, on hover.

- Category: [CSS Buttons](https://copy-css.com/category/buttons)
- Tags: border, draw, outline, hover, animation, line
- Live preview: https://copy-css.com/snippets/draw-border-button
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<button class="btn-draw">Hover me</button>
```

## CSS

```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;
}
```

## Notes

- 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.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
