Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <progress-indicator aria-valuenow="25"></progress-indicator>

              
            
!

CSS

              
                /* normally I would install form fontsource, but it's a demo */
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/* not supported by Firefox yet, but progressively enhance with ring transition animation */
@property --progress-value {
	syntax: "<number>";
	inherits: true;
	initial-value: 1;
}

:root {
	--font-base: 'Space Mono', monospace;
	--color-dark: #1f1a38;
	--color-dark-glare: #989ea9;
	--color-success: #76f7bf;
}

body {
	box-sizing: border-box;
}

progress-indicator {
	--progress-value: 1; /* start with either 1 or 0 so there’s no partial ring without JS */

	display: inline-grid;
	font-family: var(--font-base);
	font-size: 2rem;
	color: black;
	--radius: 2.09375em; /* should the whole thing scale uniformly with font size? I say yes. */
	width: calc(var(--radius) * 2);
	aspect-ratio: 1;
	border-radius: 50%;
	overflow: hidden;
	--progress-bar-thickness: .3125em;
	transition: --progress-value 50ms;

	&::before, &::after {
		grid-area: 1 / 1 / -1 / -1;
	}

	&::before {
		content: "";
		/* the ring value */
		background-image: conic-gradient(
			var(--color-dark) calc(var(--progress-value) * 1turn),
			calc(var(--progress-value) * 1turn),
			var(--color-dark-glare)
		);

		/* make it a ring instead of a whole circle */
		mask: radial-gradient(
			transparent,
			calc(var(--radius) - var(--progress-bar-thickness)),
			black calc(var(--radius) - var(--progress-bar-thickness)),
			black
		);
	}

	&::after {
		display: grid;
		place-content: center;
		/* place-self: center; */
		content: attr(aria-valuenow)"%"; /* this value will never get updated without JS, but might as well show what got sent over the wire */
	}

	&[aria-valuenow="100"]::before {
		background-image: none;
		mask: none;
		background-color: var(--color-success);
		border-radius: inherit;
		border: var(--progress-bar-thickness) solid black;
	}

	&[aria-valuenow="100"]::after {
		background-color: black;
		mask: url('data:image/svg+xml;utf8,<svg width="85" height="85" viewBox="0 0 85 85" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M35.4237 53.7327L67.9787 21.1777L72.9895 26.1842L35.4195 63.75L12.886 41.2122L17.8925 36.2015L35.4237 53.7327Z" fill="black"/></svg>');
		mask-repeat: no-repeat;
		mask-position: center;
		mask-size: 2.65625em;
	}
}

              
            
!

JS

              
                // a custom element that just watches the `aria-valuenow` attribute and sets a CSS custom prop for the ring
class ProgressIndicator extends HTMLElement {
	static observedAttributes = ["aria-valuenow"];

	attributeChangedCallback(name, oldValue, newValue) {
		if(name === "aria-valuenow") {
			this.style.setProperty("--progress-value", parseFloat(newValue)/100);

			// when resetting to 0, don’t do trannsition animation
			if(oldValue === "100" && newValue === "0") {
				this.style.setProperty("transition", "none");
			}
			else {
				this.style.setProperty("transition", "");
			}
		}
	}

	static {
		customElements.define("progress-indicator", this);
	}
}







// demo stuff
const pi = document.querySelector("progress-indicator");
const duration = 3000;
const wait = 1000;
let startTime, elapsedTime;
const tick = t => {
	if(startTime === undefined) startTime = t;
	elapsedTime = t - startTime;
	pi.setAttribute("aria-valuenow", Math.min(Math.round(elapsedTime/duration * 100), 100));
	if(elapsedTime > duration + wait) {
		startTime = undefined;
	}
	requestAnimationFrame(tick);
}
requestAnimationFrame(tick);

              
            
!
999px

Console