Border-Radius

The CSS3 border-radius property allows web developers to easily utilize rounder corners in their design elements, without the need for corner images or the use of multiple div tags, and is perhaps one of the most talked about aspects of CSS3.

Since first being announced in 2005 the border-radius property has come to enjoy widespread browser support (although with some discrepancies) and, with relative ease of use, web developers have been quick to make the most of this emerging technology.

Here’s a basic example:

How it Works
Rounder corners can be created independently using the four individual border-*-radius properties (border-bottom-left-radius, border-top-left-radius, etc.) or for all four corners simultaneously using the border-radius shorthand property. We will firstly deal with the syntax for the individual border-*-radius properties before looking at how the border-radius shorthand property works.

Where two values are supplied these are used to define, in order, the horizontal and vertical radii of a quarter ellipse, which in turn determines the curvature of the corner of the outer border edge. Where only one value is supplied, this is used to define both the horizontal and vertical radii equally. The following diagram gives a few examples of how corners might appear given differing radii: If either value is zero, the corner will be square, not round.

border-radius
The border-radius shorthand property can be used to define all four corners simultaneously. The property accepts either one or two sets of values, each consisting of one to four lengths or percentages.

The Syntax:


The first set of (1-4) values define the horizontal radii for all four corners. An optional second set of values, preceded by a ‘/’, define the vertical radii for all four corners. If only one set of values are supplied, these are used to determine both the vertical and horizontal equally. //For each set of values the following applies:// If all four values are supplied, these represent the top-left, top-right, bottom-right and bottom-left radii respectively. If bottom-left is omitted it is the same as top-right, if bottom-right is omitted it is the same as top-left, and if only one value is supplied it is used to set all four radii equally.

Browser Support
At present Opera (version 10.5 onward), Safari (version 5 onward) and Chrome (version 5 onward) all support the individual border-*-radius properties and the border-radius shorthand property as natively defined in the current W3C Specification (although there are still outstanding bugs on issues such as border style transitions, using percentages for lengths, etc.). Mozilla Firefox (version 1.0 onward) supports border-radius with the -moz- prefix, although there are some discrepancies between the Mozilla implementation and the current W3C specification (see below).

Safari and Chrome (and other webkit based browsers) have supported border-radius with the -webkit- prefix since version 3 (no longer needed from version 5 onward), although again with some discrepancies from the current specification (see [|this article] for further details of how older versions of Webkit handle border-radius). Even Microsoft have promised, and demonstrated in their recent preview release, support for border-radius from Internet Explorer 9 onward (without prefix).
 * Update:**Recent Firefox nightly versions support border-radius without the -moz- prefix.

The -moz- prefix
Mozilla’s Firefox browser has supported the border-radius property, with the -moz- prefix, since version 1.0. However, it is only since version 3.5 that the browser has allowed elliptical corners, i.e. accepting two values per corner to determine the horizontal and verical radii independently. Prior to version 3.5, the browser only accepted one value per corner, resulting in corners with equal horizontal and vertical radii. The syntax, from Firefox 3.5 onwards, for the main part follows the current W3C specification, as described throughout this article, prefixed by -moz-. The only major difference is in the naming of the individual border-*-radius properties, with the -moz- prefixed properties following a slightly different naming convention as follows:


 * ~ W3C Specification ||~ Mozilla Implementation ||
 * border-radius || -moz-border-radius ||
 * border-top-left-radius || -moz-border-radius-topleft ||
 * border-top-right-radius || -moz-border-radius-topright ||
 * border-bottom-right-radius || -moz-border-radius-bottomright ||
 * border-bottom-left-radius || -moz-border-radius-bottomleft ||

The Mozilla implementation also behaves slightly differently from the specification when percentages are supplied.

Cross Browser Examples
Here’s a few basic examples that should work in current versions of Firefox, Safari/Chrome, Opera and even IE9: