iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To fit an image into a fixed-size box without changing its proportions, use object-fit: cover to fill the box and crop overflow, or object-fit: contain to show the whole image and leave space where needed. object-fit: fill—the default—matches both box dimensions, which can stretch or squash the image when the aspect ratios differ.
How the three sizing choices work
Let the source image measure Iw × Ih, and the element’s content box measure Bw × Bh. A ratio-preserving resize uses one scale factor for both dimensions. The choice of factor determines whether the image leaves empty space or extends beyond the box.
Contain: show the entire image
contain uses the smaller of the width and height scale factors: min(Bw/Iw, Bh/Ih). The image fits completely inside the box without changing its proportions. If the image and box have different aspect ratios, some of the box remains uncovered; its background shows through. The CSS Images specification defines this as the largest rectangle with the image’s natural ratio that does not exceed either box dimension (CSS Images Module Level 3).
Free tools Windows power users keep installed
One-click scans. No signup required.
Cover: fill the box and crop overflow
cover uses the larger scale factor: max(Bw/Iw, Bh/Ih). The image keeps its proportions and fills the box, but some of it extends beyond the box and is clipped. The specification describes the replaced content as maintaining its natural aspect ratio while filling the element’s content box (CSS Images Module Level 3).
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Fill: match both dimensions
fill sizes the image to the box’s width and height independently, using scale factors Bw/Iw and Bh/Ih. When those factors differ, the aspect ratio changes: circles can become ovals, and people or objects can look compressed or elongated. fill is the initial value of object-fit.
A worked example
Put a 1200 × 800 image in a 300 × 300 box. With contain, the image renders at 300 × 200, leaving 100 pixels of vertical space in total. With centered cover, it renders at 450 × 300, and 150 pixels of width are clipped in total. With fill, it renders at 300 × 300, distorting the image. These values follow directly from the scale factors; the centered crop assumes the default centered object position.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
Set up a fixed-ratio image frame
Give the frame a size or aspect ratio, make the image occupy that frame, and choose the fit behavior explicitly:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
.media-frame {
width: 18rem;
aspect-ratio: 4 / 3;
overflow: hidden;
}
.media-frame img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
This example makes a 4:3 frame and crops the image as needed to cover it. Change cover to contain to preserve every edge, or to fill to match the frame exactly even if that distorts the image. A background color on the frame can make the unused area from contain look intentional.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Choose based on what must remain visible
- Use
coverfor cards, thumbnails, or hero media when a full frame matters more than showing every edge. Check the crop at responsive sizes, especially for faces, text, logos, and other edge-sensitive content. - Use
containfor diagrams, product packshots, screenshots, or logos when the whole image must remain visible. Expect unused space if the image and frame ratios differ. - Use
fillonly when exact box dimensions outweigh natural proportions, or when the source and destination ratios already match.
The practical trade-off is between complete visibility, full frame coverage, and distortion. cover and contain preserve the ratio; only cover crops, while contain may leave space.
Control which part of the image appears
object-position moves the rendered image within its box. Its initial position is centered. For a portrait where the subject sits high in the frame, for example, try object-position: 50% 30%; right bottom is another valid position. With cover, positioning changes which area is sacrificed to the crop. With contain, it changes where the unused space falls. See the MDN object-fit reference for the property’s values and behavior.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Why width and height can distort an image
An image normally has intrinsic dimensions and an intrinsic aspect ratio. When only one dimension is set, the other can follow that ratio. If both width and height are set to values with a different ratio, the image may be stretched or squashed when it is filled into those dimensions. The aspect-ratio property expresses a preferred ratio, but it does not override two explicitly set dimensions. MDN explains this interaction in its guide to understanding and setting aspect ratios.
For a responsive image without a fixed crop frame, a common pattern is:
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
img {
max-width: 100%;
height: auto;
}
For a fixed-ratio card, define the frame and choose object-fit deliberately instead. Keep the image’s alt text appropriate to its purpose: cropping the visible image does not make meaningful content dispensable from its text alternative.
What object-fit changes—and what it does not
object-fit controls how replaced content such as an <img> or <video> is drawn inside the element’s content box. It does not set the element’s layout dimensions; those come from its used width and height. The property has no effect on <iframe>, <embed>, or <fencedframe>, according to MDN’s guide to replaced elements.
For a CSS background-image, use background-size: cover or background-size: contain for the analogous behavior. Also, object-fit: cover changes the rendered size and clips content within the element; it does not edit or crop the source file. Creating a smaller cropped asset is a separate image-processing or content-management step.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteOther object-fit values
Besides fill, contain, and cover, the property accepts none and scale-down. none leaves the content at its default or intrinsic sizing rather than resizing it to fit. scale-down behaves like whichever of none or contain produces the smaller concrete object size. These values are documented in the MDN reference.
Browser availability
MDN marks object-fit as Baseline Widely available and says it has been available across browsers since January 2020. Its reference page was last modified July 21, 2026. If your implementation depends on newer image features beyond the established object-fit values covered here, check support for those features in your target browsers.
Quick Recap
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.

