Animated Border Button Template
Add a touch of elegance to your links with a button where the border animates into view on hover.
This subtle micro-interaction adds a modern and professional feel to secondary actions or navigation links without being distracting.
About the Animated Border Button
A simple hover effect can significantly elevate the feel of an interface. This button template moves beyond a basic color change by animating the border itself. When the user hovers over the button, lines gracefully extend from the corners to form a complete border, drawing attention to the element in a dynamic way. This effect is achieved purely with CSS, making it both lightweight and easy to implement.
Features
- Elegant Corner Animation: On hover, the border lines appear to draw themselves from the corners, creating a sharp, technical animation.
- Pure CSS and HTML: The entire effect is created using four CSS pseudo-elements (two on the button, two on an inner span).
- Highly Customizable: Easily change the border color, animation speed, and text color via the provided CSS custom properties.
- Accessible: Built on a semantic
buttonelement with a standard high-contrast focus style.
Code Breakdown
This animation uses a clever but complex technique involving four pseudo-elements. The button itself has a ::before (top border) and ::after (left border). An inner span element also has a ::before (bottom border) and ::after (right border). Each pseudo-element starts with a scale of zero on one axis (e.g., transform: scaleX(0)). On hover, they are all scaled to 1, and their transform-origin is set to different corners (e.g., left, right, top, bottom), causing the lines to expand from different directions to form the full border.
Code
Here is the complete code for the animated border button.