<p>How can I create rounded corners using CSS?</p>

[{'answer_id': 7098, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 8, 'selected': True, 'text': '<p>Since CSS3 was introduced, the best way to add rounded corners using CSS is by using the <code>border-radius</code> property. You can <a href="http://www.w3.org/TR/css3-background/#the-border-radius" rel="noreferrer">read the spec</a> on the property, or get some <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius" rel="noreferrer">useful implementation information on MDN</a>:</p>\n\n<p>If you are using a browser that <a href="http://fmbip.com/litmus/" rel="noreferrer">doesn\'t</a> <a href="http://css3test.com/" rel="noreferrer">implement</a> <code>border-radius</code> (Chrome pre-v4, Firefox pre-v4, IE8, Opera pre-v10.5, Safari pre-v5), then the links below detail a whole bunch of different approaches. Find one that suits your site and coding style, and go with it.</p>\n\n<ol>\n<li><a href="http://www.alistapart.com/articles/customcorners/" rel="noreferrer">CSS Design: Creating Custom Corners\n&amp; Borders</a></li>\n<li><a href="http://www.smileycat.com/miaow/archives/000044.php" rel="noreferrer">CSS Rounded Corners \'Roundup\'</a></li>\n<li><a href="http://www.cssjuice.com/25-rounded-corners-techniques-with-css/" rel="noreferrer">25 Rounded Corners Techniques with CSS</a></li>\n</ol>\n'}, {'answer_id': 7099, 'author': 'Jeff Atwood', 'author_id': 1, 'author_profile': 'https://Stackoverflow.com/users/1', 'pm_score': 6, 'selected': False, 'text': '<p>I looked at this early on in the creation of Stack Overflow and couldn\'t find <em>any</em> method of creating rounded corners that didn\'t leave me feeling like I just walked through a sewer.</p>\n\n<p><a href="http://24ways.org/2006/rounded-corner-boxes-the-css3-way" rel="noreferrer">CSS3 does finally define</a> the </p>\n\n<pre><code>border-radius:\n</code></pre>\n\n<p>Which is exactly how you\'d want it to work. Although this works OK in the latest versions of Safari and Firefox, but not at all in IE7 (and I don\'t think in IE8) or Opera.</p>\n\n<p>In the meantime, it\'s hacks all the way down. I\'m interested in hearing what other people think is the cleanest way to do this across IE7, FF2/3, Safari3, and Opera 9.5 at the moment..</p>\n'}, {'answer_id': 7112, 'author': 'Lance Fisher', 'author_id': 571, 'author_profile': 'https://Stackoverflow.com/users/571', 'pm_score': 4, 'selected': False, 'text': "<p>I would recommend using background images.  The other ways aren't nearly as good: No anti-aliasing and senseless markup.  This is not the place to use JavaScript.</p>\n"}, {'answer_id': 7971, 'author': 'mbillard', 'author_id': 810, 'author_profile': 'https://Stackoverflow.com/users/810', 'pm_score': 3, 'selected': False, 'text': '<p>There\'s always the JavaScript way (see other answers) but since it\'s is purely styling, I\'m kind of against use client scripts to achieve this.</p>\n\n<p>The way I prefer (though it has its limits), is to use 4 rounded corner images that you will position in the 4 corners of your box using CSS:</p>\n\n<pre><code>&lt;div class="Rounded"&gt;\n  &lt;!-- content --&gt;\n  &lt;div class="RoundedCorner RoundedCorner-TopLeft"&gt;&lt;/div&gt;\n  &lt;div class="RoundedCorner RoundedCorner-TopRight"&gt;&lt;/div&gt;\n  &lt;div class="RoundedCorner RoundedCorner-BottomRight"&gt;&lt;/div&gt;\n  &lt;div class="RoundedCorner RoundedCorner-BottomLeft"&gt;&lt;/div&gt;\n&lt;/div&gt;\n</code></pre>\n\n<hr>\n\n<pre><code>/********************************\n* Rounded styling\n********************************/\n\n.Rounded {\n  position: relative;\n}\n\n.Rounded .RoundedCorner {\n  position: absolute;\n  background-image: url(\'SpriteSheet.png\');\n  background-repeat: no-repeat;\n  overflow: hidden;\n\n  /* Size of the rounded corner images */\n  height: 5px;\n  width: 5px;\n}\n\n.Rounded .RoundedCorner-TopLeft {\n  top: 0;\n  left: 0;\n\n  /* No background position change (or maybe depending on your sprite sheet) */\n}\n\n.Rounded .RoundedCorner-TopRight {\n  top: 0;\n  right: 0;\n\n  /* Move the sprite sheet to show the appropriate image */\n  background-position: -5px 0;\n}\n\n/* Hack for IE6 */\n* html .Rounded .RoundedCorner-TopRight {\n  right: -1px;\n}\n\n.Rounded .RoundedCorner-BottomLeft {\n  bottom: 0;\n  left: 0;\n\n  /* Move the sprite sheet to show the appropriate image */\n  background-position: 0 -5px;\n}\n\n/* Hack for IE6 */\n* html .Rounded .RoundedCorner-BottomLeft {\n  bottom: -20px;\n}\n\n.Rounded .RoundedCorner-BottomRight {\n  bottom: 0;\n  right: 0;\n\n  /* Move the sprite sheet to show the appropriate image */\n  background-position: -5px -5px;\n}\n\n/* Hack for IE6 */\n* html .Rounded .RoundedCorner-BottomRight {\n  bottom: -20px;\n  right: -1px;\n}\n</code></pre>\n\n<p>As mentioned, it has its limits (the background behind the rounded box should be plain otherwise the corners won\'t match the background), but it works very well for anything else.</p>\n\n<hr>\n\n<p><strong>Updated:</strong> Improved the implentation by using a sprite sheet.</p>\n'}, {'answer_id': 9199, 'author': 'mcaulay', 'author_id': 1148, 'author_profile': 'https://Stackoverflow.com/users/1148', 'pm_score': 3, 'selected': False, 'text': '<p>jQuery is the way i\'d deal with this personally. css support is minimal, images are too fiddly, to be able to select the elements you want to have round corners in jQuery makes perfect sense to me even though some will no doubt argue otherwise. Theres a plugin I recently used for a project at work here: <a href="http://web.archive.org/web/20111120191231/http://plugins.jquery.com:80/project/jquery-roundcorners-canvas" rel="nofollow noreferrer">http://web.archive.org/web/20111120191231/http://plugins.jquery.com:80/project/jquery-roundcorners-canvas</a></p>\n'}, {'answer_id': 22222, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 0, 'selected': False, 'text': '<p>I wrote a blog article on this a while back, so for more info, <a href="http://www.kibbee.ca/Blog/viewComments.php?blogid=354" rel="nofollow noreferrer">see here</a> </p>\n\n<pre><code>&lt;div class="item_with_border"&gt;\n    &lt;div class="border_top_left"&gt;&lt;/div&gt;\n    &lt;div class="border_top_right"&gt;&lt;/div&gt;\n    &lt;div class="border_bottom_left"&gt;&lt;/div&gt;\n    &lt;div class="border_bottom_right"&gt;&lt;/div&gt;\n    This is the text that is displayed\n&lt;/div&gt;\n\n&lt;style&gt;\n    div.item_with_border\n    {\n        border: 1px solid #FFF;\n        postion: relative;\n    }\n    div.item_with_border &gt; div.border_top_left\n    {\n        background-image: url(topleft.png);\n        position: absolute;\n        top: -1px;\n        left: -1px;     \n        width: 30px;\n        height: 30px;\n        z-index: 2;\n    }\n    div.item_with_border &gt; div.border_top_right\n    {\n        background-image: url(topright.png);\n        position: absolute;\n        top: -1px;\n        right: -1px;        \n        width: 30px;\n        height: 30px;\n        z-index: 2;\n    }\n    div.item_with_border &gt; div.border_bottom_left\n    {\n        background-image: url(bottomleft.png);\n        position: absolute;\n        bottom: -1px;\n        left: -1px;     \n        width: 30px;\n        height: 30px;\n        z-index: 2;\n    }\n    div.item_with_border &gt; div.border_bottom_right\n    {\n        background-image: url(bottomright.png);\n        position: absolute;\n        bottom: -1px;\n        right: -1px;        \n        width: 30px;\n        height: 30px;\n        z-index: 2;\n    }   \n&lt;/style&gt;\n</code></pre>\n\n<p>It works quite well.  No Javascript needed, just CSS and HTML.  With minimal HTML interfering with the other stuff. It\'s very similar to what Mono posted, but doesn\'t contain any IE 6 specific hacks, and after checking, doesn\'t seem to work at all.  Also, another trick is to make the inside portion of each corner image transparent so it doesn\'t block text that is near the corner.  The outer portion must not be transparent so it can cover up the border of the non-rounded div. </p>\n\n<p>Also, once CSS3 is widely supported with border-radius, that will be the official best way of making rounded corners.</p>\n'}, {'answer_id': 42264, 'author': 'CarmineSantini', 'author_id': 2166, 'author_profile': 'https://Stackoverflow.com/users/2166', 'pm_score': 2, 'selected': False, 'text': "<p>Sure, if it's a fixed width, it's super easy using CSS, and not at all offensive or laborious.  It's when you need it to scale in both directions that things get choppy.  Some of the solutions have a staggering amount of divs stacked on top of each other to make it happen.  </p>\n\n<p>My solution is to dictate to the designer that if they want to use rounded corners (for the time being), it needs to be a fixed width.  Designers love rounded corners (so do I), so I find this to be a reasonable compromise.  </p>\n"}, {'answer_id': 144373, 'author': 'Nathan Chase', 'author_id': 8086, 'author_profile': 'https://Stackoverflow.com/users/8086', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.ruzee.com/blog/ruzeeborders/" rel="nofollow noreferrer">Ruzee Borders</a> is the only Javascript-based anti-aliased rounded corner solution I\'ve found that works in all major browsers (Firefox 2/3, Chrome, Safari 3, IE6/7/8), and ALSO the only one that works when both the rounded element AND the parent element contain a background image.  It also does borders, shadows, and glowing.</p>\n\n<p>The newer <a href="http://www.ruzee.com/blog/shadedborder" rel="nofollow noreferrer"> RUZEE.ShadedBorder</a> is another option, but it lacks support for obtaining style information from CSS.</p>\n'}, {'answer_id': 210680, 'author': 'Jethro Larson', 'author_id': 22425, 'author_profile': 'https://Stackoverflow.com/users/22425', 'pm_score': 3, 'selected': False, 'text': '<p>Here\'s an HTML/js/css solution that I did recently. There\'s a 1px rounding error with absolute positioning in IE so you want the container to be an even number of pixels wide, but it\'s pretty clean. </p>\n\n<p>HTML:</p>\n\n<pre><code>&lt;div class="s"&gt;Content&lt;/div&gt;\n</code></pre>\n\n<p>jQuery: </p>\n\n<pre><code>$("div.s")\n.wrapInner("&lt;div class=\'s-iwrap\'&gt;&lt;div class=\'s-iwrap2\'&gt;")\n.prepend(\'&lt;div class="tr"/&gt;&lt;div class="tl"/&gt;&lt;div class="br"/&gt;&lt;div class="bl"/&gt;\');\n</code></pre>\n\n<p>CSS:</p>\n\n<pre class="lang-css prettyprint-override"><code>/*rounded corner orange box - no title*/\n.s {\n    position: relative;\n    margin: 0 auto 15px;\n    zoom: 1;\n}\n\n.s-iwrap {\n    border: 1px solid #FF9933;\n}\n\n.s-iwrap2 {\n    margin: 12px;\n}\n\n.s .br,.s .bl, .s .tl, .s .tr {\n    background: url(css/images/orange_corners_sprite.png) no-repeat;\n    line-height: 1px;\n    font-size: 1px;\n    width: 9px;\n    height: 9px;\n    position: absolute;\n}\n\n.s .br {\n    bottom: 0;\n    right: 0;\n    background-position: bottom right;\n}\n\n.s .bl {\n    bottom: 0;\n    left: 0;\n    background-position: bottom left;\n}\n\n.s .tl {\n    top: 0;\n    left: 0;\n    background-position: top left;\n}\n\n.s .tr {\n    top: 0;\n    right: 0;\n    background-position: top right;\n}\n</code></pre>\n\n<p>Image is just 18px wide and has all 4 corners packed together. Looks like a circle.</p>\n\n<p>Note: you don\'t need the second inner wrapper, but I like to use margin on the inner wrapper so that margins on paragraphs and headings still maintain margin collapse.\nYou can also skip the jquery and just put the inner wrapper in the html.</p>\n'}, {'answer_id': 465123, 'author': 'Brajeshwar', 'author_id': 19564, 'author_profile': 'https://Stackoverflow.com/users/19564', 'pm_score': 3, 'selected': False, 'text': '<p>With support for CSS3 being implemented in newer versions of Firefox, Safari and Chrome, it will also be helpful to look at "Border Radius".</p>\n\n<pre><code>-moz-border-radius: 10px;  \n-webkit-border-radius: 10px;  \nborder-radius: 10px;\n</code></pre>\n\n<p>Like any other CSS shorthand, the above can also be written in expanded format, and thus achieve different Border Radius for the topleft, topright, etc.</p>\n\n<pre><code>-moz-border-radius-topleft: 10px;  \n-moz-border-radius-topright: 7px;  \n-moz-border-radius-bottomleft: 5px;  \n-moz-border-radius-bottomright: 3px;  \n-webkit-border-top-right-radius: 10px;  \n-webkit-border-top-left-radius: 7px;  \n-webkit-border-bottom-left-radius: 5px;  \n-webkit-border-bottom-right-radius: 3px;\n</code></pre>\n'}, {'answer_id': 494584, 'author': 'Simon_Weaver', 'author_id': 16940, 'author_profile': 'https://Stackoverflow.com/users/16940', 'pm_score': 2, 'selected': False, 'text': '<p>As an indication of how complex it is to get rounded corners working, even <a href="http://developer.yahoo.com/yui/container/" rel="nofollow noreferrer">Yahoo discourages them</a> (see first bulleted point)! Granted, they\'re only talking about 1 pixel rounded corners in that article but it\'s interesting to see that even a company with their expertise has concluded they\'re just too much pain <a href="http://developer.yahoo.com/yui/container/1pxRoundedCornersIE.html" rel="nofollow noreferrer">to get them working</a> most of the time.</p>\n\n<p>If your design can survive without them, that\'s the easiest solution.</p>\n'}, {'answer_id': 644587, 'author': 'juanpablob', 'author_id': 77500, 'author_profile': 'https://Stackoverflow.com/users/77500', 'pm_score': 4, 'selected': False, 'text': '<p>As Brajeshwar said: Using the <code>border-radius</code> css3 selector. By now, you can apply <code>-moz-border-radius</code> and <code>-webkit-border-radius</code> for Mozilla and Webkit based browsers, respectively.</p>\n\n<p>So, what happens with Internet Explorer?. Microsoft has many behaviors to make Internet Explorer have some extra features and get more skills.</p>\n\n<p>Here: a <code>.htc</code> behavior file to get <code>round-corners</code> from <code>border-radius</code> value in your CSS. For example.</p>\n\n<pre><code>div.box {\n    background-color: yellow; \n    border: 1px solid red; \n    border-radius: 5px; \n    behavior: url(corners.htc);\n}\n</code></pre>\n\n<p>Of course, behavior selector does not a valid selector, but you can put it on a different css file with conditional comments (only for IE).</p>\n\n<p>The <a href="http://www.htmlremix.com/files/20080924-border-radius.zip" rel="noreferrer">behavior HTC file</a></p>\n'}, {'answer_id': 823255, 'author': 'alex', 'author_id': 31671, 'author_profile': 'https://Stackoverflow.com/users/31671', 'pm_score': 3, 'selected': False, 'text': "<p>In Safari, Chrome, Firefox &gt; 2, IE &gt; 8 and Konquerer (and probably others) you can do it in CSS by using the <code>border-radius</code> property. As it's not officially part of the spec yet, please use a vendor specific prefix...</p>\n<h3>Example</h3>\n<pre><code>#round-my-corners-please {\n    -webkit-border-radius: 20px;\n    -moz-border-radius: 20px;\n    border-radius: 20px;\n}\n</code></pre>\n<p>The JavaScript solutions generally add a heap of small <code>div</code>s to make it look rounded, or they use borders and negative margins to make 1px notched corners. Some may also utilise SVG in IE.</p>\n<p>IMO, the CSS way is better, as it is easy, and will degrade gracefully in browsers that don't support it. This is, of course, only the case where the client doesn't enforce them in non supported browsers such as IE &lt; 9.</p>\n"}, {'answer_id': 1121182, 'author': 'Sinan', 'author_id': 128398, 'author_profile': 'https://Stackoverflow.com/users/128398', 'pm_score': 5, 'selected': False, 'text': '<p>I generally get rounded corners just with css, if browser does not support they see the content with flat corners. If rounded corners are not so critical for your site you can use these lines below.</p>\n\n<p>If you want to use all corners with same radius this is the easy way:</p>\n\n<pre class="lang-css prettyprint-override"><code>.my_rounded_corners{\n   -webkit-border-radius: 5px;\n           border-radius: 5px;\n}\n</code></pre>\n\n<p>but if you want to control every corner this is good:</p>\n\n<pre class="lang-css prettyprint-override"><code>.my_rounded_corners{\n    border: 1px solid #ccc;\n\n    /* each value for each corner clockwise starting from top left */\n    -webkit-border-radius: 10px 3px 0 20px;\n            border-radius: 10px 3px 0 20px;\n}\n</code></pre>\n\n<p>As you see in each set you have browser specific styles and on the fourth rows we declare in standard way by this we assume if in future the others (hopefully IE too) decide to implement the feature to have our style be ready for them too. </p>\n\n<p>As told in other answers, this works beautifully on Firefox, Safari, Camino, Chrome.</p>\n'}, {'answer_id': 1357251, 'author': 'Thomas Maierhofer', 'author_id': 165958, 'author_profile': 'https://Stackoverflow.com/users/165958', 'pm_score': 0, 'selected': False, 'text': '<p>Don\'t use CSS, jQuery has been mentioned several times. If you need full control of the background and border of your elements give the<a href="http://www.maierhofer.de/en/open-source/jquery-background-canvas-plugin.aspx" rel="nofollow noreferrer">jQuery Background Canvas Plugin</a> a try. It places a HTML5 Canvas element in the background and allows yo to draw every background or border you want. Rounded corners, gradients and so on.</p>\n'}, {'answer_id': 1357286, 'author': 'Dan Dyer', 'author_id': 5171, 'author_profile': 'https://Stackoverflow.com/users/5171', 'pm_score': -1, 'selected': False, 'text': '<p>Opera does not support border-radius yet (apparently it will be in the release after version 10).  In the meantime, you can <a href="http://dev.opera.com/articles/view/new-development-techniques-using-opera-k/" rel="nofollow noreferrer">use CSS to set an SVG background to create a similar effect</a>.</p>\n'}, {'answer_id': 1453789, 'author': 'Tristan Brotherton', 'author_id': 111408, 'author_profile': 'https://Stackoverflow.com/users/111408', 'pm_score': 3, 'selected': False, 'text': '<p>I personally like this solution the best, its an .htc to allow IE to render curved borders.</p>\n\n<p><a href="http://www.htmlremix.com/css/curved-corner-border-radius-cross-browser" rel="noreferrer">http://www.htmlremix.com/css/curved-corner-border-radius-cross-browser</a></p>\n'}, {'answer_id': 2476241, 'author': 'Salman A', 'author_id': 87015, 'author_profile': 'https://Stackoverflow.com/users/87015', 'pm_score': 1, 'selected': False, 'text': '<p>There is no "the best" way; there are ways that work for you and ways that don\'t. Having said that, I posted an article about creating CSS+Image based, fluid round corner technique here:</p>\n\n<p><a href="http://salman-w.blogspot.com/2009/10/box-with-round-corners-using-css-and.html" rel="nofollow noreferrer">Box with Round Corners Using CSS and Images - Part 2</a></p>\n\n<p>An overview of this trick is that that uses nested DIVs and background image repetition and positioning. For fixed width layouts (fixed width stretchable height), you\'ll need three DIVs and three images. For a fluid width layout (stretchable width and height) you\'ll need nine DIVs and nine images. Some might consider it too complicated but IMHO its the neatest solution ever. No hacks, no JavaScript.</p>\n'}, {'answer_id': 2686628, 'author': 'Stéphane', 'author_id': 156415, 'author_profile': 'https://Stackoverflow.com/users/156415', 'pm_score': 1, 'selected': False, 'text': '<p>If you are to go with the border-radius solution, there is this awesome website to generate the css that will make it work for safari/chrome/FF.</p>\n\n<p>Anyway, I think your design should not depend on the rounded corner, and if you look at Twitter, they just say F**** to IE and opera users. Rounded corners is a nice to have, and I\'m personally ok keeping this for the cool users who don\'t use IE :).</p>\n\n<p>Now of course it\'s not the opinion of the clients.\nHere is the link : <a href="http://border-radius.com/" rel="nofollow noreferrer">http://border-radius.com/</a></p>\n'}, {'answer_id': 3342866, 'author': 'Sniffer', 'author_id': 93641, 'author_profile': 'https://Stackoverflow.com/users/93641', 'pm_score': 4, 'selected': False, 'text': '<p>If you\'re interested in creating corners in IE then this may be of use - <a href="http://css3pie.com/" rel="noreferrer">http://css3pie.com/</a></p>\n'}, {'answer_id': 5500456, 'author': 'starikovs', 'author_id': 202550, 'author_profile': 'https://Stackoverflow.com/users/202550', 'pm_score': 1, 'selected': False, 'text': '<p>To addition of htc solutions mention above, here\'re another solutions and examples to reach <a href="http://starikovs.com/2010/08/24/css3-rounded-corners/" rel="nofollow">rounded corners in IE</a>.</p>\n'}]
['https://Stackoverflow.com/questions/7089', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/889/']