← Back toCSS Layout

Radial progress bar

Written byPhuoc Nguyen
Category
Feedback
Created
30 Nov, 2019

HTML

index.html
<div class="radial-progress-bar">
<!-- Show number of percentages -->
<div class="radial-progress-bar__percentages">...</div>

<!-- The curve -->
<div class="radial-progress-bar__curve">
<!-- The first half -->
<div class="radial-progress-bar__half radial-progress-bar__half--first"></div>

<!-- The second half -->
<div class="radial-progress-bar__half radial-progress-bar__half--second"></div>
</div>
</div>

CSS

styles.css
:root {
--radial-progress-bar-size: 8rem;
--radial-progress-bar-border-width: 0.75rem;
}

.radial-progress-bar {
position: relative;
height: var(--radial-progress-bar-size);
width: var(--radial-progress-bar-size);
}

.radial-progress-bar__percentages {
/* Center the content */
align-items: center;
display: flex;
justify-content: center;

/* Rounded border */
border: var(--radial-progress-bar-border-width) solid #d1d5db;
border-radius: 9999px;

/* Size */
height: 100%;
width: 100%;
}

.radial-progress-bar__curve {
/* Position */
left: 0;
position: absolute;
top: 0;

/* Take full size */
height: 100%;
width: 100%;

/* If percentages is less than 50 */
/* clip: rect(
0px,
var(--radial-progress-bar-size),
var(--radial-progress-bar-size),
calc(var(--radial-progress-bar-size) * 0.5),
0px
); */

/* If percentages is greater than or equals to 50 */
clip: rect(auto, auto, auto, auto);
}

.radial-progress-bar__half {
/* Take full size */
height: 100%;
position: absolute;
width: 100%;

/*
Background color of curve.
The border width should be the same as the area showing the percentages
*/
border: var(--radial-progress-bar-border-width) solid #3b82f6;
border-radius: 9999px;
}

.radial-progress-bar__half--first {
/* Position */
clip: rect(0px, calc(var(--radial-progress-bar-size) * 0.5), var(--radial-progress-bar-size), 0px);

/* Number of percentages * 360 / 100 */
transform: rotate(270deg);
}

.radial-progress-bar__half--second {
/* Position */
clip: rect(0px, calc(var(--radial-progress-bar-size) * 0.5), var(--radial-progress-bar-size), 0px);

/* If percentages is less than 50 */
/* transform: rotate(0deg); */

/* If percentages is greater than or equals to 50 */
transform: rotate(180deg);
}

Questions? 🙋

Do you have any questions? Not just about this specific post, but about any topic in front-end development that you'd like to learn more about? If so, feel free to send me a message on Twitter or send me an email. You can find them at the bottom of this page.
I have a long list of upcoming posts, but your questions or ideas for the next one will be my top priority. Let's learn together! Sharing knowledge is the best way to grow 🥷.

Recent posts ⚡

Newsletter 🔔

If you're into front-end technologies and you want to see more of the content I'm creating, then you might want to consider subscribing to my newsletter.
By subscribing, you'll be the first to know about new articles, products, and exclusive promotions.
Don't worry, I won't spam you. And if you ever change your mind, you can unsubscribe at any time.
Phước Nguyễn