DEV Community

Cover image for How to create a circle using Pure CSS?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to create a circle using Pure CSS?

Originally posted here!

You can create a circle using pure CSS. πŸ”₯

TL;DR

/* Make a Circle in pure CSS */
.circle {
  width: 100px;
  height: 100px;
  background: red;
  border-radius: 50%;
}
Enter fullscreen mode Exit fullscreen mode

If you want a clearer explanation read on. πŸš€

First, let's create a square shape in CSS using the same width and height since a square has width = height.

Let's say both width and height to be 100px like this,

/* Make a Circle in pure CSS */
.circle {
  width: 100px;
  height: 100px;
}
Enter fullscreen mode Exit fullscreen mode

Now let's give a simple background color of red like this,

/* Make a Circle in pure CSS */
.circle {
  width: 100px;
  height: 100px;
  background: red;
}
Enter fullscreen mode Exit fullscreen mode

Now all we have to do is set the border radius to 50% or greater so that it is converted to a perfect circle. It can be done like this,

/* Make a Circle in pure CSS */
.circle {
  width: 100px;
  height: 100px;
  background: red;
  border-radius: 50%;
}
Enter fullscreen mode Exit fullscreen mode

That's it! You have made a circle shape πŸ˜ƒ.

See the code live in JSBin.

To make an even smaller circle change the width and height to a much smaller pixel value.

Let's say we want a circle to be 10px in width and height. It can be done like this,

/* Much smaller Circle in pure CSS */
.circle {
  width: 10px;
  height: 10px;
  background: red;
  border-radius: 50%;
}
Enter fullscreen mode Exit fullscreen mode

Feel free to share if you found this useful πŸ˜ƒ.


Top comments (0)