Rounded Corners in Internet Explorer

Written by David Walsh on Wednesday, October 28, 2009


Rounded Corners

One of the reasons that I love Firefox and Webkit-based browsers (Chrome, Safari) is the ability to effortlessly create rounded-corner elements using pure CSS:

.round	{ -moz-border-radius:12px; -webkit-border-radius:12px; }

As you probably already know, IE doesn’t allow you to create rounded corners without using images or endless hacking. Enter the CurvyCorners javascript project. CurvyCorners allows you to quickly create rounded corners within Internet Explorer.

The CurvyCorners Javascript

<!-- SIMPLY INCLUDE THE JS FILE! -->
<script type="text/javascript" src="curvy.corners.trunk.js"></script>

CurvyCorners detects the usage of “-webkit-border-radius” and “moz-border-radius” on DOM elements and works its magic to duplicate the effect in IE using a series of small DIVs. There are no images involved. You may also identify specific elements to apply rounded corners to:

var settings = {
			tl: { radius: 12 },
			tr: { radius: 12 },
			bl: { radius: 12 },
			br: { radius: 12 },
			antiAlias: true
		 };
/* moooo */
$$('.round').each(function(rd) {
	curvyCorners(settings,rd);
});

MooTools + Curvy Corners

CurvyCorners is known to brick your MooTools code. The trunk code fixes those issues.

Don’t let Internet Explorer’s refusal to implement rounded corners via CSS keep your websites from being as dynamic as possible! CurvyCorners helps make rounded corners in IE possible!


Follow via RSS Epic Discussion

Commenter Avatar October 28 / #
Timothy says:

I’m not even going to look at the JS, but I will assume that this applies the table method in IE. Where it makes a table with bordering rows / columns, containing transparent cells that make it rounded. A correct assumption?

David Walsh October 28 / #

@Timothy: Incorrect — no table element involved.

Commenter Avatar October 28 / #
Laurence says:

Is there an equivalent method for jQuery?

David Walsh October 28 / #

@Laurence: CurvyCorners isn’t framework-specific: it will work with any library.

Commenter Avatar October 28 / #
Duncan says:

I have the problem on applying padding and embedding multiple rounded corners in i.e, stops allying the inner rounded corners .

Commenter Avatar October 28 / #
Laurence says:

So I can just amend the

[code]
$$('.round').each(function(rd) {
curvyCorners(settings,rd);
});
[/code]

to
[code]
$('.round').each(function(rd) {
curvyCorners(settings,rd);
});
[/code]

David Walsh October 28 / #

@Laurence: Yep.

Commenter Avatar October 28 / #
Savageman says:

Also useful for Opera, isn’t it? I’m used to SVG to accomplish it in Opera, but that still doesn’t work for IE (which is the point of your article).

Commenter Avatar October 28 / #
Balaji says:

Very nice! I’ve been wondering about “Rounded Corners in Internet Explorer” lately. Do you have any thoughts about Rounded Corners in Mozilla Firefox?

Commenter Avatar October 28 / #
Paul says:

simple include the file, and it does all the work. brilliant. worked great.

Commenter Avatar October 28 / #
René says:

Why would someone write stuff like this.. Brilliant.
Haven’t tested it yet, but does it also word on styling just 1 border?
So if you use things like:

-moz-border-radius-topleft: 4px;
-webkit-border-top-left-radius: 4px;
border-top-left-radius: 4px;

-moz-border-radius-topright: 4px;
-webkit-border-top-right-radius: 4px;
border-top-right-radius: 4px;

Commenter Avatar October 28 / #

@Rene: Did you only read the title of the post? :P That’s what those settings are all about “tl, tr …” top left, top right, etc.

I imagine it can auto detect that stuff too just like it auto detects the styles in the first place.

Commenter Avatar October 28 / #
Ben says:

Nice! BUT… just had a look at the generated code in the IE Developer Toolbar.. there’s hundreds and hundreds of DIVs been generated there, a lot of them with IE filter styles. This can’t be great for performance?

Commenter Avatar October 28 / #
olivier refalo says:

My rule of thumb. Use extended features for WebKit & FireFox.. leave the other browsers display is as is, without the fancy styling. In the end, users will switch to browser they like the most…

Commenter Avatar October 28 / #
thebitnix says:

Thanks much for this!

Commenter Avatar October 29 / #

Shouldn’t we just ignore IE cssroundedcornersfail and accept the lack of CSS3 support? All that JS! In that way people will never understand the difference in browser quality…

Commenter Avatar October 29 / #
dejan says:

As from 2.0.x, CurvyCorners allows you to put rounded corners on your page elements using CSS. No need for javascript.

Commenter Avatar October 29 / #
Anders Ringqvist says:

My eyes!!! It´s burning >.< damn, shouldn´t have looked at the generated code. It´s so fubar.

Commenter Avatar October 29 / #
vsync says:

from my vast experience with many “round corners” making scripts,
DD_Roundies is the best solution.

http://www.dillerdesign.com/experiment/DD_roundies/#nogo

Commenter Avatar October 29 / #
Greg says:

I’ve used curvey corners for IE and I like it. Though the main problem I have is when you rounding a corner on a container you want to be clickable then any JS rounded corner fix messes things up.
I’ve seen a tutorial for Opera rounded corners that used SVG and I’m wondering if maybe something similar could be used for IE (i think it uses VML not SVG mind you).

Commenter Avatar October 29 / #

I agree with vsync, DD_roundies, work very awesome. Not sure if its the fact that they have been around a while or not. Bonus of DD_roundies, that the library fixes transparent PNG loading in IE, and seems to be fastest one around.

Commenter Avatar October 29 / #
TheBigO says:

IMHO if IE can’t handle rounded corners – then I don’t see why we should be cluttering up the code and spending any extra time.

Like anything – this technique will be handy in the real world where some clients will insist on rounded corners in all browsers. Then it is balance between using this technique and any other that there may be floating around.

Good work. But not sure I’ll be using it anytime soon – unless I really need to.

Commenter Avatar October 29 / #
Jesse says:

I agree with oliver and anders, the code is a bit frightening. I was trying to use this library for a javascript web app, which it used to generate about four or so rounded containers and maybe 10 or so rounded buttons. The performance got pretty laggy with all that extra code getting injected. If you’re going to use it for just a few containers, it’s great, but any more than that I would just use PNG images and a PNG-fix script for IE.

Commenter Avatar October 30 / #

This is something which I was Looking for a long time.
Thanks buddy for posting this, I usally dont search, but I did — I found this. Extremely Happy.

Commenter Avatar October 31 / #

Agreed, DD_Roundies is the best solution out there. Don’t even bother playing around with any other scripts.

David Walsh October 31 / #

I recall using DD_Roundies and them messing up the position of an element.

Commenter Avatar October 31 / #
sebastien brault says:

please don’t use this!!
use standard CSS for standard compliant browsers, let IE fail (it’ll just display square corners).

Rounded corners are trivial and don’t justify kilobytes of javascript or absurdly complex markup and slow-down performance.

David Walsh October 31 / #

@sebastien brault: “Let IE Fail”…that’s ridiculous. While I agree that rounded corners are trivial, would every client believe so? Probably not.

Commenter Avatar October 31 / #
Sam says:

Great tip, I will be implementing this solution on one of my projects this week!

Commenter Avatar October 31 / #
sebastien brault says:

@David Walsh: “Let IE Fail”…that’s ridiculous.
If you HAVE to use rounded corners, using background images still seems more reasonable to me, both from page-load performance and markup coherence stand-points.
But if the “solution” is to load hundreds of lines of javascript code that generates absurd html markup, I would much rather try to deliver web layouts that avoid using rounded corners and don’t sacrifice meaningful markup.

I just hope web designers don’t start implementing this “solution” all over the place without considering the draw-backs, because they are huge.

Commenter Avatar November 04 / #
josefina says:

@olivier refalo: you will loose clients with that rule of thumb!

In my opinion applying JS for styling is just not right. Performance is very important in big sites! Of course if you are developing a site for your little sister then you dot think too much about pixel perfect and cross browsers implementation problems..but talking seriously, this is not the way to go! not JS or behaviors for CSS! they just slow down the loading of your site.

Commenter Avatar November 05 / #

Reading this conversation, I am really surprised. Think about it, if you want to let IE fail then doesn’t that include not caring about performance in it? If your site loads a tad slower with this script in IE, then hell let it be. Even though JS shouldn’t be used for styling, it SHOULD be used for fixing stuff for older/non-standard browsers. There are many like HTML5 Shiv, PNG Fixes, etc so I don’t really see a problem with this one.

Personally, I would put this within conditional tags for IE, and use php for opera detection. This way modern browsers would not suffer for IE/Opera.

Commenter Avatar November 15 / #
Ken says:

Wow this is cool. I just hope this js won’t eat up the users pc resources. I have a pretty cool design on one of my websites but in IE looks like a shit only because of the inexistent rounded corners (yep I was little bit lazy to create that rounded img).

Commenter Avatar December 16 / #
Luke says:

I’m going to stick with the traditional use of images until CSS3 is fully supported, may I also like to add that what if javascript was disabled? Alot of people browse with it turned off, images in my opinion seems tidier and works for everyone.

Commenter Avatar December 31 / #
Anders Lindén says:

Unfortunately, when this webpage was loading, the corners were straight for a while. I cannot use that…

Be Heard!

I want to hear what you have to say! Share your comments and questions below.

Name*:
Email*:
Website:  


© David Walsh 2007-2010. Contact David Walsh. Powered by the remarkable MooTools javascript framework.