21

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
  • 99,765
  • 32
  • 217
  • 249
benhowdle89
  • 36,900
  • 69
  • 202
  • 331

5 Answers5

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


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

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
  • 37,952
  • 20
  • 92
  • 95
  • 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
5

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
  • 39,223
  • 13
  • 77
  • 94
0

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

Working sample

Scott
  • 21,475
  • 8
  • 43
  • 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
  • 1
  • 13
  • 98
  • 177