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

Use an HTML <img> (or <picture>) when an image communicates information, documents content, or is part of the page’s meaning. Use CSS background-image when the image is purely decorative or part of a component’s visual treatment. This choice affects accessibility, responsive image selection, loading behavior, and layout stability—not just styling.

Choose by meaning first

The reliable rule is semantic: HTML represents document content; CSS represents presentation. A product photograph, diagram, editorial photograph, map, chart, or instructional illustration belongs in the document and should normally be an HTML image. A texture, gradient-like photo treatment, ornamental flourish, or decorative panel background belongs in CSS. MDN summarizes the principle as: “Ideally, presentational or decorative images are included with CSS instead of HTML.” MDN’s <img> reference explains the content-side behavior.

Use case Preferred method Why
Product photo, diagram, article photo <img> or <picture> It is content, can have meaningful alternative text, and participates in responsive-image features.
Texture, decorative flourish, visual panel treatment CSS background-image It is presentation and can be positioned, sized, layered, and cropped with the component.
Different crop for mobile and desktop <picture> Media conditions can select art-directed sources.
Different resolutions of the same image srcset and sizes The browser chooses an appropriate candidate for viewport and pixel density.
Meaningful image that is redundant in context <img alt=""> An empty alternative tells assistive technology to skip the image.

CSS backgrounds do not have an equivalent alt attribute. If users need information conveyed by the image, putting it only in CSS makes that information unavailable to screen readers and less explicit in the document structure.

When HTML images are the right answer

Meaningful content and alternative text

Write alternative text for the image’s purpose in context, not a mechanical inventory of every visible pixel. For example, an article image might use alt="A hiker crossing a rocky trail above the tree line". If the surrounding text already conveys exactly the same information and the image adds no new meaning, use alt="" rather than repeating the prose. Keep the alt attribute present even when it is empty.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Responsive source selection

HTML exposes native mechanisms that CSS backgrounds do not match as directly. Use srcset with sizes for width or resolution candidates, and <picture> with <source> when format or art direction depends on media conditions. The browser can make its choice while processing the document; it does not need to download every candidate.

<img
  src="trail-800.jpg"
  srcset="trail-400.jpg 400w, trail-800.jpg 800w, trail-1600.jpg 1600w"
  sizes="(max-width: 600px) 100vw, 800px"
  width="1600"
  height="1067"
  alt="A hiker crossing a rocky trail above the tree line">

The actual files, dimensions, and wording must match your image. The width and height values provide an aspect-ratio hint; CSS such as max-width:100%; height:auto can still make the image fluid.

Format and art direction with <picture>

<picture>
  <source media="(max-width: 600px)" srcset="trail-portrait.jpg">
  <source type="image/avif" srcset="trail-1600.avif">
  <img src="trail-1600.jpg" width="1600" height="1067"
       alt="A hiker crossing a rocky trail above the tree line">
</picture>

The fallback <img> remains required. See MDN’s responsive-images guide for the selection model and syntax.

When CSS backgrounds are the right answer

Decoration attached to a component

Apply the background to the element whose visual design uses it. Backgrounds are useful when the image must fill a box, sit behind text, be layered with gradients, or be cropped independently of document flow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.card {
  background-image: url("paper-texture.webp");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

Use cover when the box must be filled (accepting cropping), contain when the complete image should remain visible, and explicit positions such as center top when composition matters. Keep any information represented by the background in text, labels, or other accessible content.

Do not use a background to hide content

A banner that says “20% off,” a map used to explain directions, or a hero photograph that is the subject of the story is not merely decoration because the image contributes meaning. Put it in HTML and provide an appropriate alternative. A CSS background can supplement that content, but should not be its only delivery.

Accessibility differences

  • HTML content: meaningful images need useful alternative text; decorative HTML images need alt="".
  • CSS decoration: there is no image alternative-text attribute, so assistive technology generally does not treat the background as document content.
  • Text contrast: text placed over either method still needs sufficient contrast. Do not assume a background is harmless simply because it is decorative.
  • Redundancy: if a visible icon has an adjacent text label, mark the icon decorative or otherwise avoid announcing the same information twice.

Performance, discovery, and layout stability

Reserve space before the file arrives

Images without a known ratio can move surrounding content as they load. Provide intrinsic width and height on HTML images, or establish an equivalent aspect ratio in CSS. This lets the browser reserve space and reduces image-driven layout movement. The guidance is covered in web.dev’s image performance issues material.

Match loading to visual importance

Use loading="lazy" for suitable, noncritical images below the fold. Do not lazy-load a hero or other image likely to be visible immediately: delaying its discovery can slow the image that forms the page’s largest contentful paint. fetchpriority="high" can help a truly important image, but use it sparingly so it does not compete with other critical resources. See web.dev’s lazy-loading guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<img src="gallery-800.jpg" width="800" height="533"
     loading="eager" alt="Red canoe on a calm lake">

Background loading follows stylesheet and rendering behavior rather than the <img loading> attribute. If a background is critical, inspect when the stylesheet and image are discovered instead of assuming it behaves exactly like an image declared early in HTML. A decorative background should generally not be allowed to compete with content images for early bandwidth.

A practical decision checklist

  1. Ask whether the image conveys information. If yes, start with <img> or <picture>.
  2. Choose the alternative text. Describe the image’s purpose, or use alt="" when it is redundant decoration.
  3. Check for responsive requirements. Use srcset/sizes for candidate sizes and <picture> for art direction or format conditions.
  4. Reserve the ratio. Supply dimensions or an explicit aspect ratio before loading.
  5. Set loading priority. Keep likely above-the-fold/LCP images eager; lazy-load appropriate noncritical images.
  6. Use CSS for presentation. Choose background positioning, sizing, repeat, and layering when the image is decoration.
  7. Test without the image. Disable images or use a screen reader: the page should still communicate its purpose and controls.

Common edge cases

Hero sections

A hero photo can be either method. If it is atmosphere behind a heading, CSS is reasonable; if the photo itself communicates the story or product, use HTML. For a critical HTML hero, avoid lazy loading and reserve its dimensions.

Logos and icons

A company logo that identifies the organization is content and normally needs an accessible name (often via meaningful alt text). A purely decorative background mark can remain CSS. Interface icons that duplicate a visible label should be decorative; icons that are the only control label need an accessible name on the control.

Images in generated or stateful components

If JavaScript swaps sources, retain semantic HTML and update its alternative text when the image’s meaning changes. Do not move meaningful content into a background merely because a component is rendered dynamically.

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

Troubleshooting

The image is stretched or causes a jump

Check that the intrinsic dimensions reflect the real ratio, then use max-width:100%; height:auto for fluid HTML images. For a background, define the container’s ratio or a stable height before applying cover.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

The wrong responsive file downloads

Verify width descriptors in srcset, the rendered width in sizes, and media conditions in <picture>. Browser zoom, device pixel ratio, cache state, and network conditions all influence selection; inspect the request in developer tools rather than judging by filename alone.

A decorative image is announced

For an HTML image that adds no information, set alt="". Do not put explanatory text in a CSS background; place required information in the document.

The hero appears late

Remove inappropriate loading="lazy", ensure the image is discoverable in initial HTML, reserve its ratio, and consider fetchpriority="high" only for the genuinely critical image. For a CSS hero, check stylesheet delivery and when the background request starts.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a rendered screenshot of a page rather than an image embedded in that page, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF; it can accept cookie banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture, with each step configurable. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

Use the ScreenshotNeo API documentation for all options, including viewport and device presets, full-page and selector captures, dark mode, retina scale, PDF settings, custom CSS/JavaScript, click and wait actions, request blocking, headers, cookies, user agent, authorization, timezone, geolocation, transparent backgrounds, resizing, cache TTL, signed links, asynchronous webhooks, bulk capture, usage data, and the OpenAPI specification.

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}`);

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is available on every plan. Create a free ScreenshotNeo account.

FAQ

Can CSS backgrounds be responsive?

Yes, CSS media queries and modern image functions can change a background, but HTML srcset, sizes, and <picture> provide the dedicated content-image selection model when the asset is meaningful.

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

Should a decorative image be an HTML image with empty alt?

That is valid when the image must exist in the document for layout or scripting. Use alt="" so assistive technology skips it; otherwise CSS keeps presentation separate from content.

Does either method guarantee a faster page?

No. File size, dimensions, discovery timing, compression, caching, and loading priority determine performance. The markup choice should remain semantic first, then be tuned with responsive sources and appropriate loading behavior.

Frequently Asked Questions

Can CSS backgrounds be responsive?

Yes, but HTML srcset, sizes, and picture provide the dedicated content-image selection model for meaningful images.

Should a decorative image be an HTML image with empty alt?

It can be, when required for document layout or scripting; use alt=”” so assistive technology skips it.

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

Does either method guarantee a faster page?

No. File size, discovery timing, compression, caching, and loading priority matter more than the choice alone.

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.