Is it possible to create a circle using only HTML5 / CSS3 which has a border that only goes part way around the circle? If not, what techniques can I use to accomplish this effect? I would prefer to use pure DOM elements, but if I have to I can draw on canvas or spin up an SVG.
Share
2023 solution
This method requires no JS, no extra element and not even any pseudos, just a handful of CSS declarations. It also works if the element has a (semi)transparent
backgroundin addition to this partialborder.It uses a two layer
mask, one being aconic-gradientwhich creates a visible pie selection and whose size is relative to theborder-boxand the second being a simple full cover layer restricted to thepadding-box.First, we make our element circular (arbitrary
width, anaspect-ratioof1and aborder-radiusset to50%) and give it aborder.Then, we set a
maskthat’s aconic-gradient(), relative to theborder-box, covering a percentage--pof our element (by default starting from 12 o’clock and going clockwise).On top of this
masklayer, we set a full cover one restricted to thepadding-box.If we want to animate this, we need to also register
--p.Registering custom properties this way in order to animate them is supported in Chromium browsers and in Safari and it’s coming soonish in Firefox Nightly too.
Original answer from 2012 (preserved for web history reasons)
Yes, it is possible – see this: