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.

Screenshot of a button with a border that animates into view on hover.

Get Source Code Preview

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

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.

View Output