To expand the bottom border on hover, you can use transform:scaleX(); (mdn reference) and transition it from 0 to 1 on the hover state.

Here is an example of what the border hover effect can look like :

The border and transition are set on a pseudo element to prevent transitioning the text and avoid adding markup.
To expand the bottom border from left or right, you can change the transform-origin property to the left or right of the pseudo element:

h1 { color: #666;display:inline-block; margin:0;text-transform:uppercase; }
h1:after {
  display:block;
  content: '';
  border-bottom: solid 3px #019fb6;  
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}
h1:hover:after { transform: scaleX(1); }
h1.fromRight:after{ transform-origin:100% 50%; }
h1.fromLeft:after{  transform-origin:  0% 50%; }
<h1 class="fromCenter">Expand from center</h1><br/>
<h1 class="fromRight">Expand from right</h1><br/>
<h1 class="fromLeft">Expand from left</h1>

Expand bottom border on hover with 2 lines

You can achieve this effect when the text spans on 2 lines. The before pseudo element is absolutely positioned to make underline of the first line with bottom:1.2em;:

h1 { position:relative;color: #666;display:inline-block; margin:0;text-transform:uppercase;text-align:center;line-height:1.2em; }
h1:after, h1:before {
  display:block;
  content: '';
  border-bottom: solid 3px #019fb6;  
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}
h1:before{
  position:absolute;
  bottom:1.2em; left:0;
  width:100%;
}
.ef2:hover:after {
  transition-delay:150ms;
}
  
h1:hover:after, h1:hover:before { transform: scaleX(1); }
<h1>Expand border<br/>on two lines</h1>
<br/>
<br/>
<h1 class="ef2">Expand border<br/>effect two</h1>

Different transition direction on hover in and out :

The point is to change the transform-origin position from one side to the other on the hover state. This way the bottom boder enters from one side on hover and exits on the other when the element isn't hovered anymore.
Here is a demo :

h1 { color: #666;display:inline-block; margin:0;text-transform:uppercase; }
h1:after {
  display:block;
  content: '';
  border-bottom: solid 3px #019fb6;  
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}
h1.fromLeft:after{ transform-origin: 100% 50%; }
h1.fromRight:after{  transform-origin:   0% 50%; }
h1.fromLeft:hover:after{ transform: scaleX(1); transform-origin:   0% 50%; }
h1.fromRight:hover:after{ transform: scaleX(1); transform-origin: 100% 50%; }
<h1 class="fromRight">Expand from right</h1><br/>
<h1 class="fromLeft">Expand from left</h1>

Answer from web-tiki on Stack Overflow
🌐
CSS-Tricks
css-tricks.com › animating-border
Animating Border | CSS-Tricks
December 6, 2017 - Since transform and opacity are ... to animate for performance, why not use a pseudo-element and have the border scale up & down? .border-button { position: relative; margin: 0.5em; border: solid 5px transparent; background: #3E4377; } .border-button:after { content: ''; display: block; position: absolute; top: 0; right: 0; bottom: 0; left: 0; border: ...
🌐
Slider Revolution
sliderrevolution.com › home › awesome css border animation examples to use
Awesome CSS Border Animation Examples to Use in Your Websites
January 27, 2026 - Peter Bou Saada’s navigation animation creates a subtle bottom border effect for menu items. This widely-used technique in modern web aesthetics provides users with clear feedback about their current location within a site. The animation creates microinteractions that improve navigation experience, especially when implemented within CSS frameworks like Bootstrap or Tailwind CSS.
🌐
CodePen
codepen.io › martinwolf › pen › eNNdme
Animate Border Bottom - Link Hover Effect
[ Indent Code Right · ] Indent Code Left · ⇧ Tab Auto Indent Code · / Line Comment · ⇧ Opt / Block Comment · Also see: Tab Triggers · Alt Opt 1 HTML Editor · Alt Opt 2 CSS Editor · Alt Opt 3 JS Editor · Alt Opt 4 Toggle Console · Alt Opt 0 Preview ·
🌐
CodePen
codepen.io › yochans › pen › GRNoLbv
CSS | border animation (left to right)
<div id="container"> <p class="border">left to right</p> </div> <hr> <p><a href="https://1-notes.com/css-border-animation/" target="_blank" rel="noopener">CSS | border animation | ONE NOTES</a></p> ... body { margin: 0; padding: 0; } p { padding: 10px; } #container { margin: 70px 20px; } .border{ position: relative; font-size: 18px; } .border:before{ content: ''; position: absolute; left: 0; bottom: 0; width: 0; border-bottom: solid 2px #000; animation: border_anim 3s linear forwards; } @keyframes border_anim { 0%{ width: 0%; } 100%{ width: 100%; } }
Top answer
1 of 9
287

To expand the bottom border on hover, you can use transform:scaleX(); (mdn reference) and transition it from 0 to 1 on the hover state.

Here is an example of what the border hover effect can look like :

The border and transition are set on a pseudo element to prevent transitioning the text and avoid adding markup.
To expand the bottom border from left or right, you can change the transform-origin property to the left or right of the pseudo element:

h1 { color: #666;display:inline-block; margin:0;text-transform:uppercase; }
h1:after {
  display:block;
  content: '';
  border-bottom: solid 3px #019fb6;  
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}
h1:hover:after { transform: scaleX(1); }
h1.fromRight:after{ transform-origin:100% 50%; }
h1.fromLeft:after{  transform-origin:  0% 50%; }
<h1 class="fromCenter">Expand from center</h1><br/>
<h1 class="fromRight">Expand from right</h1><br/>
<h1 class="fromLeft">Expand from left</h1>

Expand bottom border on hover with 2 lines

You can achieve this effect when the text spans on 2 lines. The before pseudo element is absolutely positioned to make underline of the first line with bottom:1.2em;:

h1 { position:relative;color: #666;display:inline-block; margin:0;text-transform:uppercase;text-align:center;line-height:1.2em; }
h1:after, h1:before {
  display:block;
  content: '';
  border-bottom: solid 3px #019fb6;  
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}
h1:before{
  position:absolute;
  bottom:1.2em; left:0;
  width:100%;
}
.ef2:hover:after {
  transition-delay:150ms;
}
  
h1:hover:after, h1:hover:before { transform: scaleX(1); }
<h1>Expand border<br/>on two lines</h1>
<br/>
<br/>
<h1 class="ef2">Expand border<br/>effect two</h1>

Different transition direction on hover in and out :

The point is to change the transform-origin position from one side to the other on the hover state. This way the bottom boder enters from one side on hover and exits on the other when the element isn't hovered anymore.
Here is a demo :

h1 { color: #666;display:inline-block; margin:0;text-transform:uppercase; }
h1:after {
  display:block;
  content: '';
  border-bottom: solid 3px #019fb6;  
  transform: scaleX(0);  
  transition: transform 250ms ease-in-out;
}
h1.fromLeft:after{ transform-origin: 100% 50%; }
h1.fromRight:after{  transform-origin:   0% 50%; }
h1.fromLeft:hover:after{ transform: scaleX(1); transform-origin:   0% 50%; }
h1.fromRight:hover:after{ transform: scaleX(1); transform-origin: 100% 50%; }
<h1 class="fromRight">Expand from right</h1><br/>
<h1 class="fromLeft">Expand from left</h1>

2 of 9
20

We can do this with only background. No pseudo-element needed. This is more flexible.

h1 {
  /* you can change these variables to control the border */
  --border-color: purple;
  --border-width: 5px;
  --bottom-distance: 0px; /* you can increase this */
  
  color: #666;
  display: inline-block;
  background-image: linear-gradient(var(--border-color), var(--border-color));
  background-size: 0% var(--border-width);
  background-repeat: no-repeat;
  transition: background-size 0.3s;
  margin: 5px 0;
}

.fromCenter {
  background-position: 50% calc(100% - var(--bottom-distance));
}

.fromRight {
  background-position: 100% calc(100% - var(--bottom-distance));
}

.fromLeft {
  background-position: 0 calc(100% - var(--bottom-distance))
}

h1:hover {
  background-size: 100% var(--border-width);
}
<h1 class="fromCenter">Expand from center</h1><br/>
<h1 class="fromRight">Expand from right</h1><br/>
<h1 class="fromLeft">Expand from left</h1>

Multiple line animation:

h1 {
  /* you can change these variables to control the border */
  --border-color: purple;
  --border-width: 5px;
  --bottom-distance: 0px; /* you can increase this */
  
  color: #666;
  display: inline; /* should be 'inline' for multiple line animation */
  background-image: linear-gradient(var(--border-color), var(--border-color));
  background-size: 0% var(--border-width);
  background-repeat: no-repeat;
  transition: background-size 0.5s;
}

.fromCenter {
  background-position: 50% calc(100% - var(--bottom-distance));
}

.fromRight {
  background-position: 100% calc(100% - var(--bottom-distance));
}

.fromLeft {
  background-position: 0 calc(100% - var(--bottom-distance))
}

h1:hover {
  background-size: 100% var(--border-width);
}
<h1 class="fromLeft">Expand from <br>left with <br>multiple line</h1>

🌐
GeeksforGeeks
geeksforgeeks.org › css › how-to-create-border-animation-using-css
How to Create Border Animation using CSS? - GeeksforGeeks
July 12, 2025 - The ::before and ::after pseudo-elements are used to create two sets of border animations that trigger on hover. Keyframes are defined to specify the animation behavior: animate for the top and right borders, and animates for the left and bottom ...
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › Animate-border-left-property-with-CSS
Animate border-left property with CSS
June 25, 2020 - To implement animation on border-left property with CSS, you can try to run the following code · Live Demo · <!DOCTYPE html> <html> <head> <style> div { width: 500px; height: 300px; background: yellow; border: 10px solid yellow; border-bottom-right-radius: 100px; border-bottom-width: 30px; background-image: url('https://www.tutorialspoint.com/latest/testrail.png'); animation: myanim 3s infinite; background-position: bottom left; background-size: 50px; } @keyframes myanim { 40% { background-color: maroon; background-size: 90px; border-bottom-color: green; border-bottom-right-radius: 50px; border-bottom-width: 50px; border-color: red; border-left: 10px dashed orange; } } </style> </head> <body> <h2>Performing Animation for left border</h2> <div></div> </body> </html> Arjun Thakur ·
🌐
Steckinsights
steckinsights.com › animate-the-length-of-the-border-bottom-with-pure-css
Animate The Length Of The Border-Bottom With Pure CSS
February 6, 2019 - I am going to show you how to perform an animation on Mouse Hover that expands the border of an element. Improve you users experience with pure css!
Address   2621 W Cucharras St,, 80904, Colorado Springs,
🌐
CodePen
codepen.io › vulchivijay › pen › yyxyvB
CSS3 transition borders
@import "lesshat"; body { font-size: ... position: relative; overflow: hidden; &:before { content: ""; position: absolute; z-index: -1; left: 0; right: 0; bottom: 0; top: 0; border-color: #2980b9; border-width: 0; border-style: solid; ...
🌐
Let's Build UI
letsbuildui.dev › articles › how-to-animate-borders-in-css
How to Animate Borders in CSS
March 21, 2024 - This is all you need to create an animated gradient border in CSS!
🌐
CodePen
codepen.io › harman97 › pen › ZdEemB
Link Hover Effect: Animate Border Bottom
[ Indent Code Right · ] Indent Code Left · ⇧ Tab Auto Indent Code · / Line Comment · ⇧ Opt / Block Comment · Also see: Tab Triggers · Alt Opt 1 HTML Editor · Alt Opt 2 CSS Editor · Alt Opt 3 JS Editor · Alt Opt 4 Toggle Console · Alt Opt 0 Preview ·
🌐
TutorialsPoint
tutorialspoint.com › home › articles on trending technologies › how to set the width of the bottom border animatable using css?
How to set the width of the bottom border animatable using CSS?
May 17, 2023 - In CSS, we can use the ?border-bottom' CSS property to set the bottom border for an HTML element. We can use the animation property to animate the width of the bottom border.