20

I know how to create a css circle with border radius etc, but i'm interested in creating a css only doughnut shape roughly like this one here -> enter image description here

It would be one div but curved round back onto itself,

any ideas??

web-tiki
  • 92,319
  • 29
  • 210
  • 241
benhowdle89
  • 35,602
  • 65
  • 197
  • 321

5 Answers5

44
<div class="doughnut"></div>


.doughnut { 
    border: 50px solid #f00;
    border-radius: 100px;
    height:100px;
    width:100px;
}
Seth
  • 6,180
  • 3
  • 27
  • 44
5

This shape can also be drawn with css3 radial-gradient():

div {
  background: radial-gradient(circle, transparent 40%, purple 40%);
}

body {
  background: linear-gradient(orange, red) no-repeat;
  min-height: 100vh;
  margin: 0;
}

div {
  background: radial-gradient(circle, transparent 40%, purple 40%);
  border-radius: 100%;
  height: 300px;
  width: 300px;
  margin: 25px;
}
<div></div>
Mohammad Usman
  • 34,173
  • 19
  • 88
  • 85
  • Brilliant, lets the DOM unchanged, which can definitely be a deal-breaker when dealing with hundreds of elements. – Bil5 Apr 29 '21 at 10:57
4

Demo

div{width:200px; height:200px; border:1px solid black; position:relative; border-radius:200px;}
div:before{content:''; width:50px; height:50px; display:block; position:absolute; top:75px; left:75px; border:1px solid black; border-radius:200px;}
bookcasey
  • 37,335
  • 13
  • 73
  • 92
0

Just set the border radius to 50% of the div width:

Working sample

Scott
  • 20,800
  • 8
  • 42
  • 55
0

Th colors are off but this is as simple as it gets with some backwards compatibility. Can answer any questions later on if need be.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>CSS Donut</title>
<style>
#div1
{
 background-color: #f00;
 border: #f0f solid 1px;
 height: 100px;
 width: 100px;
 border-radius: 50px;
 -webkit-border-radius: 50px;
 -moz-border-radius: 50px;
}
#div2
{
 background-color: #0f0;
 border: #f0f solid 1px;
 height: 60px;
 margin: 20px 0px 0px 20px;
 width: 60px;
 border-radius: 30px;
 -webkit-border-radius: 30px;
 -moz-border-radius: 30px;
}
</style>
</head>

<body>
<div id="div1"><div id="div2">&#160;</div></div>

</body>
</html>
John
  • 11,516
  • 11
  • 87
  • 151