CSS Border Radius Guide: Creating Rounded Corners and Custom Shapes
Learn how the CSS border-radius property works, from basic rounded corners to advanced 8-value syntax for creating organic blob shapes.
In web design, replacing sharp, boxy edges with soft corners and organic shapes is a key technique for building clean and modern interfaces. The CSS border-radius property offers vast flexibility, allowing you to do far more than just rounding button corners; it can also be used to generate complex, fluid "blob" shapes, circles, and ellipses.
In this guide, we will explore the fundamentals of CSS border-radius, delve into the advanced 8-value syntax, and see how you can create eye-catching visual elements for your web projects.
CSS Border Radius Basics
The border-radius property defines the radius of an element's corners. The simplest usage is straightforward:
/* Rounds all corners by 10 pixels */
border-radius: 10px;
/* Creates a perfect circle (when width and height are equal) */
border-radius: 50%;
You can specify multiple values to control different corners individually:
- One Value: Applies the same radius to all four corners.
- Two Values: The first value applies to top-left and bottom-right corners, the second value to top-right and bottom-left corners.
- Three Values: The first value applies to top-left, the second value to top-right and bottom-left, the third value to bottom-right.
- Four Values: Applies to top-left, top-right, bottom-right, and bottom-left in clockwise order.
Advanced Usage: The 8-Value Syntax
Many frontend developers only use up to four values for border-radius. However, CSS supports a more powerful 8-value syntax that allows you to specify different horizontal and vertical radii for each corner, separated by a slash (/):
border-radius: 10px 20px 30px 40px / 40px 30px 20px 10px;
Values before the slash represent the horizontal radii, while values after the slash represent the vertical radii. This separation makes it possible to construct organic, asymmetrical shapes like leaves, lemons, or smooth fluid blobs.
Creating Common Shapes with Border Radius
1. The Perfect Circle
To make a circular container, set the element's width and height to be equal (a square) and apply border-radius: 50%.
2. The Ellipse (Oval)
If the width and height of the element are different, applying border-radius: 50% will stretch the curves into a perfect mathematical ellipse.
3. Organic Fluid Blobs
Blobs are highly popular in modern UI as background highlights or image masks. They are created using percentages with the 8-value syntax:
border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
Calculating these percentages manually to get the perfect shape is tedious and involves a lot of trial and error. To design these shapes interactively, you can use our online CSS Border Radius Generator tool. It provides a visual playground where you can drag handle points to generate organic shapes and grab the generated CSS instantly.
Best Practices and Tips
- Handling Overflow: If you round the corners of a container, its child elements (like images or colored backgrounds) might bleed past the curved edges. To fix this, always add
overflow: hidden;to the parent container so that any overflowing content gets clipped to the rounded boundary. - Percentage vs. Pixel Units: Pixels (
px) produce constant, circular curves regardless of element size. Percentages (%) scale based on the width and height of the box. If your element is a rectangle, percentage values will stretch the curves, whereas pixel values will keep them uniform. - Rendering Performance: While
border-radiusis highly optimized in modern browsers, combining complex shapes with heavy shadows (box-shadow) on hundreds of elements simultaneously can cause minor lag on low-end mobile devices. Use them deliberately.