How to Resize Background Images for Any Screen
The Challenge of Background Image Adaptation
Background images must display correctly on an enormously diverse range of screens: from 320px-wide older phones to 2560px-wide 4K monitors, from landscape desktop browsers to portrait mobile screens, from standard-DPI screens to Retina high-DPI screens. Providing only one fixed-size image can mean very different results across devices.
There are two approaches to solving this: preparing the correct original image size (typically a wide enough landscape image), and using the correct CSS background-size property to control display behavior. Combining both is needed for optimal results across all devices.
Recommended Original Dimensions for Background Images
- Full-screen background: 1920ร1080px (minimum) to 2560ร1440px (for 2K screens). WebP format, under 300KB
- Section background: 1920px wide; height per design; can be slightly smaller than full-screen
- Card background: 400ร250px is typically sufficient; at least 1.5ร the display size
- Mobile-specific background: If loaded separately via media queries, 720ร1280px or 750ร1334px (iPhone 8 resolution)
Key rule: the actual pixel width of a background image should be at least 1ร the maximum display width (for non-Retina screens) or 2ร (for Retina screens). Providing a 2560px-wide image safely covers most users' screen needs.
CSS background-size Property Explained
CSS's background-size property controls how a background image displays in its container. Key values:
- cover: Scales the image to completely cover the container, potentially cropping content. Most common for full-screen backgrounds to ensure no empty areas.
- contain: Scales the image to fit completely within the container, potentially leaving empty areas (filled with repeat or background color). Best when cropping is unacceptable.
- 100% auto: Width fills the container, height scales proportionally. May leave vertical whitespace.
- auto 100%: Height fills the container, width scales proportionally. May leave horizontal whitespace.
- Specific pixels or percentages: e.g.,
800px 400pxor50% 50%, specifying exact background image dimensions.
Complete CSS for Full-Screen Background Images
For a full-screen background that doesn't distort, has no gaps, and displays correctly on all screen sizes, use this recommended CSS:
.hero-section {
background-image: url('background.webp');
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed; /* Parallax effect (disable on mobile) */
min-height: 100vh;
}
background-position: center center ensures the center of the image is preserved when cropping; background-repeat: no-repeat prevents the image from tiling at the edges; background-attachment: fixed creates a parallax scrolling effect, but performs poorly on mobile โ disable it on mobile via media queries.
Mobile Background Image Optimization
Mobile screens are typically portrait-oriented while most background images are landscape. With background-size: cover, a landscape background gets significantly cropped on a portrait phone screen, potentially covering key content.
Solution: use media queries to provide a portrait-optimized background image specifically for mobile, or adjust background-position to ensure key content areas aren't cropped:
/* Desktop: landscape background */
.hero { background-image: url('bg-desktop.webp'); }
/* Mobile: portrait background */
@media (max-width: 768px) {
.hero {
background-image: url('bg-mobile.webp');
background-position: top center;
}
}
How to Resize Background Images to Avoid Key Content Cutoff
When resizing background images, you need to anticipate the crop areas on different screens. With background-size: cover, cropping starts from the sides (wide screens) or top/bottom (narrow screens), preserving the center by default.
If the background image has specific key content (text, logo), place it in the center of the image (the safe zone) to ensure it's visible at all screen ratios. Before resizing, use a crop tool to simulate different ratio displays and confirm key content remains visible under all cropping scenarios.
Performance: Avoiding Background Images as a Bottleneck
Background images are an important factor in page load speed. Best practices: use WebP format (30% smaller than JPG); lazy-load non-critical background images (use JavaScript to dynamically set background URLs when elements enter the viewport); provide multiple resolution versions loaded via media queries; use <link rel="preload"> for hero background images to preload early and improve LCP.
Important note: background images declared in CSS are not picked up by the browser's preload scanner โ they load later than <img> tags. If a background image is the page's LCP element, strongly consider switching to an <img> tag with absolute positioning to achieve the visual background effect, allowing the browser's preload optimization to apply.
Try the free tool now
Use Free Tool โ