# Marching Ants Border

> An animated dashed border whose dashes crawl around the box like a selection marquee, for drop zones and crops.

- Category: [CSS Effects](https://copy-css.com/category/effects)
- Tags: marching ants, animated dashed border, selection, drop target, gradient, keyframes
- Live preview: https://copy-css.com/snippets/marching-ants-border
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="ants-border">Drop files here</div>
```

## CSS

```css
.ants-border {
  --c: #2563eb;
  display: grid;
  place-items: center;
  width: 240px;
  height: 120px;
  background:
    linear-gradient(90deg, var(--c) 50%, transparent 0) repeat-x 0 0 / 14px 2px,
    linear-gradient(90deg, var(--c) 50%, transparent 0) repeat-x 0 100% / 14px 2px,
    linear-gradient(0deg, var(--c) 50%, transparent 0) repeat-y 0 0 / 2px 14px,
    linear-gradient(0deg, var(--c) 50%, transparent 0) repeat-y 100% 0 / 2px 14px,
    #eff6ff;
  color: #1e40af;
  font: 600 15px system-ui, sans-serif;
  animation: ants-border-march 0.6s linear infinite;
}

@keyframes ants-border-march {
  to {
    background-position: 14px 0, -14px 100%, 0 -14px, 100% 14px, 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ants-border {
    animation: none;
  }
}
```

## Notes

- This CSS Marching Ants Border is 28 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses keyframe animations, linear gradients, CSS Grid and custom properties.
- Customize with: `--c`.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
