23 Jul 2003
I was talking to Jesper about the dotted CSS borders trick and the subject of rounded corners in CSS came up so I showed him my method. There are other ways that I’ve seen it done, but the other methods always require lots of complex HTML and CSS. I figure that lots of nested divs aren’t much better than using a table, so my way doesn’t require much in the way of HTML or CSS. Here’s how I do it.
Create four images for your corners. Most graphics programs have a tool that will create rounded-off squares. I’ll be using this square here…

…and I’m going to cut off the corners to get my four images:
![]()
![]()
In the spot where I want the box to show up, I create a container div to hold the box, a div for the top row and a div for the bottom row. Between the top and bottom rows, I add my content. In the top and bottom row divs, I add the left corner image and set the inline style to read display: none;. This makes the image invisible unless I make it visible through the stylesheet. That way, I can hide the effect from incompatible browsers by not showing them the stylesheet.
<div class="roundcont"> <div class="roundtop"> <img src="tl.gif" alt="" width="15" height="15" class="corner" style="display: none" /> </div> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> <div class="roundbottom"> <img src="bl.gif" alt="" width="15" height="15" class="corner" style="display: none" /> </div> </div>
The CSS sets the width and background color of the container object and the color of the text inside. The margins on interior paragraphs are set so that the text doesn’t sit right up against the edge of the box.
Then the top and bottom divs are given a background image that contains the right corner images and the left corner images from the HTML code are enabled.
.roundcont {
width: 250px;
background-color: #f90;
color: #fff;
}
.roundcont p {
margin: 0 10px;
}
.roundtop {
background: url(tr.gif) no-repeat top right;
}
.roundbottom {
background: url(br.gif) no-repeat top right;
}
img.corner {
width: 15px;
height: 15px;
border: none;
display: block !important;
}
Here’s how it looks when it’s all put together.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
This works in IE6, Mozilla 1.3, and Opera 7 on Windows. It should work in most other modern browsers as well.
Update: Julian Bond asked if this will work with the container div set to 100% width. Here’s the box again. The only thing changed is the width of the roundcont class.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Very Nice.… Worked for me. Thanks.
worked great for me, thanks!
Worked great on all browsers!
Me ha gustado por su simplicidad aunque sea un método antiguo
Gracias
That’s a really useful explanation. You explain the process much more concisely than most other people writing on this topic.
Those who would rather not use a graphics program to create their initial images might want to check out a new application I have been working on at http://www.thoughtless.ca
It will let you change the size, shape, and color of your corners directly in the css, without without using a graphics editor.
BULL SHIT its not workling at all
i wanna use this inside a div tag which forms my page’s left colum
Eddie I am pretty sure this si just how to do it… I don’t even know how you would copyright orange square. If I could I would be the richest man in the world! All hail my box: _ |_|
Seriously though, thank you very much for this…
Thats awesome! I do not feel very comfortable with creating images, but the overall idea is cool.
Thanks for sharing! adi azar
I am getting a white bar (my ‘inside’ color) a few pixels high below the bottom of my box. My corners are 15 px high and my top looks good. So close… Any thoughts?
Looks great, I’ll give it a try. Much more efficient than the way I usually do this.
Thanks.
I have some problems with IE 7, ‘cause I have “text-align: center” at body.
My solution was add “text-align:left;” at “img.corner”.
(Sorry for my English)
This will not work on a gradient background or an image background… How can you do transparent corners? Need Javascript?
jaycbrf4: Sure it does. You’d just need to use an image with alpha transparency. A transparent PNG should work (older versions of IE can’t handle transparent PNGs without some work on your part,though)
Adam, but the transparent image would display the orange background-color of the div behind it, not the background of the parent container.. or?
These are the last 15 comments. Read all 287 comments here.
Adam Kalsey
Mobile: 916.600.2497
Email: adam AT kalsey.com
AIM or Skype: akalsey
©1999-2008 Adam Kalsey.
Content management by Movable Type.
Eddie
March 14, 2008 4:43 PM
Is this totally free? We are thinking to use it in our company and we are wondering if we need to buy license.
We are ready to pay for license if required,
Please let me know, Eddie Moses