Subscribe

RSS Feed | RSS Email | Twitter
 

Sponsors

 

Search / Categories

 

CSS3 Border-Radius & Rounded Corners

Posted on January 8th, 2009 by Zen Elements 16 Comments

CSS3 Rounded Corners Border Radius

Use CSS3 border-radius to make your corners rounded! In this edition of the CSS3 series, we look at how to use the third generation Style Sheet language to round the corners of div layers. There is also a quick + / – to which browsers support the border-radius CSS3 effect.

Alert

Cross Brower Compatability
As previously mentioned in An introduction to CSS3, not all current browsers support CSS3 but for those good browsers that chose to be compatible, we have two prefixes that we can work with.

The Prefixes:
-moz (e.g. -moz-border-radius) works in FireFox.
-webkit (e.g. -webkit-border-radius) works in Safari & Google Chrome.

Round Corners with CSS3 (Collectively)

The ability to have rounded corners without using images has been something long saught after, removing the need for creating those perfect little corner images with appropraite backgrounds which, at best of times, was a very time consuming task. Now with CSS3 (browser permitting..) we can create rounded corners in a few lines of code.

This is a panel set with a 5 pixel standard border and a 15 pixel border radius.

  1. CSS3 Border Radius (Collectively)
  2. #my_CSS3_id {
  3.   font-family: Arial;
  4.   border: 5px solid #dedede;
  5.   -moz-border-radius: 15px;
  6.   -webkit-border-radius: 15px;
  7.   padding: 15px 25px;
  8.   height: inherit;
  9.   width: 590px;
  10. }

Current Browser Support (Tested, Jan 2009)

  • FireFox (3.0.5)
  • Google Chrome (1.0.154.36)
  • Internet Explorer (IE6, IE7, IE8…)
  • Opera (9.6)
  • Safari (3.2.1, Windows)
 

Round Corners with CSS3 (Individually)

This of course does not have to be done collectively! It is possible to round corners individually.

This is a panel set with a 5 pixel standard border and a 15 pixel border radius on two individual corners.

  1. CSS3 Border Radius (Individually)
  2. #my_CSS3_id {
  3.   font-family: Arial;
  4.   border: 5px solid #dedede;
  5.   -moz-border-radius-topleft: 15px;
  6.   -moz-border-radius-topright: 0px;
  7.   -moz-border-radius-bottomright: 15px;
  8.   -moz-border-radius-bottomleft: 0px;
  9.   -webkit-border-top-left-radius: 15px;
  10.   -webkit-border-top-right-radius: 0px;
  11.   -webkit-border-bottom-left-radius: 0px;
  12.   -webkit-border-bottom-right-radius: 15px;
  13.   padding: 15x 25px;
  14.   height: inherit;
  15.   width: 590px;
  16. }

Current Browser Support (Tested, Jan 2009)

  • FireFox (3.0.5)
  • Google Chrome (1.0.154.36)
  • Internet Explorer (IE6, IE7, IE8…)
  • Opera (9.6)
  • Safari (3.2.1, Windows)
 

Zen Elements Blog | CSS3 Series

Thanks for reading,
Alex | Zen Elements


 
RSS
Facebook
StumbleUpon

Comments (16)

JoeJanuary 9th, 2009 at 11:55 pm

too bad it does not work in IE7, I’ll love to use this CSS but most of my clients use IE7

AlanJanuary 10th, 2009 at 1:57 am

Yep second that, quite a lot still use IE7, shame….Is there a work around hack?

Zen ElementsJanuary 10th, 2009 at 11:12 am

It is one of those things we have to wait on, unfortunately. My suggestion – as I’m sure you see around other blogs & discussions – is to continue to push for the development of CSS3 in browsers and they should get on to getting it achieved.

You can go ahead to use the CSS 3 border-radius now – along with the other CSS3 effects – knowing that some browsers will not render it and have the fallback of the standard border. If you design keeping both aspects in mind, your website can continue to work well. If you look at Twitter, it does just this.

AkashJanuary 11th, 2009 at 10:03 am

@Joe
Yes I found a way to make it work in IE. Did I mention IE6 :)

Grab it here
http://www.htmlremix.com/curved-corner-border-radius-cross-browser/

tutorialandJanuary 11th, 2009 at 10:19 am

Tutorial Added

http://www.tutorialand.com

Zen ElementsJanuary 11th, 2009 at 4:55 pm

@Akash: This hack does work in some instances, however not them all. Some versions of IE are not very friendly with your .htc but I’m not throwing it completely as it at least takes a step or two closer to the mark. I think I would personally continue just to use an border/image alternative than this but each to their own.

Thank you for sharing.

Nick CowieJanuary 13th, 2009 at 2:43 am

One issue with .htc file is they have to be served with the correct mime type http://support.microsoft.com/default.aspx/kb/306231. Not the correct mime type IE (or at least some versions) ignore them.

ConorFebruary 19th, 2009 at 8:00 pm

That’s amazing!

I didn’t know that rounded borders were possible in Firefox 3.0.5 !

I can’t wait until cross browser CSS3 compatibility. Anyone any ideas as to when this is going to happen?

Zen ElementsFebruary 19th, 2009 at 11:38 pm

@Conor | I’m afraid the best answer I can give is, “how long is a piece of string?” More and more people are wanting it, especially when discovered and if we write, prod and nudge in that direction, it will become more widely supported.
That has been said for a few years now though for a few of these CSS3 declarations… =/

KristaFebruary 23rd, 2009 at 8:54 pm

Question:

Here’s my code, and my feeble grasp on how this all works is not permitting me to make this possible. Would any of you be able to show me how to add border-radius capabilities to my blog images?

.post img {
padding:4px;
border:none $bordercolor;
}

Best regards,
Krista
reply to: webmaster -at- saddlewire -dot- com

Zen ElementsFebruary 23rd, 2009 at 9:47 pm

@Krista

It is possible to apply the border-radius effect to images, however the results can be a little unexpected.
Apply the following CSS and you will see what I mean.

.post img {
padding: 15px;
border:5px solid #900;
-moz-border-radius:15px;
-webkit-border-radius: 15px;
}

The border wraps itself around behind the image, as supposed to performing any masking of the image.
While it might not be the answer you were looking for, I hope this helps you out a little in using the border-radius declaration.

MaxMay 10th, 2009 at 8:59 am

I just copied the code into my webeditor, and tested it out in Firefox and IE8 and it doesn’t work in the most recent version of IE8. This is something I’m interested in, and IE8 support would make me add it now. Its a pity that for Firefox that currently it requires their own declaration.
You could also check out: http://www.curvycorners.net

Replyhttp://www.curvycorners.net‘); return false;”>Quote
Zen ElementsMay 12th, 2009 at 11:21 am

@Max | The most unfortunate turn with CSS3, is definitely browser support. As you have found, even IE8 (Microsofts most recent release of Internet Explorer) does not support any more CSS3 than it did in IE6 or 7! *is continually annoyed with IE..*
Regarding curvycorners.net; I prefer to stay away from it as I do not like Javascript rending too many objects on a screen. Also, in my case just now, accessing it in IE8 found errors which caused an incomplete render of the site.

bisoMay 13th, 2009 at 1:25 pm

I am really so pissed off right now.. our site uses alot of rounded corners and we are using ALOOOOOOOOOOOT of images to do that..we can increase the loading of the page dramatically if we se css.. a couple of lines of test written once in the whole website :(

im really so mad at IE right now..

RonaldMay 19th, 2009 at 10:23 am

Just a heads up for those who are wondering why something like

-webkit-border-radius: 5px 6px 7px 8px;

will not work in Chrome: Chrome doesn’t support that shorthand. You will need to set the radius for each corner, ie

-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 6px;
-webkit-border-bottom-left-radius: 7px;
-webkit-border-bottom-right-radius: 8px;

serpicoJune 30th, 2009 at 6:07 pm

@biso – I suggest you look up CSS sprites to speed up your download speed.

Leave a comment

Your comment

top
  • Zen Elements on Facebook
  • Zen Elements on Flickr
  • Zen Elements on Twitter
  • Zen Elements RSS Feed

© Zen Elements Ltd. 2008. All Rights Reserved. Sitemap | CSS | XHTML | Terms & Conditions