Half circle with CSS (border, outline only)
Make a half circle using CSS by giving a div a half-hidden look. Get the round shape with border-radius
and hide the bottom half with overflow: hidden;
. Border outline is handled by ::before
pseudo-element.
HTML setup:
Taking your semi-circle skills to the next level
Customization and experimentation are half the fun of CSS. Mold and morph your half circle infinitude ways by playing with borders and dimensions.
Sizing and border-strokes
Modify your half circle's silhouette by juggling the height, width, and border thickness to keep it a perfect ratio, and it will result in an aesthetique half circle. Or get creative, unleash the chaos and mess up the proportions for an empressé look.
Responsive design
In a world where devices are as varied as people, responsivity is key. Use percentage values in border-radius
and width
then set the height
with padding-top as half the width's percentage and you have a half-circle that can turn heads in any viewport!
Cross-browser compatibility
Cross-browser issues can be a menace! (Cough, caniuse.com, cough.) Luckily, vendor prefixes are here to save the day.
Dynamic orientation and shape control
###Rotating the semi-circle
Want to create a unique, rotating half-circle? CSS can do that. Apply the transform
property and rotate to your satisfaction. Suddenly, your page has a frisbee in it!
Elliptical shapes
A fan of ellipses? Create an elliptical semi-circle by modifying border-top-left-radius
and border-top-right-radius
to get that fine, extended curvature. Look, the moon’s on your page!
Just remember, keep the height half the width.
Color and transparency
Fill the outline with color, or make a rainbow by setting transparent borders on sides not in use.
Was this article helpful?