Rounded Images in CSS With border-radius and object-fit
To round an image in CSS, set border-radius on the img element itself. Add object-fit: cover and aspect-ratio so photos of any size fill the shape without squashing, and use border-radius: 50% on a square image for a circular avatar. No wrapper elements, no background-image tricks and no JavaScript are needed.
In 2010 Firefox did not round img corners, so the fix was a jQuery snippet that wrapped each image in a span and moved the src into a background; every current browser now rounds images natively.
The basic rounded image
Three declarations cover most cases:
.rounded {
width: 220px;
aspect-ratio: 4 / 3;
object-fit: cover;
border-radius: 16px;
}
aspect-ratio reserves the box before the file loads, which also prevents layout shift. object-fit: cover scales and crops the photo to fill that box, the same result the old background-size: cover trick gave you, except the content stays a real img with alt text, lazy loading and right-click saving intact. Keep the width and height attributes in your HTML as well so the browser knows the intrinsic ratio early.

Shadows work on images too
The original article struggled because the inset shadow did not render. A regular box-shadow on an image now follows the rounded corners without any trouble:
.shadow {
border-radius: 16px;
box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
}
An inset shadow is different. Replaced elements such as img paint their content on top of their own inset shadow, so it is hidden. The fix is a tiny wrapper that draws the shadow in a pseudo-element above the image:
<div class="inset">
<img src="photo.jpg" width="800" height="600" alt="Harbour at dusk">
</div>
.inset {
position: relative;
aspect-ratio: 4 / 3;
border-radius: 16px;
overflow: hidden;
}
.inset img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.inset::after {
content: "";
position: absolute;
inset: 0;
border-radius: inherit;
box-shadow:
inset 0 0 0 6px rgb(255 255 255 / 0.85),
inset 0 0 24px rgb(0 0 0 / 0.45);
pointer-events: none;
}
This is the one place the wrapper idea from the old article survives, and it is plain static markup rather than something a script injects. pointer-events: none keeps the overlay from blocking clicks on the image or a link around it.
Circular avatars and other shapes
A circle is a square with a 50% radius. Because aspect-ratio: 1 forces the square, non-square uploads are cropped to the center instead of turning into ovals:
.avatar {
width: 110px;
aspect-ratio: 1;
object-fit: cover;
border-radius: 50%;
border: 4px solid #fff;
box-shadow: 0 4px 14px rgb(0 0 0 / 0.25);
}
Other radius values give you different personalities from the same markup:
- Squircle-like:
border-radius: 28%on a square is softer than a rounded rectangle and a good fit for app-icon style thumbnails. - Organic blob: the elliptical form
border-radius: 60% 40% 55% 45% / 50% 60% 40% 50%sets horizontal and vertical radii separately for an irregular shape. - One-sided rounding:
border-radius: 16px 16px 0 0rounds only the top, ideal for a card image that sits flush above text.
If you want fully pill-shaped ends on a wide image, use a very large value such as 9999px. The browser clamps it to the largest radius that fits.
Rounded images inside cards
When an image sits at the top of a card, round the card and let it clip its children instead of rounding both separately:
.card {
border-radius: 16px;
overflow: hidden;
}
.card img {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
}
The radius then lives in one place and hover effects such as a scale-up zoom stay neatly clipped to the card. You can see this pattern in our category image cards with zoom hover and the thumbnail grid with hover effects.
Two newer options are worth knowing. The corner-shape property (for example corner-shape: squircle alongside border-radius) gives true squircle, bevel and notch corners, but MDN still marks it experimental with limited availability, so treat it as progressive enhancement. The shape() function, now Baseline 2026, defines fully custom outlines for clip-path. And if you would rather skip the inset-shadow wrapper, an outline with a negative outline-offset can draw a similar inner frame directly on the image.
Responsive radius and theming
Store the radius in a custom property so every image on the site shares one value and you can change it in a single line:
:root { --radius-media: 16px; }
img.rounded, .card { border-radius: var(--radius-media); }
Percent and em values also scale with the element, so a 50% avatar stays circular at any size. For a nested element, such as an image inside a padded frame, make the inner radius smaller than the outer one by the padding amount, or the corners look uneven. With a 16px outer radius and 6px of padding, use 10px on the image.
Accessibility and performance notes
- Keep real images. Because the picture stays an
img, screen readers get the alt text. A background-image on aspanexposes nothing. - Decorative photos still need
alt="", not a missing attribute. - Use
loading="lazy"on images below the fold, and never on the main hero image. - Serve modern formats with
pictureand AVIF or WebP sources; rounding does not change how that works. - Focus rings: if the rounded image is a link, style
a:focus-visiblewith an outline andoutline-offset. Modern browsers curve the outline to matchborder-radius.
Common mistakes
Most rounding problems come down to a few causes. If an image looks oval instead of round, the element is not square: add aspect-ratio: 1 and object-fit: cover. If the corners are not rounded at all, check that a parent with overflow: hidden is not the element you meant to style, or that a rule later in the cascade overrides your radius. If a hover zoom spills outside the rounded shape, move the radius and overflow: hidden to the container that holds the image.
Finally, avoid setting a fixed height without object-fit. The photo will stretch, and rounding a distorted picture only makes the distortion more obvious. Pick the ratio first, then let the browser crop.
Browser support
border-radius, box-shadow, object-fit and aspect-ratio are all Baseline widely available, so you can ship them without fallbacks. Check MDN’s border-radius page if you need the compatibility tables. Old-browser workarounds such as the jQuery wrapper are not needed anymore and should be removed from legacy sites, since they add script weight and break lazy loading and alt text.
Where to go next
Rounded images are most often used for people. Browse the team section with round profile images and the testimonial cards with profile photos for finished layouts. For more cropping and sizing techniques, 20 pro CSS tips is a good follow-up, and this photo gallery with a modal lightbox shows rounded thumbnails in a full gallery.
Don’t work corectly with inset box-shadow on Chrome (Windows)
Well done!
This problem gave me headaches with Firefox.
I’ve had a need for something like this before and remember having to use similar techniques to get it to work before, however this makes it much easier. This might work well with a conditional to keep it from applying the shadow to Chrome on Windows, as that’s my only real concern with the technique – not having the shadow is fine, but the shadow making it look like the image is sitting on a grey box bothers me – frankly in Chrome/Win I’d almost rather see just a square image if there is a square shadow behind it anyway.
I do love the technique though, and hopefully Chrome will have better support for something like this in the future – by the way, has anyone checked this out in an IE9 preview to see if it will be supported there?
Thank you so much for this! This is great, but wouldn’t it be so great if IE would catch up with the times? I know that IE9 is supposed to be like awesome, but I will believe it when I see it, and you still have to be backwards compatible, although I have recently become a big fan of saying you know what…I am going to give those people a little aesthetic treat if they use FF or a webkit browser! Thanks for this though!
Don’t work the inset box-shadow on Chrome (win)
As mentioned in the demo page, inset box-shadow doesn’t display properly on Windows Chrome. It is a bug.
IE has plans to support CSS3 sometime in 2014.
50% of visitors won’t see fancy CSS3-stuff so all these CSS3 things feel quite unnecessary. :f
Have you considered adding ie-css3.htc to this package to get IE to work with it too?
Wonderful! Love the inset one. Ran into this problem a while ago, nice solution! :)
Awesome effect! I’ve been using similar methods to fix those rounded corners when using the CSS3 rounded corners.
Using jQuery to accomplish something that…. umm.. trivial in CSS and HTML seems like a poor idea.
Just looking at the before code (the html) and the after (the jQuery) is revealing enough. You’re now using 3x as much code, and you’re going to give all your users a flash of unstyled text.
:(
I really like this, but it’s a pity that win chrome can not correctly display this.
A very nice sollution. I was looking for something like this last week but I opted for masking the corners with png’s instead. Will try this one out next time though!
very useful article. I haven’t thought about making a corner for the image will need to go a way like you said. I thought it will be the same with the border.
Too bad it’s not cross browser… Not working in any ie…
This is very nice, but what about IE6?
The CSS version works for me in the latest (stable) release of Firefox, aswell as the IE9 Testdrive tool. The jQuery example doesnt work at all in the IE9 Preview tool, and does not have rounded corners in Firefox. I’m viewing on Windows 7 64.
Hi! I’m having a problem when the span tag wraps the img the img goes small (like 1 text line height) why is that happening?
discovered: add a “display:block;” at the span style and it works ;D
Instead of sharp corner, rounded corner appeals more. I have ported the code to work in prototypejs
document.observe(“dom:loaded”, function() {
$$(“.rounded-img”).each(function(tgt) {
if (Prototype.Browser.IE) {
tgt.src = “roundhandler.ashx?f=” + tgt.src + “&c=888”;
} else {
tgt.setOpacity(0).wrap(new Element(‘span’).addClassName(tgt.getAttribute(‘class’)).setStyle({
‘width’: tgt.width + ‘px’,
‘height’: tgt.height + ‘px’,
‘background’: ‘url(‘ + tgt.getAttribute(‘src’) + ‘) no-repeat center center’
}));
}
});
});
For IE, I am using a http handler to make the image rounded. If you would like to see it in action, you can go to this location
Thank you so much for sharing such a creative idea.
Nice idea, but opacity:0 uses more CPU e.g. most mobile devices than visibility:hidden. Do your mobile users a favour and swap these attributes.
Very cool & useful idea, but sometimes I have to refresh to get the .js to run (both in my implementation and on your demo page). Anyone know how to fix that?
Thanks!
George
Why don’t you have a “share on twitter” ?? this article is pretty cool !
@Claire (#29)– What about IE6? What year do you think this is?
I’m currently working on a website and was having this problem! Thanks for posting, this saves me a lot of time!
I think CSS3 need some more time to grow as we clearly know whats the problem is… we are still struggling and crumbling our code because of these browsers.
Anyways… Nice work and keep it coming :)
Excuse me if this has been covered in one of the comments already, but inset box-shadows do work in webkit browsers.
/* Safari & Chrome */
-webkit-box-shadow: inset 0px 1px 3px rgba(0, 0, 0, .5);
/* Firefox */
-moz-box-shadow: inset 0px 1px 3px rgba(0, 0, 0, .5);
/* Opera and W3C */
box-shadow: inset 0px 1px 3px rgba(0, 0, 0, .5);
Like I said… I haven’t read all the comments, but I thought it was worth noting. (all tested on Windows XP).
Greetz,
Wouter
I was bored so I created a jQuery plugin for this lol… it’s very basic but it executes in about 0.005ms as opposed to your 0.020ms. Every little helps as they say ;)
You just need to include the plugin file and then execute $(yourSelector).roundImg(radius) on DOM ready.
E.g: http://jsfiddle.net/JJenZz/3gYqj/
I included the unminified code at that URL too so that you can see how it’s built but you don’t need to save that in your plugin file :)
This is cool, thanks.
I hope it works with IE9
Great tuts. Nowadays everything can be settle with a CSS and jQuery
This is a quality article! I’ve been reading quite a few articles recently on CSS3 rounded corner implementations, and this is one of the best I’ve read. I’ll certainly be using this implementation in my work from now on.
Thanks for the great article.
Cheers,
Keith
Thank you, I have come across this several times lately. My fix have been similar but never with the use of jquery. Its a great idea.
hey dude
just a proposal… it might be better to hide the IMG tag by visibility:hidden; than opacity… so original space keeps reserved and visibility is much more browser compliant than opacity – even in very old ones.
good article thanks nick
cheers
Lovely post, i had been struggling to find something like this for quite a while. Thanks a lot for sharing. I am going to add it to my CSS aggregator site.
It’s work, but i’m a little bit disapointed because the need of css 3 :( Maybe can have more good use latter
Great trick; looking better even in Safari.
Why do you use the .load method / ajax function for this? You could use .wrap right after the img selector, like this:
$(“.rounded-img, .rounded-img2”).wrap(function(){
etc etc
Or is there any reason for using specifically the .load in this way?
Thanks so much for the code you gave us :)
Thanks, for a great post. I have learned so much from this (and your site) about CSS.
Thanks Again
Thanks…
Jquery is the best. I like it
Great idea. I implemented it and it really works and shows great look. Thanks
thanks for the tips, i tink IE is difficult browser
Thanks for the tutorial. It works great, even for me. Great site.
Thats really good that, although if it converts an image thats within a display:none div then the size comes back as 0x0, therefore not displaying properly.
Outside of that it works really well.
dude this is what i have been looking for . thanks man great work.
Nice, too bad it doesn’t work in ie.
IE is not worth the hassle! If people want a better experience on the web, then they will have to download better web browsers.
An interesting hack for creating the inset shadow that I’m using for the first time…
If the image is inside a containing element, use the :after pseudo class and create an empty element with an inset shadow without adding to your html markup:
CSS:
box-shadow: inset 0 0 10px rgb(0,0,0);
-webkit-box-shadow: inset 0 0 10px rgb(0,0,0); /* Safari, Chrome */
-moz-box-shadow: inset 0 0 10px rgb(0,0,0); /* Firefox */
-o-box-shadow: inset 0 0 10px rgb(0,0,0); /* Opera */
content: “”;
display: block;
height: 80px;
position: absolute;
left: 3px;
top: 0;
width: 80px;
z-index: 1;
Make this element the same size as your image and position it directly on top. Granted it is still a hack, but a touch of CSS added is better than a script!
Great post as always!
don’t work with iexplorer so I find it useless
Great tutorial and website! Keep up the good work.
Another excellent tutorial. I know this is possible to do but you started it Nick. Really awesome. Unfortunately, still the same thing happen, when will IE starts to support this great function? We don’t know that. Cross browser test not really performs well in IE. Thanks for the trick anyway. Nice to implement in my next blog.
Nice tutorial.
The biggest problem is that each browser runs on different rules. i noticed that you didnt bother talking about IE 6,7 or 8.
I think everyone knows how bad they are for web standards.
I didn’t give my images a class and selected it with regular CSS selector :
.element img { }
It didn’t work … I tried over and over till I figured I have to give the image a class to make it work.
Thanks a lot for this handy plugin
Nice, but sorry with IE its not working.
do’ no’ why but this website is absolutely pleasing to the eye :)
hmmm, I’m a little confused by the .load method
I’m trying to style images off a feed and I’ve found that if the css executes before the js has time to build the elements (ie on initial load) it doesn’t work. If I refresh…voila. If I navigate to another page and return using the back button, it breaks.
I changed .load to .wrap thanks to @Andre and it works. But why?
yes, well, if you want to buy crusher, pls visit the webpage:www.hammer-crushers.com, feel free to contact us:[email protected]
I’m pretty new to WordPress, and for the last few weeks have been trying to “reverse-engineer” on my own, many of the things I have seen in my travels, and also now see here on your site. I’m not quite sure how I ended up here (too much link hopping…) but your shadow corners method is something I’ve been looking for. Thanks!
Rick
th company is really very good, http://www.hammer-crushers.com, the product of it is very [email protected], MSN;[email protected]
Great info. The provided demo is very useful.
Gente, do que adianta se não funciona nos IE’s.
Vamos ser mais pé no chão.
it is worrying that po may be very heavy if you have many images, the idea is to use css border with rounded corners and for sure in the near future will be able to mask css ……. vlws
IE9 looks good too – go figure lol.
I have recently started using the blogengine.net and I having some problems here? in your blog you stated that we need to enable write permissions on the App_Data folder…unfortunately I don’t understand how to enable it.
i find jquery so hard. thanks for this! invaluable
Thanks to Darcy Clarke for generate jQuery code. From all types of shapes I like rounded shape the most because It looks like amazing and preety good design.
Los Angeles Web Design
Even in firefox, I can see that it displays correctly..
I just wanted to echo the comments of Neo and Andre – if you are noticing that your images aren’t displaying when the browser has cached them, the solution is as they describe – change the load function to wrap.
Doesn’t work in my IE8…stupid IE. Works in firefox though!
When you do article marketing, your intention is to increase the number of visitors to your website. It is not our abilities that show what we truly are, it is our choices. I have look for such a article for a long time,
I experienced a little bug with this method, on the sample. I am using Firefox 3.6.12, I looked at the sample at this link:
Then clicked back, back again to this article, at the end I clicked the sample link again for a closer look and then the image was not rounded, it overflown the border. After refreshing with CTRL+F5 it was working again. Just thought you might be interested. :)
Good stuff though, very good.
When you do article marketing, your intention is to increase the number of visitors to your website.ugg classic boots
It relies heavily on touch because the pages I have a user acting on, are usually a collection of child records. uggs outlet Caching is a big help in this respect.Thanks
As you can see the iPhone 3G has a problem getting a sharp focus on objects that are close to the lens. The photo is blurry and very grainy compare with white iphone 4
This post is a solution of a very practical problem. way of expression is also impressive
If you want to follow the fashion trend, you can never miss the hottest White iphone 4 Conversion Kit. With smooth and liquidity design, we sure White iphone 4 Conversion Kit is what you want.
That is to be expected in a long-term, high-risk project like ours. So, we turned to the blogging community for help – and got it! We have published our problems, and the community responded with results!cheap ugg boots
but how-come? i think you could’f done it just with CSS
??? have you tried: “overflow: hidden” (for the borders)
Where in my wordpress files should I place something like this? The style.css? Index.php?
This is really great–thanks for sharing! Though, I must say it’s really frustrating that we have to find tricks just so a cool effect is useable in multiple browsers in (almost) the same way. :[
Great trick, Nick. Good use of jQuery as an enhancement. Might clarify things a little to mention the additional css on the class that is not included inline.
Great tutorial this is something I’m definitely going to try this out as I am redesigning my blog theme. I looked into this previously but I was worried that round icons would cut peoples heads in half however all of the Gravitar icons on here look great!
Very cool effect :) I have been looking at implementing it on a site I am working on, especially to “neaten” images placed in certain articles, and on screen is looking good :) I found a snag though that I wanted to ask help or advice for… While testing my print stylesheets, I saw the images weren’t being displayed so you can print them (with the browser not printing backgrounds and the image set 0 opacity)…
Is there a way to correct this, possibly some javascript or JQuery that would run when the print option was chosen, to ‘undo’ the effect for the print version, so the images can print correctly?
Just an echo of other comments: if the rounded effect only shows after reload change .load to .wrap in the script.
Hi there,
great work. Just want to know if there is a solution for the print. My print preview doesn´t show the images.
Thanks.
age of heart attack decreased with each passing day, he said.
One question, how much browser are actually support this cool feature?
Hi, I’m new to css and here’s something that I can up with..
.round
{
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
width: 96px;
height: 96px;
overflow:hidden;
border:#000 1px solid;
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
works in firefox, don’t know about other browsers. Hope I have done it right, if not please let me know.
thanks.
CSS3 rounded corners can we increase the width of the design value. I want to get used, and this thought in reading posts!
why this is not working in IE browser !!! Can any one help me out…
hi.
some time i was looki’n for this every where but now i find it here, too late but tnx!
Hi, I love the look of these rounded corners. Thanks for sharing! I seem to be having an issue, however… gaps appear between the image and borders on the right and left of all images (in all browsers). I’m assuming my css is interfering. But I can’t figure out what’s causing the problem. I’d really appreciate if anyone has any suggestions! Cheers.
I found the issue… problem resolved! Some CSS code was adding padding to that a particular div. Thx again :)
That is because IE8 doesn’t support border-radius at all. It has nothing to do with the JS code.
Do yourself a favor trashing this crap and find a REAL browser. That is the only real solution, if you’re searching for a one!
IT’s not about us, it needs to work right in IE 8 Because so many of our clients website visitors are using it still. Around 40%. So ya, much as I don’t want to, I have to make sure the design works in IE6, 7, 8 and 9.
Thank you very much! While I cannot say it is THE perfect solution, since it won’t work with JS-disabled browsers, it’s still perfect when you cannot modify the HTML layout.
Not the best of advice, @Mamouneyya and switching browser is not the only solution. You could try CSS3PIE for support in IE8, I think it even goes down to IE6. So the IE users visiting your site will get to see your rounded corners.
Yes, @Mamouneyya, I wish people would stop saying “oh, just abandon ie, its crap” – in the real world, I just can’t tell my clients that, and expect to be paid.
@Rachaelov just put fixing IE as an extra on your estimates. This way you get to see how many clients are really interested in supporting it. You won’t waste time on each project and if the client goes for it you get paid.
There’s nothing wrong with holding onto the past, not until one tries to make others do the same. If you like IE, that’s great, but it’s not, and never has been, part of the wave of the future. The choice is up to the user to stick with a sewing machine that isn’t capable of making a zig-zag stitch, or acquiring one that is. It’s just not reasonable to expect for developers to find fixes for a straight stitch machine, and more and more developers are refusing to. Microsoft certainly has the resources to keep up with technology. That they refuse to is their black eye. I have no intention of allowing that to blacken mine.
I tried to implement this on my wordpress blog’s theme () and added the .js file to my /js folder in the theme folder and then added the jQuery code to my header.php file and changed the div class name to match the one I was trying to change: .avatar—the comment avatars, but it did not work. Any idea what I’m doing wrong? Is there some extra step I need to take in order for it to get to work on a WordPress theme? Any help would be greatly appreciated.
Hi,
I stumbled across this site and have to thank you alot for bringing this idea to my mind, I have used the “background trick” in the past, but this jquery really makes it easier to add extras in the future and will become a staple part of my designs now.
Many thanks
Jimmy
Hi! :)
(sorry for my bad english)
How can I put some text on the right of the images?
I tried with align=left on the image, but the text is always on the back.
It’s amazing looking back at this post and realizing how far advanced this post was in regards to CSS3 and browser support. Now most browsers support rounded corners on elements using the border-radius css attribute.
Instead of all that
its faster and easier to do it in simple css3 without having to change pictures to background or adding javascripts, the trick is to use overflow: hidden; and works on most browsers have not test it on opera but every other browser works; example
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-moz-box-shadow: 2px 2px 5px 0px #ccc,0px 1px 0px rgba(204,204,204,.3) inset;
-webkit-box-shadow: 2px 2px 5px 0px #ccc, 0px 1px 0px rgba(204,204,204,.3) inset;
box-shadow: 2px 2px 5px 0px #ccc,0px 1px 0px rgba(204,204,204,.3) inset;
margin:0px 5px 0px 0px;
overflow: hidden;
I just confirmed, Miguel, your method works on FF11, chrome, ie8 and (via ie tester) ie6,7. So does the jquery, but the css is probly better and wont have a flash of corners while the js loads.
Thanks for this article!
I started with your example, but I didn’t need the shadows. Plus, I also wanted to see if I could do this without creating a background image.
I ended up with a similar technique, but instead of wrapping a span around the image, I am putting the span before the image. The span contains a rounded edge box with a thick border that matches the page background color. Like your example, the span grabs the original images width and height.
At the end of the function (where the opacity setting was) it adds a border class to the image to match the span above (I found it didn’t look right if I didn’t do this). It seems to work in Firefox, Safari, Chrome, and IE9. I’m more of a visual designer and HTML/CSS guy, but hey, it worked for me.
Here’s my tweaked code:
$(document).ready(function(){
$(“.rounded-img”).load(function() {
$(this).before(function(){
return ”;
});
$(this).css({ border:”3px solid #FFF” });
});
});
Crap. The pasted code didn’t past correctly. Sorry about that.
Great tutorial there, But I want to know how to create something smiler to the images that appears on the commented post, Having people image in the circle box on the comment section.
Thanks
thanks for sharing code. i’ve applied it to gallery on my site.. nice one!!
I am glad to become a part of this post.Really nice work you did man.