🌐
Theowoo
theowoo.github.io › agbg
Animated Gradient Border Generator
Animated Gradient Border Generator · Examples: 0 1 2 3 4 5 · Background · Rectangle · Circle · Width · Height · Border Width · Border Radius · Two Tones
🌐
CodePen
codepen.io › mike-schultz › pen › NgQvGO
Animated CSS Gradient Border
@import url('https://fonts.googleapis.com/css?family=Raleway:200'); html, body { height: 100%; } body { display: flex; justify-content: center; align-items: center; height: 100%; background: #1D1F20; } #box { display: flex; align-items: center; justify-content: center; width: 400px; height: 200px; color: white; font-family: 'Raleway'; font-size: 2.5rem; } .gradient-border { --borderWidth: 3px; background: #1D1F20; position: relative; border-radius: var(--borderWidth); } .gradient-border:after { content: ''; position: absolute; top: calc(-1 * var(--borderWidth)); left: calc(-1 * var(--borderWid
People also ask

How does this CSS gradient border technique work?
The technique uses two divs. An outer div has a gradient background and padding. An inner div sits inside that padding and has a solid background color. The visible portion of the outer div's gradient creates the border effect.
🌐
codeshack.io
codeshack.io › home › tools › css gradient border generator
CSS Gradient Border Generator - Free Online Tool
Can I animate the gradient border?
Yes, a common technique is to make the gradient's background size larger than the element and then use a CSS animation to change the `background-position`. This creates a subtle rotating or glowing effect.
🌐
codeshack.io
codeshack.io › home › tools › css gradient border generator
CSS Gradient Border Generator - Free Online Tool
Why not just use the `border-image` property?
The CSS `border-image` property has poor support for `border-radius`, which means it is difficult to create gradient borders with rounded corners. The padding technique used by this tool is more flexible and works perfectly with rounded corners.
🌐
codeshack.io
codeshack.io › home › tools › css gradient border generator
CSS Gradient Border Generator - Free Online Tool
🌐
Ibelick
ibelick.com › blog › create-animated-gradient-borders-with-css
Creating an animated gradient border with CSS
May 2, 2023 - .box { display: flex; justify-content: center; align-items: center; padding: 12px; height: 400px; width: 400px; border: 3px solid #0000; border-radius: 12px; background: linear-gradient(#131219, #131219) padding-box, linear-gradient( var(--angle), #070707, #687aff ) border-box; animation: 8s rotate linear infinite; } @keyframes rotate { to { --angle: 360deg; } } @property --angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; } To achieve our desired effect, we'll use the following CSS properties:
🌐
CodeTV
codetv.dev › blog › animated-css-gradient-border
Animated CSS gradient borders (no JavaScript, no hacks)
Learn how to create beautiful, CSS-only gradient borders. Combine custom properties, OKLCH, and background-origin — and zero hacks. So much cool stuff has been happening in CSS lately — if you haven’t looked at it in a few years, it might be worth giving things another shot. A lot has changed! Here’s what you’ll build by the end of this article. See the Pen Gorgeous animated gradient borders using only CSS by Jason Lengstorf (@jlengstorf) on CodePen.
🌐
CSS-Tricks
css-tricks.com › animating-a-css-gradient-border
Animating a CSS Gradient Border | CSS-Tricks
February 8, 2021 - div { --angle: 0deg; /* … */ border-image: linear-gradient(var(--angle), green, yellow) 1; animation: 10s rotate linear infinite; } @keyframes rotate { to { --angle: 360deg; } }
🌐
CodeShack
codeshack.io › home › tools › css gradient border generator
CSS Gradient Border Generator - Free Online Tool
Easily create CSS gradient borders for your divs, buttons, and cards. Our visual tool generates the cross-browser code for beautiful, modern gradient borders in real-time.
🌐
Bejamas
bejamas.com › hub › guides › css-animated-gradient-border
Finding the best way to create animated gradient borders in CSS - Bejamas
November 18, 2024 - .media-object { border: 1px solid; border-image: conic-gradient(#381D6A 80%, #E0D1FF 88%, #E0D1FF 92%, #381D6A 100%) 1; }
Find elsewhere
🌐
Bram.us
bram.us › 2021 › 01 › 29 › animating-a-css-gradient-border
Animating a CSS Gradient Border – Bram.us
While the effect here looks quite nice it won’t play nice with more than two colors. Take this rainbow animated gradient border for example: See the Pen CSS Rainbow Gradient Border (Animated, Attempt 1) by Bramus (@bramus) on CodePen.
🌐
CSS-Tricks
css-tricks.com › gradient-borders-in-css
Gradient Borders in CSS | CSS-Tricks
September 30, 2022 - Thanks for writing this! I used the first option recently when a student wanted to have a gradient border animated. Worked out pretty well: https://codepen.io/jupago/ Did not know about border-image-slice. Might also be fun to try clip-path. That 24ways article on Clip Paths got me wondering if that will eventually be the the next best thing.
🌐
UI Surgeon
uisurgeon.com › tools › css-border-gradient-generator
CSS Border Gradient Generator - Create Animated Gradient Borders | UI Surgeon
Design eye-catching border gradients with smooth animations using our advanced CSS Border Gradient Generator. Perfect for buttons, cards, and more!
🌐
CodePen
codepen.io › shshaw › pen › RwJwJJx
Animated Border Gradient
Minimize CSS Editor · Fold All · Unfold All · html { height: 100%; background: #223; display: grid; place-items: center; } .box { width: 60vmin; height: 50vmin; display: grid; place-content: center; color: white; text-shadow: 0 1px 0 #000; --border-angle: 0turn; // For animation. --main-bg: conic-gradient( from var(--border-angle), #213, #112 5%, #112 60%, #213 95% ); border: solid 5px transparent; border-radius: 2em; --gradient-border: conic-gradient(from var(--border-angle), transparent 25%, #08f, #f03 99%, transparent); background: // padding-box clip this background in to the overall element except the border.
🌐
Magic Gradient
magicgradient.com › animated-gradient-generator
Animated Gradient Generator - Magic Gradient
Preview the result — see your animated gradient applied to a full-width background and a border effect in real time. Copy the CSS — click the copy button on any preview to get the complete CSS code, including the keyframe animation.
🌐
YouTube
youtube.com › kevin powell
Create an animated, glowing, gradient border with CSS - YouTube
Inspired by a codepen by Gayane Gasparyan - https://codepen.io/gayane-gasparyan/pen/jOmaBQK - I took my own attempt to create a rotating gradient border, inc
Published   March 16, 2023
🌐
CodePen
codepen.io › bibby0912 › pen › mEMWyr
CSS Gradient Border + Animated
body { display: flex; flex-flow: column; } .container { margin: auto; width: 40vw; height: 40vh; /*outline: 1px solid red;*/ border: 20px solid transparent; box-sizing: border-box; text-transform: uppercase; font-weight: 900; font-family: "Open Sans","Source Sans Pro",Helvetica,sans-serif; font-size: 1em; letter-spacing: 1em; padding: 1rem; display:flex; justify-content: center; align-items: center; } .demo { /*background-image: linear-gradient(white, white), linear-gradient(180deg, cornflowerblue, purple);*/ background-image: linear-gradient(white, white), linear-gradient(270deg, #00D7B9, #B9
🌐
Theo Soti
theosoti.com › short › border-gradient
Create Animated Gradient Borders with Pure CSS
July 2, 2025 - Build clean, animated gradient borders using only CSS—no extra elements, fully responsive, and JavaScript-free.
🌐
Gradient-animator
gradient-animator.com
CSS Gradient Animator
A CSS generator to create beautiful animated gradients for use on your website.
Top answer
1 of 2
2

I like your original idea with using overflow: hidden, but to make it work I had to include an extra wrapper div.

  • The outer wrapper defines a padding which serves as the display area for the gradient border
  • The inner div is just the content box with a black background

.loading-box-container {
  --size: 200px;
  --radius: 10px;
  position: relative;
  width: var(--size);
  height: var(--size);
  padding: var(--radius);
  border-radius: var(--radius);
  overflow: hidden;
}

.loading-box {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: #000;
  border-radius: var(--radius);
}

.loading-box-container::before {
  content: '';
  width: 150%; /* The upscaling allows the box to fill its container even when rotated */
  height: 150%;
  position: absolute;
  top: -25%; left: -25%;
  background: conic-gradient(#0000ff00, #ff0000ff);
  animation: rotate-border 5s linear infinite;
}

@keyframes rotate-border {
    to {
        transform: rotate(360deg);
    }
}
<div class="loading-box-container">
  <div class="loading-box">
    <p>Loading</p>
  </div>
</div>

An alternative: Using @property

There's a much more elegant solution using @property, but unfortunately it only works on Chrome. I'm including here in case one day it becomes more universally supported or support for other browsers isn't important for your use case.

The conic-gradient function has a parameter that allows you to specify at what angle the gradient starts. If we can animate just that parameter, perhaps using a CSS variable, then we can animate the border with just a single div and without actually rotating anything.

Unfortunately, without some hinting the browser doesn't know how to transition a CSS variable. Therefore, we use @property to indicate the variable is an angle, telling the browser how to transition it.

@property --rotation {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

.loading-box {
  --size: 200px;
  --radius: 10px;
  position: relative;
  width: var(--size);
  height: var(--size);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: #000;
  border-radius: var(--radius);
  margin: var(--radius);
}

.loading-box::before {
  --rotation: 0deg;
  content: '';
  width: calc(100% + 2 * var(--radius));
  height: calc(100% + 2 * var(--radius));
  border-radius: var(--radius);
  position: absolute;
  top: calc(-1 * var(--radius)); left: calc(-1 * var(--radius));
  background: conic-gradient(from var(--rotation), #0000ff00, #ff0000ff);
  animation: rotate-border 5s linear infinite;
  z-index: -1;
}

@keyframes rotate-border {
    to {
        --rotation: 360deg;
    }
}
<div class="loading-box">
  <p>Loading</p>
</div>

CanIUse for @property indicates this will only work in Chrome and Edge as of this post.

2 of 2
0

Hi is this what you are looking for?

What I did was I added a new div which will be the "mask" as well as a container div for both the mask and the loadingBox.

I then sized the mask to be a little larger than your visible area, make it a transparent background, and then gave it a large outline the same color as your background to effectively mask out a border. I then fiddled with z-indexs of the mask, the loadingbox and the before. I also added some actual borders on mask to box it out into a nice shape.

Take a look:

.gradient-box {
  
  display: flex;
  align-items: center;
  width: 90%;
  margin: auto;
  max-width: 22em;

  position: relative;
  padding: 30% 2em;
  box-sizing: border-box;

  border: 5px solid blue;
  color: #FFF;
  background: #000;
  background-clip: padding-box; /* !importanté */
  border: solid 5px transparent; /* !importanté */
  border-radius: 1em;

}

.gradient-box:before {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    z-index: -3;
    margin: -35px; /* !importanté */
    border-radius: inherit; /* !importanté */
    background: conic-gradient(#0000ff00, #ff0000ff);
    -webkit-animation: rotate-border 5s linear infinite;
    -moz-animation: rotate-border 5s linear infinite;
    -o-animation: rotate-border 5s linear infinite;
    animation: rotate-border 3s linear infinite;
}

@keyframes rotate-border {
    to {
        transform: rotate(360deg);
    }
}

html { height: 100%; background: #000; display: flex; }
body { margin: auto; }

.mask {
  position: absolute;
   box-sizing: border-box;
background-color: transparent; 
 outline: 65px solid black;
height: 100%;
  width: 100%;
  border: 2px solid black;
  border-left: 7px solid black;
  border-right: 7px solid black;
  z-index: -1;
}

.container {
  position: relative;
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Loading DIV Test</title>
</head>
<body>
<div class="container">
<div class="mask"></div>
<div id="loadingBox" class="gradient-box">
<p>Loading.</p>
</div>
  </div>
</body>

🌐
Daily Dev Tips
daily-dev-tips.com › posts › animating-a-gradient-border-in-css
Animating a gradient border in CSS
December 2, 2021 - div { width: 50vmin; height: 50vmin; border: 1rem solid; border-image: linear-gradient(0deg, #12c2e9, #c471ed, #f64f59) 1; } We should now have our basic border setup, which should look like this. Pretty close already. Now we need to animate this! Let’s use some CSS variables to make the position animatable.
🌐
Cruip
cruip.com › home › animated gradient borders with tailwind css
Animated Gradient Borders with Tailwind CSS - Cruip
March 12, 2024 - Note: this animation is currently only supported in Chrome and Chromium-based browsers. Firefox does not yet support the CSS @property rule, but it is expected to be integrated soon, as it is already available in the nightly development version. <div class="w-full max-w-[422px] [background:linear-gradient(45deg,#172033,theme(colors.slate.800)_50%,#172033)_padding-box,conic-gradient(from_var(--border-angle),theme(colors.slate.600/.48)_80%,_theme(colors.indigo.500)_86%,_theme(colors.indigo.300)_90%,_theme(colors.indigo.500)_94%,_theme(colors.slate.600/.48))_border-box] rounded-2xl border border-
🌐
Reddit
reddit.com › r/reactjs › creating an animated gradient border with css
r/reactjs on Reddit: Creating an animated gradient border with CSS
May 2, 2023 -

Hey everyone! I just published a new article on creating an animated gradient border using CSS. I've also included a version for Tailwind CSS users (with React and TypeScript too!).

I'm planning on writing more articles about design, UI, software, and other topics in the future. If you have any suggestions, feedback, or any cool ways you've used this effect in your projects please feel free to share! I'd love to hear your thoughts.

https://www.julienthibeaut.xyz/blog/create-animated-gradient-borders-with-css