Dashed Gradient Border Generator
See the Pen Dashed Gradient Border Generator.
Tech & Dependencies
Features
- ✓ Procedural Generation
- ✓ Trigonometric Logic
- ✓ Live Code Preview
- ✓ Animated Gradients
Browser Support
Core
This is an Animated Gradient Border Generator. It bypasses standard CSS border limitations by utilizing stacked repeating-linear-gradient functions applied to the background-image. Its function is to provide developers with a visual interface to dial in specific parameters — slant, gap, fade, and velocity — while instantly outputting the required, mathematically precise CSS code.
Specs
- Weight: ~5 KB (UI + Engine).
- Performance: Uses hardware-accelerated
background-positionanimations for 60fps rendering. - DOM Complexity: Low. The generated result applies entirely to a single HTML node.
Anatomy
The component acts as both a showcase and a functional utility.
- HTML (The Skeleton): A grid-based layout housing range inputs and a live
.resultdisplay container. - CSS (The Skin): Sets up the visual environment. It includes a library of preset
.boxclasses demonstrating the raw capabilities of the background-border technique (dotted, slanted, cornered). - JS (The Nervous System): An event-driven engine. It listens to slider changes, reads the numeric values, and executes complex geometric calculations to dynamically assemble a robust CSS string.
Logic
The defining feature of this script is its trigonometric approach to ensuring seamless animation loops.
const borderLengthPx = Math.round((dashLength + spacing) / Math.sin((90 - Math.abs(slanting)) * Math.PI / 180) * 100) / 100;
const borderLength = (animation > 0) ? `calc(100% + ${borderLengthPx}px)` : '100%';
When a border is slanted, a simple linear translation causes jitter when the animation repeats. This logic uses the Sine function to calculate the exact hypotenuse of the dashed pattern based on the user’s chosen angle. It then expands the background-size (borderLength) by precisely that extra amount, ensuring the background-position shift completes a perfect, imperceptible cycle.
Feel
Tactile and immediate. Moving the sliders provides instantaneous visual feedback. The generated animations feel crisp, geometric, and precise. It takes the abstract, often frustrating syntax of complex CSS gradients and transforms it into a predictable, manipulatable physical object.


