Is it possible to draw circle using css only which can work on most of the browsers (IE,Mozilla,Safari) ?
Asked
Active
Viewed 3.8e+01k times
146
-
6This question [has been asked many times](http://www.google.com/search?q=site%3Astackoverflow.com+css+circle) – OverZealous Aug 04 '11 at 06:21
-
1This is included in [How to make a circle around content using CSS?](http://stackoverflow.com/q/9358882/562769) – Martin Thoma Jun 29 '13 at 17:28
6 Answers
242
Yep, draw a box and give it a border radius that is half the width of the box:
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
Working demo:
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
<div id="circle"></div>

mplungjan
- 169,008
- 28
- 173
- 236

Tatu Ulmanen
- 123,288
- 34
- 187
- 185
-
6
-
3IE8 does not support border-radius, so that makes sense... Great idea for modern browsers though, very cool... – jcreamer898 Feb 08 '13 at 14:37
-
39Instead of supporting IE8 please ask your clients if you can show a message telling the user to upgrade their browser. It will benefit everyone, and Microsoft recommends it. Google even discontinued IE8 support in their web apps (Gmail, Calendar, Drive, Docs, etc.) at the end of 2012. It's ridiculous to support a 5 year old browser. – Gavin Sep 12 '13 at 10:08
-
2use a polyfille for ie8 http://css3pie.com/ and use border-radius:100%; for responsive circle use padding-bottom:40%; width:40%; height:0; overflow:visible; – fearis Jun 29 '15 at 17:20
-
2
-
there is a much simpler way now using aspect-ratio: .circle { inline-size: 25ch; aspect-ratio: 1; border-radius: 50%; } – Felix Haeberle Mar 23 '23 at 07:14
177
You could use a .before with a content with a unicode symbol for a circle (25CF).
.circle:before {
content: ' \25CF';
font-size: 200px;
}
<span class="circle"></span>
I suggest this as border-radius won't work in IE8 and below (I recognize the fact that the suggestion is a bit mental).
-
4`:before` doesn't work in IE7 and below, so this method only gains support for IE8 but makes it very hard to position the circle correcly. For example, font-size of 200px doesn't equate to a circle with a diameter of 200px and you lose antialiasing on some systems. – Tatu Ulmanen Aug 04 '11 at 08:02
-
Maybe also we can set `margin: -0.5em -0.3em -0.3em -0.1em` – Pierre de LESPINAY Nov 30 '12 at 12:41
-
1Given that at this point, IE 8 is nearly 10 years old, this should no longer be the accepted answer. It is reasonable to drop support for it, as according to https://caniuse.com/usage-table, IE 8 currently has a 0.18% share of usage, and most modern websites have done so. The border-radius property is now supported pretty much across the board (https://caniuse.com/#search=border-radius), so should be the accepted answer. – bjg222 Aug 24 '18 at 22:19
-
is there a way to appease the SEO gods, even if i use an image of circular text, instead of rotating each letter? – oldboy Oct 19 '20 at 08:21
52
- Create a div with a set height and width (so, for a circle, use the same height and width), forming a square
- add a
border-radius
of 50% which will make it circular in shape. (note: no prefix has been required for a long time) - You can then play around with
background-color
/ gradients / (evenpseudo elements
) to create something like this:
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
.yellow {
background-color: yellow;
}
.sphere {
height: 200px;
width: 200px;
border-radius: 50%;
text-align: center;
vertical-align: middle;
font-size: 500%;
position: relative;
box-shadow: inset -10px -10px 100px #000, 10px 10px 20px black, inset 0px 0px 10px black;
display: inline-block;
margin: 5%;
}
.sphere::after {
background-color: rgba(255, 255, 255, 0.3);
content: '';
height: 45%;
width: 12%;
position: absolute;
top: 4%;
left: 15%;
border-radius: 50%;
transform: rotate(40deg);
}
<div class="sphere red"></div>
<div class="sphere green"></div>
<div class="sphere blue"></div>
<div class="sphere yellow"></div>
<div class="sphere"></div>

web-tiki
- 99,765
- 32
- 217
- 249

jbutler483
- 24,074
- 9
- 92
- 145
-
3
-
1
-
I learned a lot from this simple example. Thank you very much for it. – degenerate Jul 15 '16 at 14:23
-
1
-
1I was going to post an angry reply saying that it's the same answer as Tatu's but then I clicked "Run Code".... #micdrop – NickG Sep 15 '16 at 15:58
-
1
11
This will work in all browsers
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
}

AeJey
- 1,447
- 20
- 40
9
yup.. here's my code:
<style>
.circle{
width: 100px;
height: 100px;
border-radius: 50%;
background-color: blue
}
</style>
<div class="circle">
</div>

Erik Schierboom
- 16,301
- 10
- 64
- 81