CSS Reference ยท Borders, Outlines and Shadows
The border-radius property
Reference for the CSS border-radius property: round box corners with lengths or percentages, set elliptical corners with a slash, with live examples and usage notes.
The border-radius property rounds the corners of an element's box. A radius describes the quarter circle (or quarter ellipse) that replaces the sharp corner: the larger the radius, the rounder the corner. It is a shorthand for the four corner properties border-top-left-radius, border-top-right-radius, border-bottom-right-radius and border-bottom-left-radius.
The rounding is not only visual decoration on the border. The element's background, its box shadow, and (with overflow other than visible) its content are all clipped to the rounded shape.
.card { border-radius: 12px; }
Try it
The last two boxes show the difference between 50% and a huge length. On a rectangle, 50% produces an ellipse, while 999px produces a pill: the browser scales the radii down just enough that the curves meet, but the straight edges stay.
Syntax
border-radius: <length-percentage>{1,4} [ / <length-percentage>{1,4} ]?;
- Initial value:
0 - Applies to: all elements (but not the internal table elements when
border-collapseiscollapse) - Inherited: no
- Animatable: yes, as lengths and percentages
- Computed value: for each corner, two absolute lengths or percentages (horizontal and vertical radius)
Values
| Value | Description |
|---|---|
<length> |
A fixed radius such as 8px or 0.5rem. Negative values are invalid. |
<percentage> |
Relative to the border box: the horizontal radius uses the width and the vertical radius uses the height. 50% on a square gives a circle. |
| One value | Applies to all four corners. |
| Two values | The first is top-left and bottom-right, the second is top-right and bottom-left. |
| Three values | Top-left, then top-right and bottom-left, then bottom-right. |
| Four values | Top-left, top-right, bottom-right, bottom-left (clockwise from the top-left). |
a / b |
Values before the slash are horizontal radii and values after it are vertical radii, which gives elliptical corners. |
Usage notes
- Overlapping radii are scaled down. If the radii on one side add up to more than the side's length, the browser shrinks all radii by the same factor. That is why a very large value like
999pxgives a clean pill shape. - Content may poke out. Rounded corners do not clip children by default. Add
overflow: hidden(oroverflow: clip) to the parent when an image or coloured child would otherwise cover the curve. - Outlines and shadows follow the curve.
box-shadowis always rounded to match, and modern browsers also curve theoutlinearound the rounded border box. - Border images ignore it. A
border-imageis not rounded byborder-radius. Clip withclip-pathor use a background-based trick instead. - Inner curve. With a thick border, the inner edge of the border has a smaller radius (the outer radius minus the border width, never below zero).
- Tables. Radii do not work on cells, rows or the table when
border-collapseiscollapse. Useseparate, or round a wrapper element. - Logical properties. For layouts that change direction, use
border-start-start-radiusand its siblings instead of physical corners.
Browser support
Supported in every current browser, with no vendor prefix needed.
Related
border-top-left-radiusand the other corner propertiescorner-shapeโ change the corner style (limited support)box-shadow,outline,border-image- Lesson: Rounded Corners
- Lesson: Borders