CSS border-radius Property
Example
Add rounded corners to two <div> elements:
border: 2px solid blue;
border-radius: 25px;
}
#example2 {
border: 2px solid blue;
border-radius: 50px 20px;
}
Definition and Usage
The border-radius
property defines the radius of the element's corners.
Tip: This property allows you to add rounded corners to elements!
This property can have from one to four values. Here are the rules:
Four values - border-radius: 15px 50px 30px 5px; (first value applies to top-left corner, second value applies to top-right corner, third value applies to bottom-right corner, and fourth value applies to bottom-left corner):
Three values - border-radius: 15px 50px 30px; (first value applies to top-left corner, second value applies to top-right and bottom-left corners, and third value applies to bottom-right corner):
Two values - border-radius: 15px 50px; (first value applies to top-left and bottom-right corners, and the second value applies to top-right and bottom-left corners):
One value - border-radius: 15px; (the value applies to all four corners, which are rounded equally:
Default value: | 0 |
---|---|
Inherited: | no |
Animatable: | yes. |
Version: | CSS3 |
JavaScript syntax: | object.style.borderRadius="25px" |
- Inherited : "Inherited = no" means that it cannot takes (inherit) it's value from it's parent element.
- object - object in javascript means the element on which
border-radius
is applied. - Animatable - "Animatable = yes" means that it can be animated with CSS
@keyframes
.
Browser Support
The numbers in the table specify the first browser version that fully supports the property.
Numbers followed by -webkit- or -moz- specify the first version that worked with a prefix.
Property | |||||
---|---|---|---|---|---|
border-radius | 5.0 4.0 -webkit- |
9.0 | 4.0 3.0 -moz- |
5.0 3.1 -webkit- |
10.5 |
CSS Syntax
Note: The four values for each radius are given in the order top-left, top-right, bottom-right, bottom-left. (15px 20px 10px 5px)
- If bottom-left is omitted it is the same as top-right. (15px 20px 10px is same as 15px 20px 10px 20px)
- If bottom-right is omitted it is the same as top-left. (15px 20px is same as 15px 20px 15px 20px)
- If top-right is omitted it is the same as top-left. (15px is same as 15px 15px 15px 15px)
Property Values
Value | Description | Demo |
---|---|---|
length | Defines the shape of the corners. Default value is 0. | |
% | Defines the shape of the corners in % | |
initial | Sets this property to its default value. | |
inherit | Inherits this property from its parent element. |
More Examples
Example
Set rounded corners for an element with a background color:
border-radius: 25px;
background: #0054ff;
color: #fff;
padding: 20px;
width: 200px;
height: 150px;
}
Example
Set rounded corners for an element with a border:
border-radius: 25px;
border: 2px solid #0054ff;
padding: 20px;
width: 200px;
height: 150px;
}
Example
Set rounded corners for an element with a background image:
border-radius: 25px;
background: url(road.jpg);
background-position: left top;
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
}
Example
Also notice this: (Elliptical Border Radius)
e.g. For border-radius: 2em 1em 4em / 0.5em 3em;
The three values before the "/" will be:
- border-top-left-radius = 2em.
- border-top-right-radius = 1em.
- border-bottom-right-radius = 4em.
- border-bottom-left-radius = 1em.
- border-top-left-radius = 0.5em.
- border-top-right-radius = 3em.
- border-bottom-right-radius = 0.5em.
- border-bottom-left-radius = 3em.
- border-top-left-radius = 2em 0.5em.
- border-top-right-radius = 1em 3em.
- border-bottom-right-radius = 4em 0.5em.
- border-bottom-left-radius = 1em 3em.
border-radius: 2em / 5em;
}
/* is equivalent to:
border-top-left-radius: 2em 5em;
border-top-right-radius: 2em 5em;
border-bottom-right-radius: 2em 5em;
border-bottom-left-radius: 2em 5em; */
#example2 {
border-radius: 2em 1em 4em / 0.5em 3em;
}
/* is equivalent to:
border-top-left-radius: 2em 0.5em;
border-top-right-radius: 1em 3em;
border-bottom-right-radius: 4em 0.5em;
border-bottom-left-radius: 1em 3em; */
Comments
Post a Comment