<h1 class="underline">Underline effect</h1>
<span>hover on "underline effect"</span>
* {
  box-sizing: border-box;
}

@import url(https://fonts.googleapis.com/css?family=PT+Sans);

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}

body {
  font-family: 'PT Sans', Arial, Verdana;
  background-color: #eee;
}

h1 {
  text-align: center;
  font-size: 48px;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: #222;
  margin: 20px 0;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.underline {
  position: relative;
  
  &:hover,
  &:focus,
  &:active {
    cursor: pointer;
    &:after {
      width: 100%;
    }
  }
  
  &:after {
    content: '';
    position: absolute;
    left: 0; bottom: -3px;
    height: 3px;
    background-color: #000;
    width: 0;
    transition: width .4s;
  }
}
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.