Use CSS background-image for decorative images, size it with cover when the element should be filled, and supply responsive image variants instead of sending one oversized file to every device. If the image conveys information, use an HTML <img> or <picture> instead so it has meaning for assistive technology and can use responsive-image loading behavior.
Choose a background image or an HTML image
A CSS background is a good fit for decoration: a hero texture, abstract pattern, or photograph that supports the page but does not add essential information. Background images are not announced by screen readers. If a reader needs the image to understand the page, put that information in text and use an <img> with appropriate alternative text where it helps.
For meaningful images, <picture> and <img> can use srcset and sizes to select a suitable source, expose image semantics, and generally receive higher loading priority than CSS backgrounds. MDN explains responsive image markup in its responsive images guide.
Set up a CSS background that fills its container
A background does not give its element intrinsic height. Set a height, minimum height, or aspect ratio so there is an area to paint. Add a fallback color in case the image cannot load; browsers use background-color behind the background image. This hero uses a dark overlay to help foreground text stand out:
#1 Best Overall
- DO MORE ON ONE SCREEN: See every detail on the wider display featuring a 21:9 aspect ratio; Ultra WQHD provides the simplest way to maximize screen real estate and experience truly seamless multitasking on just one screen.Brightness (Typical) : 300 cd/㎡. Static Contrast Ratio 3000:1.
- ENJOY A BILLION COLORS W/ INCREDIBLE DEPTH: With HDR10 that displays over 1 billion colors compared to 16.7 million for typical SDR technology, dark colors are darker and the brightest are even brighter; Content is experienced as the creator intended
- CARE FOR YOUR EYES DAY and NIGHT: An ambient light sensor on the monitor detects lighting in your workstation and automatically adjusts brightness; Eye Saver Mode minimizes excessive blue light, and Flicker Free relieves eye strain
- SEE CONTENT SMOOTHER, EVEN GAMING: A faster than average refresh rate updates the image on screen more often every second; 100Hz refresh rate reduces lag and motion blur when playing games, watching videos, or working on design projects
- STAY IN SYNC WITH THE ACTION: AMD Radeon FreeSync keeps the refresh rate of your monitor and graphics card in sync to reduce image tearing for a superfluid entertainment experience; Watch movies and play games without interruptions
.hero {
min-height: 22rem;
background-color: #243447;
background-image:
linear-gradient(rgb(0 0 0 / .35), rgb(0 0 0 / .35)),
url("hero-1600.avif");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
The gradient is layered above the image; adjust its opacity and inspect the actual text contrast rather than assuming that a darkened image is automatically readable. The CSS background property and fallback behavior are documented by MDN’s background-image reference.
Choose between cover and contain
| Value | What it does | Use it when | Trade-off |
|---|---|---|---|
cover |
Scales the image proportionally until the entire box is covered. | You want a full-bleed hero or panel with no uncovered area. | Some edges may be cropped, depending on the element’s aspect ratio. |
contain |
Scales the image proportionally until the entire image fits inside the box. | The whole image must remain visible. | Empty space can remain in the box. The background may repeat unless you disable it. |
With cover, use background-position to keep the important subject in view. For example, background-position: 65% center; biases the crop toward a subject that sits right of center. With contain, set background-repeat: no-repeat; if tiling is not intended. The correct choice depends on the container shape at each viewport, not just the source image dimensions.
Serve the right resolution for each screen
A high-resolution source helps avoid softness on high-density screens, but one very large file is wasteful on a small display. Make derivatives at realistic display widths and provide a 1x and 2x option where useful. MDN notes that only a very few people can spot an increase in resolution beyond 2× device pixel ratio in its Multimedia: Images guide.
Use image-set() for resolution variants
For a background whose composition works across sizes, image-set() lets the browser select a resolution candidate:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #2
- WIDESCREEN UHD: With 4x the pixels of Full HD, get more screen space (vs 16:9 screen) and UHD images; View documents & webpages w/ less scrolling, work more comfortably w/ multiple windows & toolbars, and enjoy photos, videos & games in stunning 4K
- A BILLION COLOR SHADES: Supporting a billion shades of color, the UJ59 delivers incredibly vivid and realistic images; Its color accuracy means colors appear true to life, making the UJ59 ideal for photo, video and graphics applications
- SEAMLESS UPSCALING: Samsung’s UHD upscaling technology includes signal analysis and detail enhancement that seamlessly upconverts SD, HD and Full HD content to near UHD-level picture quality
- WIDESCREEN 4K GAMING: With 8.3 million pixels supporting a wide range of colors and resolving every image with astonishing clarity, UHD gives you a wider view for a truly thrilling and immersive gaming experience
- SMOOTHER GAMEPLAY: AMD FreeSync synchronizes the refresh rate of your graphics card & monitor to reduce image tear & stutter; Low Input Lag Mode minimizes the delay between mouse, keyboard or joystick input and onscreen response for smooth gaming
.hero {
min-height: 22rem;
background-color: #243447;
background-image: image-set(
url("hero-800.jpg") 1x,
url("hero-1600.jpg") 2x
);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
The descriptor is a resolution hint, not a guarantee that every device will display the larger file: the browser selects a candidate for the context. If the scene needs a different crop on phones, use a media query to art-direct the background rather than relying only on a larger version of the desktop crop.
Offer modern formats with a fallback
MDN describes WebP as an excellent general-purpose format and AVIF as highly efficient; JPEG remains a practical photographic fallback, while PNG is useful when lossless detail or transparency is required. MDN documents format selection and fallback patterns for image-set() in its image-set() reference. For example, a browser that supports AVIF can select it, while another can use JPEG:
.hero {
background-image: image-set(
url("hero-1600.avif") type("image/avif") 2x,
url("hero-1600.jpg") type("image/jpeg") 2x,
url("hero-800.jpg") type("image/jpeg") 1x
);
background-size: cover;
}
Check format support for the browsers your site serves and retain an appropriate fallback when support or progressive rendering matters. Export at the actual display widths, remove metadata that is not needed, and compare the image at the largest expected display size before accepting compression.
Use responsive HTML for content imagery
If the image is meaningful or must load promptly as page content, use <picture> and <img> with responsive candidates. Example:
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
- Stunning Image Quality in 4K Display - The 27-inch UHD 4K (3840 x 2160) IPS display reproduces clear images and vibrant colors with up to 95% DCI-P3 color gamut expression . Experience dramatic visual immersion with all your favorite shows, movies, sports and games.
- 4K UHD HDR - To more fully realize content creators vision, this monitor is compatible with VESA DisplayHDR 400 high dynamic range, supporting specific levels of color and brightness that exceed the capabilities of ordinary monitors.
- Color Your World - Explore HDR content the way it was meant to be seen with up to 95% DCI-P3 color gamut expression—an elevated color spectrum that brings brilliant color to life.
- Never In the Dark - Light up your gameplay with enhanced vision. Black Stabilizer brightens dark scenes to give you an advantage over the competition—even when they’re hiding in the shadows.
- Action As It Happens - Get a pro-level experience with the closest thing to real-time gaming. Dynamic Action Sync elevates your gameplay so you can respond every moment of the action with reduced input tag and unbelievable performance.
<picture>
<source
type="image/avif"
srcset="hero-800.avif 800w, hero-1600.avif 1600w"
sizes="100vw"
>
<img
src="hero-1600.jpg"
srcset="hero-800.jpg 800w, hero-1600.jpg 1600w"
sizes="100vw"
width="1600"
height="900"
alt="A hiker looking across a mountain valley"
>
</picture>
Change sizes to describe the rendered width in your layout rather than copying 100vw blindly. The intrinsic dimensions help reserve space and reduce layout shifts. MDN’s responsive-image example illustrates how file size changes with delivered dimensions: it reports 93KB for a 640px image versus 39KB for a 320px image. Those figures describe that example, not a universal compression ratio.
Keep the subject, text, and contrast usable
Test the crop at the narrowest and widest breakpoints where the background appears. If cover cuts off the subject, shift background-position, choose a different crop at a breakpoint, or use an HTML image with a layout that preserves its composition. When placing text over photography, use an overlay, change the text color, or move the text to a quieter part of the image.
MDN cites WCAG contrast targets of 4.5:1 for body text and 3:1 for larger text in its background-image reference. Measure contrast against the rendered image behind the text, including the overlay and each responsive crop; checking only the original image does not establish the final contrast.
Performance checklist for background images
- Do not send a desktop-sized image to every phone when a smaller derivative will look adequate.
- Use
image-set()or breakpoint-specific CSS for resolution choices and art direction. - Prefer WebP or AVIF where they work for your audience; keep a fallback when needed.
- Do not make a decorative image a critical dependency if the content works without it.
- Prefer
<img>or<picture>for meaningful content and cases where loading priority matters. - Reserve the background container’s intended space with a height, minimum height, or aspect ratio. Give content images dimensions or an aspect ratio as well.
- Check actual transfer size, crop, focal point, readability, and behavior on narrow and high-DPI screens.
Image CDNs can automate device-size and format delivery; MDN names Cloudinary, Image Engine, ImageKit, and imgix as examples in its image guide. Compare their current capabilities and pricing directly with each provider before choosing one.
Rank #4
- 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
Troubleshoot common problems
The background is invisible
Check that the element has a non-zero height or aspect ratio, the URL resolves, and the stylesheet is not overridden by a later background declaration. Keep a fallback color so a failed request does not leave the text on an unexpected surface.
The image looks soft on a Retina display
Confirm the browser is receiving a sufficiently large candidate for the rendered CSS size. Add an appropriate higher-density version with image-set(), or serve responsive variants through an HTML image if it is content. Avoid routinely exceeding 2× density: MDN says only a very few people can spot higher resolution.
The subject is cut off
This is expected with cover when source and container proportions differ. Reposition the image with background-position, prepare a mobile crop, or choose contain if showing the complete image is more important than filling the box.
The image tiles or leaves blank bands
contain can leave uncovered space; set a suitable background color and use background-repeat: no-repeat if repetition is undesirable. If the image must fill the box, try cover and accept a deliberate crop.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Best Value
- Improved ComfortView Plus: Reduces harmful blue light emissions to ≤35%, for all-day comfort without sacrificing color accuracy.
- Refresh rate: A smooth, tear-free experience with AMD FreeSync Premium (refresh rate up to 120Hz) and an ultra-low 0.03ms response time create a captivating experience for work and play.
- Vivid colors: Immerse yourself in breathtaking 4K visuals with in-plane switching technology. Enjoy vibrant colors with 99% sRGB. The 1500:1 contrast ratio and HDR readiness deliver excellent depth and detail.
- Re-engineered sound quality: Enjoy more detailed sound with spacious audio featuring greater output power, deeper frequency response and more decibel range than the previous generation.
- Ultra-thin bezel: Designed with a sleek, modern aesthetic and an ash white finish, this display features ultra-thin bezels for a refined, minimalist design.
Text is hard to read over the image
Test the final crop and overlay at the actual breakpoints. Increase or adjust the overlay, reposition the text or focal point, or use a solid text surface. Verify the rendered contrast rather than judging the asset in isolation.
Or skip the browser setup
To capture a rendered page for a visual check, use ScreenshotNeo’s screenshot API. Its one-call GET endpoint returns an image or PDF; see the ScreenshotNeo documentation for request options.
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 or 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 the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan.
Frequently Asked Questions
Can I use a CSS background image for a logo or product image?
Only if it is purely decorative. If the image identifies a product or communicates information, use an HTML image with suitable alternative text.
Does a higher-resolution source always make a background look better?
No. It can improve sharpness on high-density displays, but the image still needs an appropriate crop, and excessive resolution adds transfer cost with little visible benefit for most people.
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.

