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

Use CSS—not a special HTML tag—to place a PNG behind an element. Add background-image: url("...") to the element’s rule, give that element visible dimensions, and choose how the image fits with background-size, background-position, and background-repeat.

.hero {
  min-height: 20rem;
  background-image: url("images/background.png");
  background-color: #e8eef2;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

The HTML can stay simple:

<section class="hero">
  <h1>Page heading</h1>
</section>

This approach is suitable for decorative artwork, textures, overlays and logos with transparent edges. If the PNG conveys information a visitor needs, use an <img> with useful alternative text instead of a CSS background.

1. Put the PNG in your project and reference it from CSS

Save the file in a location served by your site, such as images/background.png. The URL in background-image is resolved relative to the CSS file, not relative to the HTML file. For example, if your stylesheet is css/site.css and the image is images/background.png at the project root, use url("../images/background.png").

/* css/site.css */
.hero {
  min-height: 20rem;
  background-image: url("../images/background.png");
  background-color: #e8eef2;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

MDN describes background-image as the CSS property that sets one or more background images on an element. A relative path, an absolute path, or a URL such as url("cat-front.png") is valid.

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.

Make sure the element has a background area

A background paints only the element’s box. An empty <div> with no height may collapse to zero pixels, making a correctly loaded image appear missing. Use content, min-height, explicit dimensions, padding, or an aspect-ratio to create a visible box.

.banner {
  min-height: 320px;
  padding: 4rem 2rem;
}

/* Useful when the element should keep a known shape */
.preview {
  aspect-ratio: 16 / 9;
}

Use a fallback color

Set background-color along with the image. The color shows through transparent PNG pixels and remains visible if the URL is wrong, the server is unavailable, or the image has not finished loading. A color that contrasts with the text also gives a more reliable fallback.

2. Control scale: cover, contain, or explicit dimensions

background-size determines how the PNG is fitted into the element. The two practical choices preserve the source aspect ratio and make different compromises.

Value Result Choose it when Trade-off
cover Scales until the entire box is covered. A full-bleed hero, card or section is required. Parts of the image can be cropped.
contain Scales the complete image to fit inside the box. Every edge of a diagram, illustration or logo must remain visible. Uncovered space can remain around the image.
100% 100% Stretches width and height independently. Only when intentional distortion is acceptable. Circles and other proportions can look warped.

Full-bleed section with cropping

.hero {
  min-height: 24rem;
  background: #17202a url("../images/mountain.png") center / cover no-repeat;
}

The shorthand combines color, image, position, size and repeat. The equivalent longhand is often easier to debug. With cover, the image is scaled until both dimensions meet or exceed the element; the excess lies outside the box.

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

Show the entire PNG

.diagram-panel {
  min-height: 20rem;
  background-color: #f4f6f8;
  background-image: url("../images/diagram.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

Different aspect ratios can leave strips of the fallback color. That is expected with contain, not a failed load.

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.

3. Choose the visible focal point

background-position decides which part of the image stays visible when fitting or cropping. Its default origin is the top-left corner. Common values include center, top center, right bottom, and percentages.

.portrait-hero {
  min-height: 28rem;
  background-image: url("../images/portrait.png");
  background-size: cover;
  background-position: 70% 20%;
  background-repeat: no-repeat;
}

The first percentage controls the horizontal position and the second controls the vertical position. Move the value toward the subject you want to preserve. For a subject near the top, top center is easier to read than a trial-and-error percentage.

4. Stop accidental tiling

Backgrounds repeat by default. If your PNG should appear once, set background-repeat: no-repeat; the property is documented in MDN’s background-repeat reference. Without it, a small image can tile across both axes and look like a pattern.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.single-art {
  background-image: url("../images/art.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

For a deliberately repeating texture, choose the behavior explicitly: repeat-x repeats horizontally, repeat-y vertically, and repeat in both directions.

5. Layer a color, gradient, and PNG

CSS accepts comma-separated background layers. The first image is painted on top of later layers. This lets you add a readable overlay while retaining the PNG.

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.
.readable-hero {
  min-height: 22rem;
  color: white;
  background-color: #243447;
  background-image:
    linear-gradient(rgba(0, 0, 0, .45), rgba(0, 0, 0, .45)),
    url("../images/city.png");
  background-repeat: no-repeat, no-repeat;
  background-position: center, center;
  background-size: cover, cover;
}

Each layer gets a matching position, size and repeat value. The final background color remains underneath all layers and is useful when the PNG has transparent regions.

6. Responsive and transparent PNG patterns

Let the box adapt to the viewport

Use a flexible height or minimum height rather than a fixed pixel height when the text can wrap. Combine a responsive padding value with background-size: cover, then check the crop at narrow widths.

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.
.feature {
  min-height: clamp(18rem, 55vw, 34rem);
  padding: clamp(2rem, 6vw, 6rem) 1.25rem;
  background: #dce7ee url("../images/feature.png") center / cover no-repeat;
}

@media (max-width:  fortyrem) {
  .feature {
    background-position: 65% center;
  }
}

Replace fortyrem with a valid numeric media-query value such as 40rem; the example is shown this way to emphasize that CSS units must be numeric. A valid rule is:

@media (max-width: 40rem) {
  .feature { background-position: 65% center; }
}

Use transparency intentionally

PNG supports an alpha channel, so shadows, irregular logos and illustrations can reveal the element’s color behind them. Pick that color for sufficient contrast and test the result in both light and dark themes. PNG uses lossless compression, but that does not make it the smallest format for every image. MDN’s image format guide notes that WebP and AVIF can provide better compression; choose based on transparency, image type, delivery size and the browser support your project requires.

7. Background versus an HTML image

A CSS background is presentation layered behind content. It does not provide an image alternative-text attribute. Use an HTML image when the image itself communicates information, such as a product photo, chart, map or instructional diagram.

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
<figure>
  <img src="images/diagram.png" alt="Flow from sign-up to account activation">
  <figcaption>Account activation flow</figcaption>
</figure>

Keep the background approach for decorative scenery, textures, color treatments and nonessential artwork. Do not hide meaningful text in the PNG; place text in HTML so it can be resized, translated, selected and read by assistive technology.

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

8. Debug a PNG background that does not appear

  1. Inspect the computed styles. In browser developer tools, select the element and verify that background-image resolves to the expected URL rather than none.
  2. Check the path from the CSS file. Move up directories with ../ as needed. A path that works in an HTML src attribute can be wrong in a stylesheet.
  3. Open the image URL directly. A 404, permission error, redirect problem or mixed-content block confirms a delivery issue. Correct the filename, capitalization and server route.
  4. Give the element height. Temporarily add min-height: 200px and a conspicuous background color. If the color appears, the box exists and the remaining issue is image loading or fitting.
  5. Disable cropping while testing. Try background-size: contain and background-position: center. This distinguishes a crop from a missing image.
  6. Look for an overriding rule. A later background shorthand can reset image, repeat, position and size declarations. Place the final rule later or keep related declarations together.
  7. Check the network panel. Confirm the response status and content type. If the server returns an HTML error page with a successful status, fix the route rather than the CSS.

9. Performance, caching and delivery considerations

Large lossless PNGs can increase transfer time, especially for photographic backgrounds. Export at the largest display size you actually need, remove unnecessary metadata, and compare WebP or AVIF when alpha transparency and browser support allow. Keep a solid color behind the image so text and layout remain usable while it loads.

Browsers cache successful image responses according to the server’s cache headers. When replacing a file during deployment, use a versioned filename such as background.v2.png or an appropriate cache-busting query string if stale content must be avoided. Avoid loading a huge background for a small component; use media queries or a responsive image strategy when different assets materially reduce bytes.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

10. Capture the finished page without setting up a browser

If you need a rendered PNG of the page for a test, documentation image, preview or automation pipeline, ScreenshotNeo provides a website screenshot API and MCP server. It accepts a URL and returns PNG, JPEG, WebP or PDF. Before capture, it can accept consent banners and remove more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and whether it was billed.

One-call cURL example

See the parameter details in the ScreenshotNeo documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://example.com 
  -o page.webp

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
    timeout=90,
)
r.raise_for_status()
open("page.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://example.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('page.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo also offers full-page captures with lazy images loaded, selector-based element captures, device presets, arbitrary viewports, retina scale, custom CSS and JavaScript, click actions, waits, request blocking, headers, cookies, user agents, authorization, timezone and geolocation controls, transparent backgrounds, resizing, selectable cache TTLs, signed public-image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs, which can simplify migration. An MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

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.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; all features are available on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to try it.

11. A practical decision checklist

  • Use background-image on the element that owns the visual area.
  • Confirm the URL is relative to the stylesheet and the filename’s capitalization matches.
  • Give the element content, padding, height, min-height or aspect-ratio.
  • Choose cover for a filled box with possible crop, or contain to preserve every edge.
  • Set background-position to keep the important subject visible.
  • Set background-repeat: no-repeat unless tiling is intentional.
  • Set a fallback background-color, especially when the PNG has transparency.
  • Use an accessible <img> with alt text for meaningful image content.
  • Review file size and consider WebP or AVIF when their compression and support fit the project.

Frequently Asked Questions

Can I use a PNG from another domain in CSS?

Yes, a public image URL can be used, but availability, hot-link restrictions, authentication and the remote server’s caching policy still apply. Hosting the asset with your site gives you control over those conditions.

How do I use more than one background image?

Separate layers with commas: background-image: url("foreground.png"), url("base.png");. The first layer is painted above the second, and each layer can have its own position, size and repeat values.

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

Will a CSS background print by default?

Browsers and user print settings may omit background graphics. If the visual is required on paper, provide an equivalent foreground image or content and test the browser’s print preview rather than relying solely on a background.

How can I preload a critical background?

A preload link can request a known image early, but it must use the exact URL and an appropriate as value. Measure first; preloading too many backgrounds competes with HTML, fonts and other critical resources.

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.