Html css круглый прогресс бар

Circular Progress Bar using HTML and CSS

Circular Progress Bar is a popular web element that is mainly used on business or personal websites. If you want to create a circular progress bar using HTML and CSS, then this article will help you. Here I am going to show you how to make a simple CSS circle progress bar. When you load the page, this animation will go from zero to your assigned meaning. A percentage of text is used here, but no animation is used in this text. It is made in a very simple way. ✅ Watch Live Preview 👉👉 Circular Progress Bar In this article, I will show you step by step how I made this circular progress bar design.To make it, you need to have an idea about basic HTML and CSS.

Step 1: The basic structure of Circular Progress Bar

I have used HTML and CSS to create the basic structure of the Circular Progress Bar. I have created a small circle on the webpage. The width and height of this circle are 150 px. The background color of the circle is white and margins are used to place it in the middle.

 class="circle-wrap">  class="circle">   
body  font-family: "Roboto", sans-serif; background:#d2eaf1; > .circle-wrap  margin: 150px auto; width: 150px; height: 150px; background: #fefcff; border-radius: 50%; border: 1px solid #cdcbd0; > 

The basic structure of Circular Progress Bar

Step 2: Half of the simple CSS circle progress bar

As I said before, the animation in this circle is divided into two parts. This means that the animation has been divided into two parts up to the customer value. I have made the first part of those two parts. Width and height 150 have been used to make this animation equal in size to the Circular Progress Bar. Similarly, border-radius 50% has been used to make it round. Here I have set the background-color to blue. If you want to play an animation in another color, you can use that color here.

 class="mask half">  class="fill">
.circle-wrap .circle .mask, .circle-wrap .circle .fill  width: 150px; height: 150px; position: absolute; border-radius: 50%; > .mask .fill  clip: rect(0px, 75px, 150px, 0px); background-color: #227ded; > 

Half of the simple CSS circle progress bar

Step 3: The other half of the Circular Progress Bar

Now I have designed the other half of the Circular Progress Bar. I set the time to three seconds by adding animation here. This means that when this page is opened, the animation will take 3 seconds to reach the meaning you set from zero. Here 135 degrees have been used using transform. This transform will determine where the animation will end in this circle. ➤ We know that a circle is formed by 360. Since here we have divided the CSS circle progress bar into two parts, so each part is 180 degrees. ➤ Here we have set a 135-degree animation for each part using Transform. So it will be 270 degrees for the total circle. Here I want to increase the animation to 75% so I have used 270 degrees.

You determine the value of this degree according to your needs. For example, if you want the animation of the Circular Progress Bar will be up to 80%. But for that, you have to use 144 degrees here . Lastly, I have implemented this animation using @keyframes.

 class="mask full">  class="fill">
.circle-wrap .circle .mask  clip: rect(0px, 150px, 150px, 75px); > .mask.full, .circle .fill  animation: fill ease-in-out 3s; transform: rotate(135deg); > @keyframes fill 0%  transform: rotate(0deg); > 100%  transform: rotate(135deg); > > 

The other half of the Circular Progress Bar

Step 4: Create a percentage in the Circular Progress Bar

Now I have added percentages in this circular progress bar. Although that percentage of animation is not added. Added text using basic HTML and CSS code. I have used text-align: center and position: absolute to place the text in the middle of the Circular Progress Bar. I used border-radius: 50% to make its background width and height 122 px and round. Here I have used font-size: 2em to make the size of the text smaller and larger.

.circle-wrap .inside-circle  width: 122px; height: 122px; border-radius: 50%; background: #d2eaf1; line-height: 120px; text-align: center; margin-top: 14px; margin-left: 14px; color: #1e51dc; position: absolute; z-index: 100; font-weight: 700; font-size: 2em; > 

Circular Progress Bar using HTML and CSS

Related Post:

  1. Responsive Footer HTML CSS
  2. Todo List using JavaScript
  3. Simple Stopwatch using JavaScript
  4. Javascript Age Calculator
  5. javaScript Password Generator
  6. Automatic Image Slider in Html CSS
  7. Sidebar Menu Using HTML CSS

As you can see in the picture above, now this CSS Circular Progress Bar is absolutely ready. Hope you find out from this article how I created this Circular Progress Bar using HTML and CSS.

Источник

Circle progress bar with pure CSS and HTML

Progress bars are widely used on websites to highlight specific data in a more appealing way for users. One benefit of using a circle progress bar over a regular (horizontal) progress bar is that you can fit more progress bars in one row, thus displaying more data to the user.

I’ve already covered how you can style a progress bar in my earlier article. But now we’re going to look at how you can create a circle progress bar.

Setup

To display a circle progress bar with CSS we want to use as few HTML elements as possible. A proper way to show a progress bar is to use a semantic HTML element called progress.

However, it has specific default styles which make its unique appearance, thus preventing us from using all available CSS properties and displaying it as a circle.

As an alternative, we can use a div element with a progressbar role.

So to create a circle progress bar with only CSS we will need to use a div element anyway. There are two options for the markup.

Option 1

The first option is to use a regular div with a progressbar role along with additional ARIA attributes such as aria-valuenow , aria-valuemin , and aria-valuemax to indicate the range of the progress bar. HTML looks as follows:

 class="progress-bar" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">

Option 2

The second option is to wrap a progress element inside a div and hide it with CSS. That way we use a native progress element that will still be accessible in the DOM (just visually hidden) and the div will act as a visual representation. HTML looks as follows:

 class="progress-bar">  value="75" min="0" max="100" style="visibility:hidden;height:0;width:0;">75%  

Conic gradient

Since in both HTML approaches we will be styling a div element to create a circular progress bar, we’re going to use gradients. For the background property, we’ll set a radial-gradient function and a conic-gradient function that is available in CSS.

The conic-gradient will show the actual progress (the current value) and the radial-gradient will act as a mask on top of the conic-gradient .

.progress-bar  width: 100px; height: 100px; border-radius: 50%; background: radial-gradient(closest-side, white 79%, transparent 80% 100%), conic-gradient(hotpink 75%, pink 0); > 

To break it down. The conic-gradient function accepts multiple parameters (steps). In our case it is two steps, the first one will start at 0 degrees (12 o’clock) and span all the way up to 75% of the circumference of the circle (9 o’clock).

The radial-gradient in our case represents the mask, and consists of a white color (to match the background) and transparent color to show the progress bar.

The first parameter of the radial-gradient function is the size of the gradient’s ending shape, in our case, it is equal to the closest-side . Meaning the gradient’s ending shape meets the side of the box closest to its center.

After the size of radial-gradient , we specify the color and size of our mask (white overlay) white 79% and transparent color to take up the remaining size of the circle transparent 80% 100% . The one percent difference (79% and 80%) is made to smooth out the border of the gradient.

Browser compatibility for conic-gradient function:

Conic gradient browser support

Browser compatibility for radial-gradient function:

Radial gradient browser support

Showing the percentage

Additionally, let’s display a percentage value in the middle of the circle to inform users about the exact value of our progress bar.

To do so, we can use a pseudo-element with a content property. As for the progress bar div , we’ll need to set additional properties to center the percentage, flex in this case.

.progress-bar  display: flex; justify-content: center; align-items: center; width: 100px; height: 100px; border-radius: 50%; background: radial-gradient(closest-side, white 79%, transparent 80% 100%), conic-gradient(hotpink 75%, pink 0); > .progress-bar::before  content: "75%"; > 

Animation

💡 NOTE: The animation of such a progress bar will only work in Chromium-based browsers.

To make the progress bar animate, we’ll need to specify the value inside a CSS variable, and then change its value inside the animation.

We must use @property rule to use the variable value inside the animation, but like I said previously, this way we are limited to Chromium based browsers.

Specifying CSS variables in a traditional way like —progress-value: 0 won’t work inside the animation, as per specification they are not animatable.

Browser compatibility for @property rule:

@property browser support

We’ll need to change the percentage value to a calc() function to calculate the percentage for the conic-gradient .

Finally, let’s animate the percentage value along with the progress bar. We will do it in a similar fashion. We’ll use existing CSS variable and set it equal to a pseudo-element counter property, as well as specify the animation property.

@property --progress-value  syntax: ""; initial-value: 0; inherits: false; > @keyframes progress  to  --progress-value: 75; > > .progress-bar  display: flex; justify-content: center; align-items: center; width: 100px; height: 100px; border-radius: 50%; background: radial-gradient(closest-side, white 79%, transparent 80% 100%), conic-gradient(hotpink calc(var(--progress-value) * 1%), pink 0); animation: progress 2s 1 forwards; > .progress-bar::before  counter-reset: percentage var(--progress-value); content: counter(percentage) '%'; animation: progress 2s 1 forwards; > 

Result (refresh page):

Conclusion

While pure CSS solution for circle progress bar is easy to implement it lacks additional customization. For the most part you can only control the width and color of the bar.

Another aspect of this solution, is that it’s not yet fully supported by all browsers, the animation to be exact. So if you’re considering a bulletproof way to display a circle progress bar with animation and possible customizations, you’d might want to use SVG solution.

Finally the end result with complete code can be viewed on CodePen:

See the Pen Untitled by Nikita Hlopov (@nikitahl) on CodePen.

Источник

Читайте также:  Java application properties yaml
Оцените статью