Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

How to Resize Images with CSS Without Distortion

Learn when to use max-width, height, aspect-ratio, object-fit, and object-position to resize images responsively without unwanted distortion.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a responsive image that shrinks to fit its container without growing beyond its natural width, use max-width: 100%; height: auto;. The automatic height preserves the image’s aspect ratio. If you need every thumbnail to fill a set-size frame, use object-fit: cover instead and choose where the crop falls.

Make an image responsive without stretching it

Apply a maximum width of 100% and let the height remain automatic:

As an Amazon Associate I earn from qualifying purchases.

img {
  max-width: 100%;
  height: auto;
}

This lets an image shrink when it is wider than its available space while preserving its natural proportions. It does not enlarge a smaller image to fill a wider container. A logical-properties equivalent is max-inline-size: 100%; block-size: auto;.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To apply this only to a particular group of images, use a class instead of styling every image:

.responsive-image {
  max-width: 100%;
  height: auto;
}
<img class="responsive-image" src="photo.jpg" alt="Description of the image">

Choose between scaling, cropping, and empty space

First decide whether the whole image must stay visible and whether the layout needs a consistent frame. If the image should simply fit the available width, the responsive rule above is usually enough. For a box with defined dimensions or a preferred ratio, choose how its contents should fit:

CSS choice What happens Use it when
object-fit: cover Fills the image box while preserving proportions; parts that do not fit are cropped. You need a filled, consistent frame and cropping is acceptable.
object-fit: contain Shows the complete image at its natural proportions; unused space may remain in the box. Every part of the image must remain visible.
object-fit: fill Fills the box, potentially changing the image’s proportions. Distortion is acceptable for the particular content; it is usually unsuitable for photographs or illustrations.
object-fit: none Leaves the image content unresized. You specifically want the object to remain at its intrinsic size.
object-fit: scale-down Uses whichever is smaller: the result of none or contain. You want to avoid enlarging the object while allowing it to shrink to fit.

Crop images to a consistent frame

Set the box dimensions or a preferred aspect ratio, then use object-fit to control how the image sits inside it. For a full-width landscape thumbnail:

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
.thumbnail {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  object-position: center;
}

object-position controls which area remains visible in a crop. For example, use object-position: top center; when the important subject is near the top. With cover, some content outside the frame will be clipped. Replace it with contain if the complete image must be visible, and allow for empty space around it.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An aspect-ratio sets a preferred shape for the box. At least one box dimension needs to remain automatic for that preferred ratio to affect sizing. Pair a chosen box ratio with object-fit so the image content is not stretched to match the frame.

Reserve space before an image loads

When the image’s intrinsic dimensions are known, include its width and height attributes in the HTML. The browser can use those values to calculate the aspect ratio before the image finishes loading. Responsive CSS can still change its rendered size while the ratio information helps establish the space it needs.

<img
  src="photo.jpg"
  alt="Description of the image"
  width="1200"
  height="800"
  class="responsive-image"
>

The attribute values should describe the image’s actual intrinsic dimensions, not the desired CSS display size.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Common problems and fixes

  • The image overflows its container: Apply max-width: 100% to the image and check that another CSS rule is not overriding it.
  • The image looks stretched: Avoid forcing both rendered dimensions to values that conflict with the image’s natural ratio. Use an automatic second dimension for natural scaling, or use a frame with object-fit: cover or contain.
  • The whole subject does not fit in a thumbnail: cover crops by design. Change to contain to show the full image, or adjust object-position to shift the visible crop.
  • There is blank space in the frame: That can be expected with contain, which prioritizes showing the whole image. Use cover if filling the frame matters more than preserving every edge.
  • An image is unexpectedly enlarged or not enlarged: max-width: 100% prevents overflow but does not enlarge a naturally smaller image. Set an explicit width if enlargement is intentional, and retain an automatic height to preserve proportions.

Or skip the browser setup

If you need a screenshot of a webpage rather than CSS for images in your own page, ScreenshotNeo provides a website screenshot API and MCP server. A single request can return an image or PDF; its capture options include resizing images. See the ScreenshotNeo documentation for the API parameters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for 1,000 free screenshots a month—no card required.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does max-width: 100% enlarge a small image?

No. It limits the image’s width to its available space; it does not by itself scale a smaller image up.

Can I preserve the whole image and still fill a fixed-ratio frame?

Not when the image and frame have different ratios without either cropping, leaving unused space, or distorting the image. Choose cover, contain, or a matching frame ratio based on which trade-off is acceptable.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.