About Dashed Border Generator
The CSS border property gives you dashes, but not their length, their spacing or their ends: each browser draws border-style: dashed its own way. This tool draws the border as a small SVG instead and puts it behind the element as a background image, so you choose the dash length, the gap, the line width, rounded or flat ends and the corner radius, and it looks the same everywhere.
Turn on animation for a moving "marching ants" border, often used for drop zones and selections. The CSS it writes includes a still version for people who have asked their system for less motion.
How it works
- A rectangle that fills the element is stroked with stroke-dasharray. Its stroke is centred on the edge and the outer half falls outside, so the stroke is drawn at twice the line width you choose.
- Round and square ends reach past each dash, so that reach is taken off the dash and added to the gap. The dash length and spacing you set are what you see.
- Animation moves stroke-dashoffset by exactly one dash and one gap per loop, so the movement never jumps.
- The SVG is escaped into a data URI rather than Base64, which keeps the CSS short and still readable.
Questions
Why not just use border-style: dashed?
Because CSS does not let you set the dash length or the gap, and browsers draw dashed borders differently, especially around rounded corners. A background image gives you the same border in every browser.
How do I make a dotted border?
Set the dash length to 0 and the ends to Round. Each dot is then as wide as the line, and the gap sets how far apart they are.
Does the border take up space like a real border?
No. It is painted inside the element as a background, so it does not change the element size. Add padding if your content should keep clear of it.
Will the animation run for people who prefer less motion?
The CSS includes a prefers-reduced-motion rule that swaps in a still border, and the preview here also stays still when your system asks for less motion.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.