Set the background-size property on the element that has the background-image. For a full-bleed hero or panel, begin with background-size: cover; it fills the element while preserving the image’s proportions, so part of the image may be cropped. Use contain when every part of the image must remain visible, accepting possible empty space. Add background-position, background-repeat and a fallback background-color to control the result.
The basic CSS
Here is a complete hero example:
.hero {
min-height: 28rem;
background-image: url("hero.jpg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: #1d2430;
}
background-size changes the rendered size of a background image; it does not resize an ordinary inline <img>. Put the declaration on the same element that owns background-image. The initial value is auto auto, which uses the image’s intrinsic dimensions where available. See the MDN background-size reference.
The element must have a usable background area. A block with no height may collapse to the height of its content, making a background appear missing or unexpectedly small. Set a height, min-height, padding, or content-driven dimensions as appropriate.
Choose between cover and contain
cover: fill the whole area
cover scales the image proportionally until the entire background positioning area is covered. If the image and element have different aspect ratios, one axis extends beyond the area and is cropped. This is usually the right choice for banners, cards and hero sections where edge-to-edge coverage matters more than showing every pixel.
.hero {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
For example, a wide image in a tall mobile hero will lose some of its left and right edges. A tall image in a wide banner will lose some of its top and bottom. Cropping is expected behavior, not a loading failure.
contain: show the entire image
contain scales the image proportionally so all of it fits inside the area. The unused part of the element remains visible as the background color. Because backgrounds repeat by default, explicitly disable repetition when using contain unless tiling is intentional.
#1 Best Overall
- How to Custom: Customize backdrop with your images, text or Logo or any design. Grommets or Rod Pocket can also be customized. Please Click "Customize Now" to start, the higher the image clarity, the better the printing effect. After order, please pay attention to the message for confirmation.
- Size: Various sizes to choose from. Horizontal size, Square size, Vertical size. If you can not find the required size, please feel free to contact us for speical size customized.
- Material: Upgraded Polyester Fabric. BELECO Fabric Backdrop is very soft, not easy to fade, durable, and reusable. Can be ironed and washed, easy to care.
- Service: If you need any help for the custom backdrop or have any design ideas, please feel free to send messages to contact us.
- Wide Application: Both Indoor and Outdoor use. For Party, Festival, Holiday, School Activities, Club, Church, Business, Video Recording, Zoom Meetings, etc. Home or Office Wall Decoration. Best Gift for Friends or Family Members.
.product-panel {
background-color: #f3f5f7;
background-image: url("product.png");
background-size: contain;
background-position: center;
background-repeat: no-repeat;
}
This option suits logos, diagrams and product artwork that cannot be cropped. The MDN guide to resizing background images documents the practical difference between the two keywords.
Quick decision table
| Requirement | Value | Result and trade-off |
|---|---|---|
| Fill the element edge to edge | cover |
Preserves the ratio and crops one axis when ratios differ. |
| Keep every part of the image visible | contain |
Preserves the ratio but can leave empty bands; use no-repeat. |
| Set a rendered width while preserving ratio | 300px or 50% |
The other dimension is calculated as auto. |
| Set both rendered dimensions | 300px 200px |
Both dimensions are forced, so the image can distort. |
Use lengths, percentages and auto
You may provide one or two size values:
background-size: 300px;sets the width to 300 pixels and calculates the height automatically.background-size: 50%;sets the width to half of the relevant background positioning area and calculates the height automatically.background-size: 300px 200px;sets width and height explicitly. Use this only when distortion is acceptable or the dimensions match the source ratio.background-size: auto 240px;calculates the width from the image ratio while fixing the height.background-size: 100% auto;makes the image as wide as the positioning area and preserves its ratio.
A single value is interpreted as width, with height treated as auto. With two values, the first is width and the second is height. Lengths can be absolute units such as px or relative units such as rem; percentages are also valid.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11How percentage sizing is calculated
A percentage is relative to the background positioning area, normally the element’s padding box because that is the default background-origin. It is not automatically relative to the viewport. If you change background-origin, the reference area changes. With background-attachment: fixed, the reference area for percentage sizing is the viewport.
.banner {
background-image: url("banner.jpg");
background-size: 100% auto;
background-origin: padding-box;
}
If a percentage looks unexpectedly large or small, inspect the element’s box dimensions and its background-origin and attachment settings.
Control cropping and placement
Move the focal point with background-position
When cover crops a subject, reposition the image instead of stretching it:
Rank #2
- Lightweight Physical board - Not a roll up or rollout - Moisture & Stain Resistant
- Measures 19.5 x 19.5 Inches - this is a small square backdrop
- Rounded corners for easy storage and protection.
- These backdrops are shipped with the printed side down. Remove from the cardboard and flip over to reveal the printed side.
- Your white balance settings in your camera or editing process will help achieve a natural color hue
.hero {
background-size: cover;
background-position: 70% center;
}
Common values include center, top, bottom, left and right. You can combine keywords or use percentages, such as 20% 40%. Choose a position that keeps a face, product or headline-safe region inside the visible crop at the smallest supported viewport.
Stop accidental tiling
Background images repeat in both directions by default. Set background-repeat: no-repeat for a single image. Other valid patterns include repeat-x, repeat-y and space or round for specialized textures.
Provide a color fallback
The background color remains visible wherever the image does not cover the area and behind transparent pixels. It also provides a useful fallback while an image loads:
.hero {
background-color: #202838;
background-image: url("hero.webp");
background-size: cover;
}
Responsive background-size patterns
Full-width hero
.hero {
min-height: clamp(18rem, 60vw, 42rem);
background: #18202b url("hero.jpg") center / cover no-repeat;
}
The shorthand places the color, image, position, size and repeat in one declaration. The slash separates background-position from background-size. Keep a minimum height so the hero does not collapse on narrow screens.
Image that spans a content column
.article-header {
background-image: url("header.jpg");
background-size: 100% auto;
background-position: top center;
background-repeat: no-repeat;
padding-block: 12rem 3rem;
}
This preserves the image ratio while the padding supplies enough vertical space for the visible artwork and text.
Rank #3
- Pliable & Bendable, but store flat - Moisture & Stain Resistant
- Measures 2 feet x 3 feet or 24 inches x 36 inches
- Great for food & product photography, videos, social media images, and website photos
- Be sure to match up the natural shadows in the backdrop with your lighting set-up for a more realistic look in your photos.
- Rounded corners for easy storage and protection
Different positioning on small screens
.hero {
min-height: 32rem;
background: url("wide.jpg") 65% center / cover no-repeat;
}
@media (max-width: 600px) {
.hero {
min-height: 24rem;
background-position: 35% center;
}
}
Changing position is often better than using a distorted image. If mobile and desktop compositions are fundamentally different, use separate images with media queries or a responsive image strategy rather than forcing one crop to do both jobs.
Background images versus <img>
Use a background when the image is decorative, sits behind content, or should be cropped as part of a visual treatment. Use an <img> when the image is content that needs alternative text, intrinsic dimensions, captions, semantic meaning or independent loading behavior. background-size cannot resize an inline <img>; use CSS such as object-fit: cover or object-fit: contain for that element instead.
.card img {
width: 100%;
height: 14rem;
object-fit: cover;
object-position: center;
}
Do not hide important text or information solely inside a background image. Ensure foreground text remains readable against the chosen image and fallback color.
Layering multiple backgrounds
You can combine a gradient overlay and an image. The first layer is painted on top of later layers, so put the gradient first:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
.hero {
background-image:
linear-gradient(rgba(0, 0, 0, .45), rgba(0, 0, 0, .45)),
url("hero.jpg");
background-size: cover, cover;
background-position: center, center;
background-repeat: no-repeat, no-repeat;
}
Each layer receives a corresponding value. A single cover can be reused for both layers, but writing both values makes the pairing explicit. A gradient improves contrast without editing the source image.
Rank #4
- How to Custom: Customize backdrop with your images, text or Logo or any design. Grommets or Rod Pocket can also be customized. Please Click "Customize Now" to start, the higher the image clarity, the better the printing effect. After order, please pay attention to the message for confirmation.
- Size: Various sizes to choose from. Horizontal size, Square size, Vertical size. If you can not find the required size, please feel free to contact us for speical size customized.
- Material: Upgraded Polyester Fabric. BELECO Fabric Backdrop is very soft, not easy to fade, durable, and reusable. Can be ironed and washed, easy to care.
- Service: If you need any help for the custom backdrop or have any design ideas, please feel free to send messages to contact us.
- Wide Application: Both Indoor and Outdoor use. For Party, Festival, Holiday, School Activities, Club, Church, Business, Video Recording, Zoom Meetings, etc. Home or Office Wall Decoration. Best Gift for Friends or Family Members.
Debugging checklist
The image is not visible
- Verify that
background-imageis on the same element asbackground-size. - Inspect the image URL in the browser’s network panel. Check spelling, case, relative-path location and server permissions.
- Give the element a height,
min-heightor padding if it has no visible content height. - Check that another rule, shorthand declaration or pseudo-element is not overriding the background.
- Temporarily set a contrasting
background-colorto distinguish an unloaded image from a transparent image.
contain is tiled
Add background-repeat: no-repeat. Repetition is the default behavior and is independent of the contain scaling choice.
cover cuts off the subject
Adjust background-position, reduce the element’s extreme aspect ratio, choose a differently composed source image, or switch to contain if preserving the entire image is more important than filling the area.
A percentage has the wrong apparent size
Measure the element rather than the viewport. Review padding, background-origin and whether background-attachment: fixed changes the reference area to the viewport.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →The image looks stretched
Check for two explicit dimensions such as 300px 200px. Replace them with cover, contain, or one dimension plus auto to preserve the source ratio.
Performance, quality and accessibility considerations
- Serve an appropriately sized, compressed image.
background-size: coverchanges display scaling, not the downloaded file size. - Use modern formats where your delivery setup supports them, and avoid multi-megapixel backgrounds when a smaller source is visually sufficient.
- Keep text and controls in HTML so they remain selectable, responsive and accessible.
- Check crops at narrow, wide, short and tall viewport sizes. A centered desktop crop can remove the subject on a phone.
- Set a background color that maintains acceptable contrast while the image loads and in areas exposed by
contain. - If a background is purely decorative, do not add redundant alternative text. If the visual conveys essential information, use semantic HTML instead.
Or skip the browser setup
If you need a rendered screenshot of the result rather than a manual browser check, ScreenshotNeo returns a PNG, JPEG, WebP or PDF from one request. It accepts cookie and consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers.
For the API parameters, options and response details, see the ScreenshotNeo documentation. Replace the example URL with your page.
cURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
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)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo also provides full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets and custom viewports, retina scale, PDF paper and page controls, custom CSS and JavaScript, clicks, selector or network-idle waits, ad/tracker/request blocking, custom headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, configurable-TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API and an OpenAPI specification. Parameters used by other screenshot APIs are accepted to ease migration. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.
The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; Growth is $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000 and Business $249 for 1,000,000. Yearly billing gives two months free, and every feature is included on every plan. Create a free ScreenshotNeo account to try it without a card.
Frequently asked questions
Frequently Asked Questions
Can I use background-size with a CSS gradient?
Yes. Gradients and images are background layers; give each layer its own size, position and repeat value when their settings differ.
Does cover change the original image file?
No. It only changes how the browser paints the image inside the element. The downloaded source file remains unchanged.
Why does my background look different after the browser window resizes?
The element’s aspect ratio changes, so proportional scaling and cropping change. Test representative viewport sizes and adjust the position or source composition.
Recommended Free Tools
What is the default background repetition?
Backgrounds repeat by default. Use background-repeat: no-repeat when you want one non-tiled image.
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.

