<div class="animated-box in">
  <h1>Animated border</h1>
  <p>Without fixed width or static background</p>
</div>
/* Here's some environment setup,
   scroll down for the interesting parts */

@import url('https://fonts.googleapis.com/css?family=Lato:200');

html, body {
  width: 100%;
  height: 100%;
}

body {
  background-image: url(https://images.unsplash.com/photo-1515254100245-67228492bf65?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=1b058fcd3bdba98711aa240123fca6b8);
  background-position: center center;
  background-size: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.animated-box {
  font-family: 'Lato';
  color: #ffffff;
  padding: 30px;
  text-align: center;
  border-radius: 4px;
}

.animated-box h1 {
  font-weight: 200;
  font-size: 40px;
  text-transform: uppercase;
}

.animated-box p {
  font-weight: 200;
}

/* The animation starts here */
.animated-box {
  position: relative;
}

.animated-box:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 4px;
  background: linear-gradient(120deg, #00F260, #0575E6, #00F260);
  background-size: 300% 300%;
  clip-path: polygon(0% 100%, 3px 100%, 3px 3px, calc(100% - 3px) 3px, calc(100% - 3px) calc(100% - 3px), 3px calc(100% - 3px), 3px 100%, 100% 100%, 100% 0%, 0% 0%);
}

.animated-box.in:after {
  animation: frame-enter 1s forwards ease-in-out reverse, gradient-animation 4s ease-in-out infinite;
}

/* motion */
@keyframes gradient-animation {
  0% {
    background-position: 15% 0%;
  }
  50% {
    background-position: 85% 100%;
  }
  100% {
    background-position: 15% 0%;
  }
}

@keyframes frame-enter {
  0% {
    clip-path: polygon(0% 100%, 3px 100%, 3px 3px, calc(100% - 3px) 3px, calc(100% - 3px) calc(100% - 3px), 3px calc(100% - 3px), 3px 100%, 100% 100%, 100% 0%, 0% 0%);
  }
  25% {
    clip-path: polygon(0% 100%, 3px 100%, 3px 3px, calc(100% - 3px) 3px, calc(100% - 3px) calc(100% - 3px), calc(100% - 3px) calc(100% - 3px), calc(100% - 3px) 100%, 100% 100%, 100% 0%, 0% 0%);
  }
  50% {
    clip-path: polygon(0% 100%, 3px 100%, 3px 3px, calc(100% - 3px) 3px, calc(100% - 3px) 3px, calc(100% - 3px) 3px, calc(100% - 3px) 3px, calc(100% - 3px) 3px, 100% 0%, 0% 0%);
  }
  75% {
    -webkit-clip-path: polygon(0% 100%, 3px 100%, 3px 3px, 3px 3px, 3px 3px, 3px 3px, 3px 3px, 3px 3px, 3px 0%, 0% 0%);
  }
  100% {
    -webkit-clip-path: polygon(0% 100%, 3px 100%, 3px 100%, 3px 100%, 3px 100%, 3px 100%, 3px 100%, 3px 100%, 3px 100%, 0% 100%);
  }
}
/**

CSS-only animated gradient borders
The box can be resized, based on the content, and it doesn't need a static background color

The animation starts when you add the .in class to the animated-box.
 
IE / Edge browsers don't support
clip-path, so use a regular border as a fallback.

More description: https://medium.com/@johnnyfekete/animated-gradient-border-in-css-80c32a69563f
*/

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.