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

There is no single best pixel dimension for every website gallery. Choose image candidates from the largest rendered slot in your responsive layout, then let the browser select among them with srcset and sizes. Account for device-pixel ratio, reserve space with intrinsic dimensions, and encode each candidate at a quality that balances sharpness and download weight.

Start with the rendered slot, not an arbitrary image size

The width an image occupies in CSS is the most useful starting point. A thumbnail in a three-column desktop grid may render at roughly one third of the content area, while the same item can occupy half or all of the viewport on smaller screens. Those slots do not need the same source width.

Measure the real layout after accounting for the page container, column gaps, padding, borders and breakpoints. If a gallery column is 360 CSS pixels wide, a 360-pixel source is adequate for a standard-density display, but a high-density screen may need a larger candidate to remain crisp. Source dimensions should follow the largest slot the image can actually occupy, not the monitor’s total pixel width.

A practical starting range

For many responsive galleries, generate several derivatives around the widths your layout uses—for example 320, 600, 900 and 1200 pixels. These values are illustrative, not a universal preset. Replace them with widths that fit your container and breakpoint math. Generating dozens of nearly identical files increases storage, processing and cache complexity without necessarily improving the result.

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

Account for device-pixel ratio

CSS pixels and image pixels are not always one-to-one. A slot that is 500 CSS pixels wide may need a 1000-pixel source on a device-pixel ratio (DPR) 2 display, or a 1500-pixel source at DPR 3. These are worked examples rather than a rule that every gallery should ship only 2x or 3x files.

Width-descriptor candidates let the browser choose an appropriate resource for both slot width and density. Supplying only a small thumbnail can make a high-density display look soft; supplying only a very large original wastes bandwidth for users who see a small tile.

Use responsive image markup

Provide a fallback src, a width-descriptor srcset, and a sizes expression that describes your CSS layout. Include the source’s intrinsic dimensions so the browser can reserve the correct aspect ratio before the file arrives.

<img
  src="gallery-600.jpg"
  srcset="gallery-320.jpg 320w,
          gallery-600.jpg 600w,
          gallery-900.jpg 900w,
          gallery-1200.jpg 1200w"
  sizes="(min-width: 66em) 33vw,
         (min-width: 44em) 50vw,
         100vw"
  width="600"
  height="400"
  alt="Describe the image"
  loading="eager"
>

How sizes maps to the layout

The example says that at 66em and above, each image is about one third of the viewport; between 44em and 66em, it is about half; below 44em, it is about the full viewport width. Change those values when your CSS uses a max-width container, fixed gaps or different breakpoints. An inaccurate sizes value can make the browser download an unnecessarily large file or choose one that is too small.

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

Why keep width and height

These attributes communicate the intrinsic ratio before the image loads, reserving space and reducing layout movement. Use numbers that match the source ratio. They do not force the image to render at that CSS size; CSS still controls the displayed dimensions.

.gallery img {
  max-inline-size: 100%;
  block-size: auto;
  display: block;
}

Choose the right aspect ratio and crop

Uniform tiles often look best when every item has the same ratio. If your design intentionally crops thumbnails, make that decision explicit:

.gallery-tile {
  aspect-ratio: 3 / 2;
  overflow: hidden;
}

.gallery-tile img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}

Use the uncropped, larger derivative for a lightbox or detail page when users can enlarge an image. Do not stretch a source into a different ratio; preserve proportions with block-size: auto or apply a deliberate crop with object-fit.

When to use <picture>

Use <picture> when the composition itself should change by viewport—for example, a wide landscape crop on desktop and a tighter subject-focused crop on mobile. Merely changing resolution does not require art direction.

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.
<picture>
  <source media="(max-width: 43.99em)" srcset="subject-mobile-600.jpg 600w, subject-mobile-900.jpg 900w" sizes="100vw">
  <img
    src="subject-wide-900.jpg"
    srcset="subject-wide-600.jpg 600w, subject-wide-900.jpg 900w, subject-wide-1200.jpg 1200w"
    sizes="(min-width: 66em) 33vw, (min-width: 44em) 50vw, 100vw"
    width="1200"
    height="800"
    alt="Describe the image"
    loading="eager"
  >
</picture>

Balance quality, format and transfer weight

WebP and AVIF can be more space-efficient than JPEG or PNG for many images, but the best choice depends on the content and the browsers your audience uses. Compare visible quality at the actual rendered size, not only at 100% zoom. Keep a fallback where your supported audience requires it.

Decision What to evaluate Typical trade-off
More width candidates How closely files match real slot widths Less overfetching, but more files to generate, store and cache
Higher DPR candidates Sharpness on dense displays Better detail, larger downloads
WebP or AVIF Audience browser support and image content Smaller files when supported, more encoding and fallback work
PNG or JPEG Existing compatibility and content characteristics Simple delivery, sometimes heavier files

Every additional format and width variant adds operational cost. Start with candidates justified by your breakpoints and performance goals, then expand only when measurements show a meaningful benefit.

Lazy-load without delaying the first view

Gallery items below the initial viewport are good candidates for loading="lazy". The first visible, content-critical image should generally be allowed to load normally so it is not unnecessarily delayed. Keep meaningful alt text for informative images; use an empty alt only when an image is purely decorative.

Validate the result on real layouts

  1. Open the gallery at each breakpoint and record the actual rendered width of a tile.
  2. Inspect the selected image resource in browser developer tools and confirm it is close to the slot width multiplied by the needed density.
  3. Test slow and fast connections, standard and high-density displays, and browsers used by your audience.
  4. Run Lighthouse’s “Properly size images” audit to identify images that are substantially larger than their rendered slots.
  5. Check that reserved dimensions prevent layout shifts and that cropped tiles preserve the intended focal point.

Common sizing mistakes and fixes

Using one enormous original everywhere

Symptom: Small thumbnails download multi-megapixel files. Fix: Create width derivatives and provide accurate srcset and sizes.

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.

Using one tiny thumbnail for every context

Symptom: Desktop or high-density tiles look blurry. Fix: Add a candidate large enough for the widest slot and the target DPR.

An inaccurate sizes expression

Symptom: The browser consistently chooses files that are too large or too small. Fix: Recalculate the CSS slot at each breakpoint, including container limits and gaps, then update sizes.

Missing intrinsic dimensions

Symptom: Text and neighboring tiles jump as images load. Fix: Set matching width and height attributes or an equivalent aspect-ratio reservation.

Accidental distortion

Symptom: Faces or objects appear stretched. Fix: Use proportional sizing, or intentionally crop within a fixed-ratio wrapper using object-fit: cover.

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

Too many barely different variants

Symptom: Build pipelines and caches become difficult to maintain with little visual gain. Fix: Keep widths near real layout demands and remove candidates that are never selected.

Performance, reliability and cost considerations

Image optimization is not only a pixel question. More derivatives require generation time, storage and cache entries. Fewer, well-chosen candidates simplify operations but may cause modest overfetching. Measure transfer size and visual quality at the gallery’s real display dimensions, and revisit the set when your breakpoints or container width changes.

Preserve originals separately when your product supports downloads or a lightbox. Gallery thumbnails should not become the only copy of an image. If you change encoding settings, verify that metadata, orientation and color handling remain correct for your workflow.

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 your goal is to obtain clean screenshots of gallery pages for documentation, previews or automated checks, ScreenshotNeo makes one request instead of requiring you to configure a headless browser. It accepts consent banners before capture and removes 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 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 Claude, Cursor and other MCP clients.

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

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

See the ScreenshotNeo API documentation for the complete options. Features include full-page shots with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF controls, custom CSS and JavaScript, clicks, selector or network-idle waits, request blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, configurable caching, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. Parameter names used by other screenshot APIs also work, which can simplify migration.

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

Frequently Asked Questions

Should gallery images be square?

Only if the design calls for square tiles. Choose the ratio that suits the content, reserve that ratio in markup or CSS, and crop deliberately when uniform tiles are required.

How can I tell whether a candidate set is too large?

Compare the selected resource width with the measured slot at each breakpoint and inspect transfer sizes on representative devices. Remove candidates that are rarely selected or substantially exceed the rendered requirement.

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

Do I need separate files for a lightbox?

Use larger, preferably uncropped sources when the lightbox permits enlargement; the thumbnail derivatives should remain optimized for the gallery slots.

The Bottom Line

The best gallery image size is the smallest source that remains sharp for the image’s largest real slot and target display density. Build a small, purposeful set of derivatives, describe the layout with sizes, let srcset choose the file, and reserve the aspect ratio before loading.

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.