How to Crop an Image into a Circle with a Border Using CSS
To show an image as a circle with a border around it, as with a profile icon, set the img width and height to the same value, then add object-fit: cover and border-radius: 50%. A border follows the circle. Whether the original image is wide or tall, the center is cut out as a circle without distortion.
The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I opened an HTML and CSS page with Playwright, took screenshots, and read the color one pixel at a time from the center of the image outward to confirm what was drawn where. I have not tested Firefox or Safari.
For the test, I used a 300×200 wide image like the one below. It has a green circle in the middle and 40px-wide blue bands at the left and right edges.

- 1. Full code
- 2. If width and height don't match, it becomes an ellipse
- 3. Without object-fit, the image is squeezed and distorted
- 4. Cutting with clip-path also cuts the border
- 5. Preventing the box from growing by the border width
- 6. Leaving a gap between the border and the image
- 7. Gradient borders are made with the parent element's background
- 8. Supported browsers
Full code
The HTML is just a normal img element with a class added.
<img class="avatar" src="photo.png" alt="">
The CSS is as follows.
.avatar {
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
border: 4px solid #00c8e8;
}
width and height make the box that displays the image a square. object-fit: cover keeps the image's aspect ratio, fills the whole box, and cuts off the parts that overflow. border-radius: 50% rounds the corners of the square into a circle, and the border is drawn along that circle.
When I measured the image displayed with this CSS, the box including the border was 128×128. Moving outward from the center to the left, up, or up-left, the pixels were green from 0 to 36px, sand-colored from 37 to 60px, and light blue border from 61 to 64px. Beyond that was the white background. The green circle had a radius of 36px, which is the original 60px scaled by 0.6 to match the image height. The blue bands that were at the left and right of the original image did not appear in any direction. They were cut off as the part that extended sideways.
Without border-radius, in the up-left direction the border was at 85 to 90px from the center. With border-radius: 50%, the border that had reached the square's corners moved to the same 61 to 64px position as in the other directions, forming a circle.
If width and height don't match, it becomes an ellipse
If you set only width and not height, the height is determined by the image's aspect ratio. Applying width: 120px and border-radius: 50% to a 300×200 image alone made the box 120×80. It did not become a circle but a wide ellipse, and the blue bands on the left and right were still visible.
For percentage values of border-radius, the horizontal radius is a percentage of the box width, and the vertical radius is a percentage of the box height. For a 120×80 box, 50% gives a horizontal radius of 60px and a vertical radius of 40px. To get a true circle, set width and height to the same value.
Without object-fit, the image is squeezed and distorted
Even with width and height equal, if you leave out object-fit, the default fill applies. fill stretches the image to fill the box, changing its aspect ratio if needed.
Removing object-fit and using 120×120 gave a tall ellipse for the green circle, 24px to the left and 36px up from the center. The image width was reduced from 300px to 120px (0.4 times) and the height from 200px to 120px (0.6 times), so the horizontal direction was squeezed more. The blue bands on the left and right remained at 45 to 60px from the center.
Cutting with clip-path also cuts the border
If you round the image with clip-path: circle(50%) instead of border-radius, the border is not drawn as a circle. When I measured, there was a light blue border at 61 to 64px to the left and up, but no border in the up-left direction. As described in the clip-path documentation, the reference box for the shape, if not specified, is the box bounded by the outer edge of the border. That box is clipped into a circle, so the border remains only at four spots: top, bottom, left, and right. When adding a border, round it with border-radius.
Preventing the box from growing by the border width
When I added border: 4px to width: 120px, the displayed size was 128×128. This is because with the default box-sizing of content-box, the border width is not included in width and height (see the box-sizing documentation).
To keep the total including the border at 120×120, add box-sizing: border-box.
.avatar {
box-sizing: border-box;
}
With box-sizing: border-box, the box became 120×120, and the border was at 57 to 60px from the center. As a result, the image area inside the border shrank to 112×112.
Leaving a gap between the border and the image
I tried two ways to leave a gap between the border and the image. They are the upper-right and lower-left in the image below.

The first way is to use outline instead of border. You can move the frame away from the image with outline-offset.
.avatar {
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
outline: 4px solid #00c8e8;
outline-offset: 4px;
}
Measuring to the left from the center, 61 to 64px was the gap and 65 to 68px was the light blue outline. In the up-left direction the outline was at the same distance, and the outline also followed the circle of border-radius. Nothing is drawn in the gap, so the background behind it shows through. With a white background it was white, and when I set the background to a pale light blue (#eefafd), the gap was pale light blue. The box stayed at 120×120. As stated in the outline documentation, outline takes no space, so the layout of surrounding elements does not change.
The second way is to layer a box-shadow with no blur outside a white border.
.avatar {
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
border: 4px solid #fff;
box-shadow: 0 0 0 4px #00c8e8;
}
The fourth value of box-shadow is the spread distance. With no offset and no blur, and a spread of only 4px, a 4px-thick line is created on the outside. As with outline, the measurement showed white from 61 to 64px and light blue from 65 to 68px. The box is 128×128, including the white border. The gap here is the color of the border, so it stayed white even on a page with a pale light blue background.
When only box-shadow is added without a border, a light blue line appears at 61 to 64px, and the box stays at 120×120. You get a frame that looks like a border without taking up the space of the border.
Gradient borders are made with the parent element's background
To make the border color a gradient, wrap the img in a span or similar element and apply the gradient to the parent's background. If you add padding to the parent and round it, the background in the padding area appears as the border.
<span class="ring"><img src="photo.png" alt=""></span>
.ring {
display: inline-block;
padding: 4px;
border-radius: 50%;
background: linear-gradient(135deg, #00c8e8, #d85878);
}
.ring img {
display: block;
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
border: 4px solid #fff;
}
The white border on the img becomes the gap between the image and the gradient. With this CSS, the parent element measured 136×136, and there were 4px margins above and below the image.
If you forget display: block on .ring img, the parent element becomes 136×141. The space above the image is 4px and the space below is 9px. By default, img is an element placed in the same line as text (display: inline), and the default value of vertical-align is baseline. I placed a zero-height element inside the parent to measure the baseline position. The bottom edge of the image and the baseline were at the same position, and the bottom edge of the parent was 9px below that. The 5px left after removing the 4px padding is the leftover space below the baseline.
When vertical-align: top is used instead of display: block, the parent is also 136×136, with 4px margins above and below.
If this extra space remains, the image shifts upward from the center of the parent. Because border-radius: 50% is a percentage of each of the width and height, a 136×141 parent is not a perfect circle but a slightly tall ellipse.
Supported browsers
According to MDN's compatibility data (@mdn/browser-compat-data 8.1.8), border-radius is supported from Chrome 4, Edge 12, Firefox 4, and Safari 5 (Safari on iOS from 4.2). object-fit is supported from Chrome 32, Edge 79, Firefox 36, and Safari 10 (Safari on iOS also from 10).





