The CSS border animation using hover is used to create border animation when we hover over a text. The concepts that we are going to use are before , after and hover selectors. It is highly recommend to go through all these selectors before moving any further in this article.
Approach: The approach of this animation is to divide the animation into two parts. The top and right will be done at one time using before, bottom and left are done at one time using after selector.
HTML Code: We have created HTML file and create a div in it with h1 inside div. Below is the code for the same.
CSS Code: The CSS for this animation is a little bit tricky so let’s try to understand it step by step.
Step 1: The first thing we have done is provide basic background and align our text at center. Below is the code for the same.
Step 2: The second step is creating top and right border.
- The first thing is to create a border with a transparent background.
- Then animate it over hover giving it a linear animation and an identifier name as animate.
- Now using keyframes we will animate the border. Make sure to apply color to only the top and right side of the border. First, we have increased the width for top border animation and the height for right border animation.
Step 3: Repeat the step-2 with after selector. Some key points to remember during this step are:
- Make sure to make top and right transparent and left and bottom as coloured.
- For left the height will increase and for bottom width will increase.
- Make sure to use a different name for keyframes identifier in this step.
Complete CSS Code:
Complete Code: It is the combination of both HTML and CSS codes.
- How to create X and Y axis flip animation using HTML and CSS ?
- How to Create Loading Blur Text Animation Effect using HTML and CSS ?
- How to Create Gradient Background Animation using HTML and CSS ?
- How to Create Text Color Animation using HTML and CSS ?
- How to Create Jumping Text 3D Animation Effect using CSS ?
- How to Create Text Changing Animation Effect using CSS ?
- How to create text-fill animation using CSS ?
- How to Create Animation Loading Bar using CSS ?
- How to Create Ghost Text Animation on Hover using HTML and CSS?
- How to Create a Dot loading Animation using HTML and CSS?
- How to create a button with stitched border using HTML and CSS?
- How to create text stagger animation using TypographyMotion plugin ?
- Create a transparent border with CSS
- Cartoon animation loader using CSS
- How to make smooth bounce animation using CSS ?
- Loading Text Animation Effect using CSS
- Rubber Band Text animation using HTML and CSS
- Text Animation with changing the color of the text using HTML & CSS
- Animation using clip-path property in CSS
- How to play the animation exactly two times using CSS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.