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.
Thats cool way, but i hope CSS nerds like you can figure out a way for us to do rounded corners without creating the images.
Thanks!
I have read through a lot of feedback where people say they are getting a bar a few pixels high at the bottom of thier box (in IE). I haven’t found a straight answer on how to fix this. Would you please save me some time and let me know?
Thanks!
for a way without images try googling “niftycorners”. this is a very good way also though.
Okay. So. Doing this layout: http://www.midnight-umbreon.net/other/layout.png and. I only need one rounded corner. The top right is done by the header image. I only need the bottom right. So, I created three other images that are just squares. Would this work?
Have to agree with Stuart — what can we do about the bar at the bottom?
It is not just good way. It is so simple you are saying about but I want to never use any kind of image. Only use colors and then make it round corners. it is no matter that what do you use, table or div. but i need you to use colors and and make round corners.
try giving 0 margin and 0 padding of each div. I understand different browsers have different default values and this may be causing the bar at the bottom.
OMG. You say DIVs are so great.
Then create a good 3x3 box code in few minutes, just like when using tables. Tip: the code above is not a GOOD one. In fact it sucks hard: it will break the transparent (gif, png) corners and borders.
Is it so hard to create a REAL 3x3 layout with DIVs?!
DIVs are theoretically nice, but they do suck like hell in the real life.
twoja stara, why so negative?
divs eat tables for breakfast, you just need to get to know them…
thanks for the excellent code Adam
Hi Adam, nice example its great but i have an question is it possible we can do it same with border corner .imeans to say we have a rounded box with border how to make tht in html
Well, it worked even in safari, in addition to all other browsers… I reallized that I can do this css corners using a background image (I mean the entire thing using image). it may be bad since it is going to take more time for download.. ur solution is better, but if u lazy, u can create 1 image using adobe, and place it as background.
Great work, worked on all browsers.. gonna use it on my website :)
Thanks, Alan
Great css, it worked on ie, and firefox for me.
Thanks
i dont gett itt :-| everyone says its really easyy omg im soo thick! pleasee explain.
These are the last 15 comments. Read all 309 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.
Kurt
May 27, 2008 12:44 AM
Thanks! Great explaining of the code, will help my css design skills greatly!