HTML5 introduced a new "progress" element that by default is rendered as a progress bar (thermometer).
A very basic example is:
<progress max="100" value="85"></progress>
I have been experimenting with a variety of progress circle options using javascript, and also have been really impressed by some pure CSS approaches discussed here: CSS Progress Circle
I am interested to know if anyone has successfully applied CSS to the "progress" element to provide a pie/clock/circle rendering rather than a linear display?
EDIT/ADDENDUM: The "meter" element is also quite similar to "progress" but provides for a low/high range...I mention this more for anyone who might stumble upon this post in the future and want to apply a similar technique to the HTML5 meter element.
Run my code and see the result
Well, that's an interesting challenge.
The element has quite some default styles applied to it, by the browser and even the OS.
So first, we should get rid of the
appearance
property setting it to noneThen, additional styles are created by the browser stacking pseudo-elements. For instance, if you're looking at this answer in any webkit browser, the above snippet will still show a flat box with a green fill representing the progress.
Those pseudo-elements can be addressed in CSS too. Each browser has it's specific pseudo elements, which further complicates the issue.
Webkit stacks 3 pseudo elements, in the following hierarchy
while Gecko and Trident use a single pseudo-element for the progress fill bars,
::-moz-progress-bar
and::-ms-fill
, respectively.That should leave us with the progress element styled as a good ol' div, which we can use for any of the circle progress bar methods linked above, while being awesome at semantics. We might even use the default additional pseudo elements and style them as needed instead of creating nested divs and such mumbo jumbo.
This is, of course highly experimental and non-standard, so shouldn't be used for production. The support is somewhat decent though, with all major players getting some form of the appearance property, and the three major engines supporting the styling of the pseudo elements... so maybe I'll take back my previous statement and change it for a "just got to be extra careful"
Trying to do this in pure CSS is quite hard, so I don't think than this is the correct technique to do it.
Anyway, just as a technical exercise, let's try it. (Tested only in Chrome !)
First of all the basis. We are going to divide the circle in 4 quadrants, and for each one we will need a different style. Here we have the styles, showing in color (green, red, blue, yellow) the useful range of the progress value element. The gray area is the rest of the element, unused.
Now, let's show a trick for creating the radial segments. This can be acomplished setting an element normal (at a right angle) to the user, and applying some perspective:
And now, just some boring selectors (it's difficult to target values in the range 20-29 and not targetting the value 2 at the same time).
A little bit of JS, but only to control the progress value. You can use both the input and the slider to change it.
There is a difficulty in the overflow: hidden; and a bug in Chrome. It isn't expected for it to work on the same element where perspective is applied, but it should work applied to the progress itself. It just works half of the time ...
Also, another idea, the style is much more simpler, and I could get it to extend to the full range, but anyway it's a starting point: