Skip to main content

CSS Rounded Corners

Rounded corners on an element come from one CSS property: border-radius.


CSS border-radius Property

What border-radius controls is how large a radius each corner of the element gets.

It works on any element that has a background-color, a border, or a background-image.

Tip: Behind this shorthand sit the longhand properties border-top-left-radius, border-top-right-radius, border-bottom-right-radius, and border-bottom-left-radius.

Example

Each of these three boxes has rounded corners: the first gets them on a background color, the second on a border, the third on a background image.

Prompt
Create a page with three div elements, each with border-radius: 25px. The first div has a green background (#73AD21), the second has a green border (2px solid #73AD21), and the third has a background image. Each div is 200px wide and 150px tall with 20px padding and contains the text "Rounded corners!".
Output: complete HTML page

CSS border-radius - Specify Each Corner

Anywhere from one to four values can be given to border-radius, and the count decides which corners each value reaches.

border-radius: 15px 50px 30px 5px; - with four values, the corners are assigned in turn: top-left, top-right, bottom-right, and finally bottom-left.

border-radius: 15px 50px 30px; - with three values, top-left takes the first, top-right and bottom-left share the second, and bottom-right takes the third.

border-radius: 15px 50px; - with two values, top-left and bottom-right share the first, while top-right and bottom-left share the second.

border-radius: 15px; - with one value, every one of the four corners gets the same rounding.

Example

One box per variation of the border-radius shorthand: one, two, three, and four values.

Prompt
Create a page with four div elements showing different border-radius values: four values (15px 50px 30px 5px), three values (15px 50px 30px), two values (15px 50px), and one value (15px). Each div has a green background (#04AA6D), is 200px wide and 150px tall.
Output: complete HTML page

CSS Elliptical and Circular Shapes

A corner turns elliptical when its radius has two values separated by a slash /: the horizontal radius comes first, then the vertical radius.

Setting border-radius to 50% gives a result that depends on the element's shape: a rectangular element becomes an oval, and a square one becomes a circle.

Example

Here border-radius produces elliptical, oval, and circular shapes.

Prompt
Create a page with four div elements demonstrating elliptical and circular shapes using border-radius. First: border-radius 70px/30px (200x150px), second: border-radius 15px/50px (200x150px), third: border-radius 50% (200x150px oval), fourth: border-radius 50% (200x200px circle). All with green background (#04AA6D).
Output: complete HTML page