Written by Harry Roberts on CSS Wizardry.
This is a quick post concerning the
border-radius CSS3 property, and the syntax behind it. After coming across this site earlier today via Twitter I remembered my initial frustrations with lack of uniformity across user agents and their required syntax in order to create round corners; Firefox requiring a different format to Webkit and the CSS3 spec was pretty annoying.
However, it’s not all that bad. As border-radius.com would have you believe, the syntax to create an element with top-left and bottom-right corners with a 50px round, and top-right and bottom-left corners with 10px rounds would be:
<code>-webkit-border-radius: 50px; -webkit-border-top-right-radius: 10px; -webkit-border-bottom-left-radius: 10px; -moz-border-radius: 50px; -moz-border-radius-topright: 10px; -moz-border-radius-bottomleft: 10px; border-radius: 50px; border-top-right-radius: 10px; border-bottom-left-radius: 10px;</code>
Wrong, you can actually use the
border-radius shorthand to nail this in three lines:
<code>-moz-border-radius:50px 10px 50px 10px; -webkit-border-radius:50px 10px 50px 10px; border-radius:50px 10px 50px 10px;</code>
The syntax follows the following rule:
border-radius:top-left top-right bottom-right bottom-left;. I’ve tested this in Firefox (
-moz-border-radius), Webkit (
-webkit-border-radius) and Opera (
border-radius) and it works just fine.
You’d think Webkit would just be Webkit, right? Wrong. This works in Chrome but not Safari. I’ve had reports that Safari 4.0.4 (I guess it’s not found it, get it? Oh never mind.) doesn’t work. Useful…
Still, this version will work, and is still considerably shorter:
<code>-webkit-border-radius: 50px; -webkit-border-top-right-radius: 10px; -webkit-border-bottom-left-radius: 10px; -moz-border-radius:50px 10px 50px 10px; border-radius:50px 10px 50px 10px;</code>
Hi there, I’m Harry. I am an award-winning Consultant Web Performance Engineer, designer, developer, writer, and speaker from the UK. I write, Tweet, speak, and share code about measuring and improving site-speed. You should hire me.
I am available for hire to consult, advise, and develop with passionate product teams across the globe.
I specialise in large, product-based projects where performance, scalability, and maintainability are paramount.