Draw circle using CSS alone
Make a flawless circle by setting the width and height of a div as equals and applying border-radius: 50%. Include a background to make it visible:
Indent this into your HTML:
This forms a 50px red circle. Tweak width, height, and background to alter.
Progressing with CSS
CSS offers a plethora of tools to embellish the way your circle shows up on the screen. Let's explore them:
Your circle's halo – box-shadow
You can make a simple circle more tangible with box-shadow:
Decorate with pseudo-elements
Pseudo-elements like :before or :after can give your circle complex shapes or layers:
Responsive dimensions
Use adjustable units like em, vw, or % instead of fixed pixel amounts to warrant your circle's proper scaling:
Ensuring cross-browser compatibility
Accessible design means your CSS circles should show up on any browser:
Catering for older browsers
Safeguard older versions of Firefox and Safari by including -moz- and -webkit- prefixes:
Plan B for ancient IE
IE8 and below can only fancy a circle using a :before pseudo-element with Unicode character (●):
Backing up with HTML character codes
The HTML character code •, used as a last resort, can conjure a circle in a minimal-CSS environment:
You can style this character with font-size and color to convert it into a primitive circle.
Was this article helpful?
