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

Use fit (usually CSS object-fit: contain) when every part of an image must remain visible. Use fill (usually object-fit: cover or a platform’s equivalent) when the image must occupy a fixed frame and controlled cropping is acceptable. Do not assume that an option literally named fill means “cover”: CSS object-fit: fill stretches an image and can distort it.

The right choice depends on the platform, the source and container aspect ratios, and whether missing pixels or empty space is the bigger problem. This guide explains the distinction in CSS, SwiftUI and image-transformation services, then gives practical patterns, responsive examples and troubleshooting steps.

Fit and fill are priorities, not universal standards

“Fit” normally prioritizes seeing the complete source. The software scales the image proportionally until it fits within the available box. If the shapes do not share an aspect ratio, unused space appears on two sides.

“Fill” normally prioritizes a completely occupied frame. The image is scaled until both dimensions cover the box; excess content is clipped, allowed to extend outside the view, or handled according to that platform’s rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

These labels are not interchangeable across APIs. Before implementing a design, identify the platform and read its definition. CSS, SwiftUI and a server-side image service can expose similarly named choices with different overflow and cropping behavior.

Priority Typical choice What you see when ratios differ Main risk
Keep all source content Fit / contain Letterboxing or pillarboxing (empty bands) The frame may look unfinished
Occupy every pixel of a fixed frame Fill / cover Cropped edges or overflow Important details can disappear
Force dimensions exactly CSS fill or equivalent stretch mode No empty space; entire image is resized to the box Distortion when aspect ratios differ

CSS: contain, cover and fill are three different behaviors

CSS’s object-fit property controls how replaced content such as an <img> is resized inside its used width and height. The CSS Images specification and MDN document five values: contain, cover, fill, none and scale-down.

object-fit: contain — the fit choice

contain preserves the natural aspect ratio and scales the complete image to fit inside the content box. If the box is wider or taller than the image, the remaining area is empty. Set the container’s background color when you want those bands to look intentional.

.diagram {
  width: 100%;
  height: 320px;
  object-fit: contain;
  background: #f3f4f6;
}

Use it for diagrams, screenshots, logos, product details, maps and any visual where losing an edge changes the meaning.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

object-fit: cover — the usual cover/fill choice

cover preserves aspect ratio while filling the entire content box. When ratios differ, the image is clipped. MDN summarizes the rule: “If the object’s aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit.”

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
.card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  object-position: center;
}

Use it for card thumbnails, avatars, hero imagery and decorative tiles where a uniform grid matters more than showing every edge. Choose the crop deliberately rather than assuming the center is safe.

object-fit: fill — literal stretching

CSS fill sizes the replaced content to the content box without preserving its aspect ratio. A square box can turn a landscape photograph into a visibly narrow or wide image. This is rarely appropriate for photographs, faces, logos or screenshots, but can be valid for deliberately deformable artwork.

The other CSS values

  • none does not resize the content; the natural dimensions can overflow or leave unused space.
  • scale-down chooses the smaller concrete size produced by none or contain, so a small source is not enlarged unnecessarily.

Positioning and clipping a cover image

object-position determines which part remains visible when cover crops. Percentages, lengths and keywords such as top, center and right are supported.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.portrait img {
  width: 100%;
  height: 360px;
  object-fit: cover;
  object-position: 50% 20%; /* keep a face near the top visible */
}

If the image extends beyond a wrapper or you use a background-based technique, add overflow: hidden to the element that defines the visible boundary. Test narrow screens and unusually wide images: a focal point that works on desktop may be cut off on mobile.

Responsive patterns that avoid surprises

Keep a complete image at every width

.report-preview {
  aspect-ratio: 16 / 9;
  background: #111827;
}
.report-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

The explicit aspect ratio creates a predictable frame; contain ensures the full report remains readable.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Use cover only where cropping is acceptable

.news-grid img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center;
}

Keep the source’s focal subject away from edges, or provide a per-image position such as object-position: 70% 50%.

Switch modes at a breakpoint

Tailwind CSS maps object-contain, object-cover and object-fill directly to the corresponding CSS declarations. Its responsive utilities let a design change mode when the frame changes shape:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<img class="w-full h-64 object-contain md:object-cover" src="photo.jpg" alt="...">

That example keeps the complete image on small screens and uses a consistent cropped card on medium screens. Verify that the breakpoint matches your actual content, not just a device category.

SwiftUI: fit can leave space, fill can extend beyond the view

SwiftUI calls the choices ContentMode.fit and ContentMode.fill. Fit scales an image to fit along one axis and can leave empty space along the other. Fill covers the view, and part of the image may extend beyond the view’s bounds. Clip it when the filled content must not paint outside the frame.

Image("product")
    .resizable()
    .aspectRatio(contentMode: .fit)
    .frame(width: 220, height: 160)

Image("hero")
    .resizable()
    .aspectRatio(contentMode: .fill)
    .frame(width: 220, height: 160)
    .clipped()

Use fit for a complete product or document. Use fill for a fixed hero slot, then add .clipped() and adjust the composition if the default crop hides the subject.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Server-side transformations are their own vocabulary

Image transformation services may offer options such as scale-down, contain and cover, but their resizing, padding, crop anchor and overflow rules are service-specific. Do not copy a CSS value into a URL transformation and assume identical output. Confirm the service’s definition, then inspect representative wide, tall and small sources.

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

A decision checklist

  1. Identify non-negotiable content. If a label, face, edge or diagram detail must survive, start with fit/contain.
  2. Measure the frame. Compare source and box aspect ratios at every important breakpoint.
  3. Choose the failure you can tolerate. Empty bands are preferable to missing information; cropping is preferable to uneven cards only when the subject remains clear.
  4. Preserve aspect ratio unless distortion is intentional. In CSS, choose contain or cover, not fill, for normal photos.
  5. Set the focal position. Use object-position or the platform’s equivalent for cover crops.
  6. Test extremes. Try a panoramic image, a portrait, a tiny image and a source with important content at each edge.
  7. Check accessibility. Keep meaningful text in HTML or a caption; do not rely on a crop to communicate information.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common results

“My image has bars around it.”

You selected a fit/contain mode and the aspect ratios differ. Keep the bars for complete content, change the frame ratio, or switch to cover only after confirming that cropping is safe. A background color can make the bands intentional.

“The subject’s head or logo is cut off.”

You are probably using cover/fill with a centered crop. Change object-position, provide a focal point per asset, or use contain for that image.

“The image looks stretched.”

In CSS, check for object-fit: fill or for width and height applied without a fitting rule. Replace it with contain or cover and ensure the image is replaced content inside a box with explicit dimensions.

“The image spills outside its SwiftUI frame.”

ContentMode.fill can extend beyond the view. Add .clipped(), or use fit when overflow and cropping are unacceptable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

“Different services produce different crops.”

That is expected when the platforms define anchors, padding or overflow differently. Record the service’s exact option, test the same source and dimensions, and do not treat a similarly named option as a compatibility guarantee.

Capture examples without building a browser pipeline

If you need screenshots to verify these modes across breakpoints, you can automate a real browser yourself, but cookie dialogs, newsletter popups, chat widgets, bot checks and failed loads add setup and operational cases. ScreenshotNeo provides a single HTTP endpoint for PNG, JPEG, WebP or PDF captures, with controls for full-page or element capture, device and viewport presets, retina scale, dark mode, custom CSS and JavaScript, click actions, waits, request blocking, headers, cookies, user agents, timezone, geolocation, transparent backgrounds, resizing, caching, signed links, asynchronous webhooks, bulk capture and usage reporting. Every feature is available on every plan.

Or skip the browser setup

Call the API with a URL; the complete parameter reference is in the ScreenshotNeo documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Before capture, ScreenshotNeo accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server lets Claude, Cursor or another MCP client use take_screenshot, get_page_info and capture_pdf. The Free plan includes 1,000 shots each month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

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

Performance, reliability and cost considerations

  • Browser layout: cover and contain are generally layout decisions; the expensive work is loading and decoding the source. Supply appropriately sized images and avoid enlarging tiny files.
  • Visual consistency: fixed aspect-ratio boxes and explicit object positioning reduce layout shifts and unpredictable crops.
  • Automation: wait for a selector, a delay or network idle when images are lazy-loaded. Use caching with a TTL when repeated captures do not need a fresh render.
  • Failure handling: inspect ScreenshotNeo’s X-Page-Verdict and X-Billed headers so your pipeline can distinguish a clean billed shot from a bot check, blank page, timeout, failed load or cache hit.
  • Volume: bulk capture supports up to 100 URLs per call; asynchronous jobs with signed webhooks help move long captures out of a request timeout.

Frequently Asked Questions

Does fit always mean no cropping?

No. It is a common convention, not a universal API contract. Check the platform’s definition; in CSS, contain keeps the complete image visible.

Can I use cover for an important diagram?

Only if you control the crop and have verified that no labels or edges are removed. Otherwise use contain or change the frame ratio.

What is the CSS difference between fill and cover?

Cover preserves aspect ratio and clips excess content. CSS fill resizes to the box even when that distorts the aspect ratio.

Why does a small image look blurry with cover?

Cover may enlarge it to fill the frame. Use a sufficiently large source, or choose scale-down/contain when enlargement is undesirable.

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

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.