Files
30-seconds-of-code/snippets/circle.md
2018-03-04 16:19:52 +10:00

795 B

Circle

Creates a circle shape with pure CSS.

HTML

<div class="circle"></div>

CSS

.circle {
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  background: #333;
}

Demo

<style> .snippet-demo__circle { border-radius: 50%; width: 2rem; height: 2rem; background: #333; } </style>

Explanation

border-radius: 50% curves the borders of an element to create a circle.

Since a circle has the same radius at any given point, the width and height must be the same. Differing values will create an ellipse.

Browser support

No caveats.