Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <input type="checkbox" />
<div></div>

<footer>
	<p>Extra Demo for <a href="https://brm.us/animated-gradient-border" target="_top">https://brm.us/animated-gradient-border</a>,<br />including a fallback for non-Houdini browsers.</p>
</footer>
              
            
!

CSS

              
                div {
	width: 50vmin;
	height: 50vmin;
	border: 10vmin solid;
	border-image: conic-gradient(from 0deg, red, yellow, lime, aqua, blue, magenta, red) 1;
	animation: 10s rotate linear infinite;
}


/* Houdini Browsers: Animate the gradient using Houdini Magic */
/* As we can't use @supports for @property (see https://github.com/w3c/csswg-drafts/issues/2463) we're using another way to target browsers that speak Houdini. */
@supports (background: paint(worklet)) {
	@property --angle {
		syntax: '<angle>';
		initial-value: 0deg;
		inherits: false;
	}

	div {
		--angle: 0deg;
		border-image: conic-gradient(from var(--angle), red, yellow, lime, aqua, blue, magenta, red) 1;
	}

	@keyframes rotate {
		to {
			--angle: 360deg;
		}
	}
}

/* Non-Houdini Browsers: Manually adjust the border-image frame by frame … */
/* Code was generate using the little JS snippet included with this pen */
@supports not (background: paint(worklet)) {
	@keyframes rotate {
	  0% { border-image: conic-gradient(from 0.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  1% { border-image: conic-gradient(from 3.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  2% { border-image: conic-gradient(from 7.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  3% { border-image: conic-gradient(from 10.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  4% { border-image: conic-gradient(from 14.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  5% { border-image: conic-gradient(from 18.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  6% { border-image: conic-gradient(from 21.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  7% { border-image: conic-gradient(from 25.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  8% { border-image: conic-gradient(from 28.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  9% { border-image: conic-gradient(from 32.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  10% { border-image: conic-gradient(from 36.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  11% { border-image: conic-gradient(from 39.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  12% { border-image: conic-gradient(from 43.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  13% { border-image: conic-gradient(from 46.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  14% { border-image: conic-gradient(from 50.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  15% { border-image: conic-gradient(from 54.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  16% { border-image: conic-gradient(from 57.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  17% { border-image: conic-gradient(from 61.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  18% { border-image: conic-gradient(from 64.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  19% { border-image: conic-gradient(from 68.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  20% { border-image: conic-gradient(from 72.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  21% { border-image: conic-gradient(from 75.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  22% { border-image: conic-gradient(from 79.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  23% { border-image: conic-gradient(from 82.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  24% { border-image: conic-gradient(from 86.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  25% { border-image: conic-gradient(from 90.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  26% { border-image: conic-gradient(from 93.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  27% { border-image: conic-gradient(from 97.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  28% { border-image: conic-gradient(from 100.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  29% { border-image: conic-gradient(from 104.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  30% { border-image: conic-gradient(from 108.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  31% { border-image: conic-gradient(from 111.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  32% { border-image: conic-gradient(from 115.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  33% { border-image: conic-gradient(from 118.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  34% { border-image: conic-gradient(from 122.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  35% { border-image: conic-gradient(from 126.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  36% { border-image: conic-gradient(from 129.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  37% { border-image: conic-gradient(from 133.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  38% { border-image: conic-gradient(from 136.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  39% { border-image: conic-gradient(from 140.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  40% { border-image: conic-gradient(from 144.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  41% { border-image: conic-gradient(from 147.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  42% { border-image: conic-gradient(from 151.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  43% { border-image: conic-gradient(from 154.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  44% { border-image: conic-gradient(from 158.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  45% { border-image: conic-gradient(from 162.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  46% { border-image: conic-gradient(from 165.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  47% { border-image: conic-gradient(from 169.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  48% { border-image: conic-gradient(from 172.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  49% { border-image: conic-gradient(from 176.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  50% { border-image: conic-gradient(from 180.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  51% { border-image: conic-gradient(from 183.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  52% { border-image: conic-gradient(from 187.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  53% { border-image: conic-gradient(from 190.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  54% { border-image: conic-gradient(from 194.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  55% { border-image: conic-gradient(from 198.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  56% { border-image: conic-gradient(from 201.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  57% { border-image: conic-gradient(from 205.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  58% { border-image: conic-gradient(from 208.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  59% { border-image: conic-gradient(from 212.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  60% { border-image: conic-gradient(from 216.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  61% { border-image: conic-gradient(from 219.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  62% { border-image: conic-gradient(from 223.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  63% { border-image: conic-gradient(from 226.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  64% { border-image: conic-gradient(from 230.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  65% { border-image: conic-gradient(from 234.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  66% { border-image: conic-gradient(from 237.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  67% { border-image: conic-gradient(from 241.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  68% { border-image: conic-gradient(from 244.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  69% { border-image: conic-gradient(from 248.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  70% { border-image: conic-gradient(from 252.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  71% { border-image: conic-gradient(from 255.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  72% { border-image: conic-gradient(from 259.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  73% { border-image: conic-gradient(from 262.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  74% { border-image: conic-gradient(from 266.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  75% { border-image: conic-gradient(from 270.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  76% { border-image: conic-gradient(from 273.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  77% { border-image: conic-gradient(from 277.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  78% { border-image: conic-gradient(from 280.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  79% { border-image: conic-gradient(from 284.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  80% { border-image: conic-gradient(from 288.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  81% { border-image: conic-gradient(from 291.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  82% { border-image: conic-gradient(from 295.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  83% { border-image: conic-gradient(from 298.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  84% { border-image: conic-gradient(from 302.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  85% { border-image: conic-gradient(from 306.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  86% { border-image: conic-gradient(from 309.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  87% { border-image: conic-gradient(from 313.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  88% { border-image: conic-gradient(from 316.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  89% { border-image: conic-gradient(from 320.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  90% { border-image: conic-gradient(from 324.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  91% { border-image: conic-gradient(from 327.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  92% { border-image: conic-gradient(from 331.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  93% { border-image: conic-gradient(from 334.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  94% { border-image: conic-gradient(from 338.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  95% { border-image: conic-gradient(from 342.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  96% { border-image: conic-gradient(from 345.60deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  97% { border-image: conic-gradient(from 349.20deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  98% { border-image: conic-gradient(from 352.80deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  99% { border-image: conic-gradient(from 356.40deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	  100% { border-image: conic-gradient(from 360.00deg, red, yellow, lime, aqua, blue, magenta, red) 1; }
	}
}















input[type="checkbox"] {
	position: fixed;
	top: 1em;
	left: 1em;
}

input[type="checkbox"]:after {
	content: 'Toggle Fill';
	white-space: nowrap;
	padding-left: 1.5em;
}

input[type="checkbox"]:checked + div {
	border-image-slice: 1 fill;
}

body {
	margin: 0;
	padding: 0;
	height: 100vh;
	width: 100vw;
	display: grid;
	place-items: center;
	background: #fff;
}

footer {
	text-align: center;
	font-style: italic;
}
              
            
!

JS

              
                // @note: This is a little helper to quickly generate the keyframes.
// It not active, but left here for debugging purposes …
const generateCSS = () => {
	let css = '@keyframes rotate {';
	for (let i = 0; i <= 100; i++) {
		css = `${css}
  ${i}% { border-image: conic-gradient(from ${(360 * i / 100).toFixed(2)}deg, red, yellow, lime, aqua, blue, magenta, red) 1; }`;
	}

	return `${css}
	}`;
}

const injectCSS = (css) => {
	const style = document.createElement('style');
	style.innerHTML = css;
	document.head.appendChild(style);
}

// console.log(generateCSS());
              
            
!
999px

Console