Resize an image without compressing it in CSS

You know how it is... That famous profile photo you want to display for your user with rounded corners, but which ends up becoming an obstacle course due to the dimensions of the original photo... Fortunately, thanks to CSS, it's very easy to resize an image without compressing it. Let's take a look!
•
Updated on August 14, 2026
•
3 min read
Believemy logo

You know what it is... That famous profile picture you want to display for your user with rounded corners, which is becoming a hassle due to the original photo's dimensions... Fortunately, thanks to CSS, it's very simple to resize an image without compressing it. Let's go through it together!

 

The Problem with Images

When we want to display an image, we must not forget that its original size can quickly become annoying: in portrait or landscape mode, when we want to display it in a square form, or even just resize it, it can quickly become difficult to handle in the long run...

Image

 

A Small Example

Here is an example representing a profile picture that becomes very compressed:

HTML
<p>Your profile picture</p>

<img src="https://image.freepik.com/free-photo/asian-women-traditional-japanese-kimonos-fushimi-inari-shrine-kyoto-japan_335224-245.jpg" alt="Japan" />
CSS
p {
  font-weight: bold;
  font-family: arial;
  font-size: 1.5rem;
}

img {
  width: 300px;
  height: 300px;
  border-radius: 50%;
}

The problem with this example is that the profile photo is reduced in width, and the image becomes very compressed to fit into the dimensions we specified with the CSS of the img tag:

  • width: 300px
  • height: 300px

 

The Miracle Solution

Fortunately, CSS allows us to resize an image without distorting its display, all thanks to the object-fit property.

This handy property can take all of these values:

  • fill - The image must respect the given dimensions, even if it gets distorted;
  • contain - The image must be contained within the given dimensions while maintaining its original ratio;
  • cover - The image must cover the given dimensions and adjust to leave no white space;
  • none - The image must respect the dimensions, but it is not resized: the original size is kept, and the image is simply cropped when it exceeds the specified width and height;
  • scale-down - This is almost like contain and none, except that this value chooses the smallest final rendered size (which means that if contain allows the image to be smaller than none, scale-down will choose to display the image as if you specified contain).

In all these possibilities, you guessed it... We need cover!

Its functionality is identical to the background-size: cover property you may have used before. The image will be represented to leave no gaps without being distorted.

So, we have the following code to make our example work perfectly:

CSS
p {
  font-weight: bold;
  font-family: arial;
  font-size: 1.5rem;
}

img {
  width: 300px;
  height: 300px;
  border-radius: 50%;
  object-fit: cover;
}

By simply adding the object-fit: cover property to all your images, you can resize them without compressing them. All that's left is for you to have fun with this property!

If you want to learn more, especially about HTML and CSS, we have a complete training dedicated to these two languages. Don't forget to share this article with your friends if you think they might need it—you'd be doing them a great service for their images!

Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Create hover text on image with CSS

We've already seen how to create an element that is displayed when the mouse hovers over an image, but in this article we'll show you how to display a whole host of information very fluidly by hovering the mouse over an element!

December 9, 2024

Create an image slideshow

Let's discover together how to create a simple and effective image slideshow using HTML, CSS and JavaScript!

December 6, 2024

Create an "architectural" design button using CSS

Creating a button where the borders split in two on hover may seem complicated, but nothing could be easier! Let's find out how in this article.

December 9, 2024

Create an animated gradient background on hover avec CSS

Whether it's to highlight a part of your website or a quote as in this example, generating and adding a gradient to the background can give your website a very modern touch. Find out in this article how to do it easily!

December 9, 2024

Generate images with Midjourney - the complete guide

Creating images with artificial intelligence: this has become the big trend of 2023. Whether for video, photos, text content or music. One of the most popular services is called Midjourney. So we've decided to put together a huge, packed guide to help you generate your own images too!

December 9, 2024

Creating a button with a "fill" effect using CSS

In this article, we'll be taking a look at the secret to achieving this "filling" effect on a button!

December 9, 2024

Create an animated "rainbow" button with CSS

In this article, we'll show you how to create a rainbow button that comes to life when the mouse hovers over it. A modern and sensational effect guaranteed!

December 9, 2024

Creating animated borders and rainbow blurs with CSS and JavaScript

Think again: it's not a shadow, it's a trick that will make your visitors think you've added borders and animated rainbow shadows! It's nothing of the sort: no borders or shadows are used in this tutorial. Let's discover the secret behind this trick.

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.