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

Choose the format from the image’s content, then choose dimensions from the largest size your layout actually displays. Use SVG for scalable artwork, WebP or AVIF for most modern raster images, JPEG for photographs and broad fallback compatibility, and PNG when transparency or exact, lossless detail matters. Export several width variants, connect them with srcset and sizes, compress at the rendered size, and provide useful alternative text.

Start with the image’s job, not its file extension

There is no single “best” website format. A photograph, logo, interface screenshot and animated illustration have different requirements. The correct choice balances visual detail, transparency, animation, browser compatibility, decoding behavior and downloaded bytes.

Content or requirement Best starting point Why and what to watch
Logos, icons, diagrams and geometric illustrations SVG Scales without raster blur. Give the image an appropriate accessible name, or use an empty alternative when it is purely decorative.
Photographs and photo-like editorial images JPEG, lossy WebP or lossy AVIF Lossy coding is efficient for photographic detail. Compare files at their actual display size rather than judging only at 100% zoom.
Screenshots, UI captures, diagrams and line art PNG, lossless WebP or lossless AVIF Sharp text and edges reveal ringing and blur from aggressive lossy compression.
Transparency PNG, WebP or AVIF All support transparency; select the smallest format that preserves edges and the compatibility you need.
Animation Animated WebP or AVIF; video for longer sequences GIF is limited to 256 colors and can be much larger than video. Use video when the sequence is long or photographic.
Legacy or broad fallback JPEG or PNG They remain the broadly supported raster fallbacks when a platform cannot decode a modern format.

WebP versus AVIF

WebP and AVIF generally compress better than older formats, so they are strong defaults for new raster delivery. AVIF can produce very small files, while WebP has a mature implementation footprint and is often an easier operational choice. The winning format is the one that meets your visual-quality target at the dimensions you serve and works in every client you support.

Use a fallback when the audience requires it

For public sites, embedded WebViews, email-like environments or controlled enterprise software, offer a modern source and a JPEG or PNG fallback:

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
<picture>
  <source srcset="hero.avif" type="image/avif">
  <source srcset="hero.webp" type="image/webp">
  <img src="hero.jpg" alt="Description of the subject and purpose" width="1200" height="675">
</picture>

The browser selects the first supported source. The fallback remains a real, usable image rather than a placeholder.

PNG or JPEG?

Choose JPEG for photographs

JPEG’s lossy compression is well suited to continuous-tone images such as people, landscapes and product photography. Increase or decrease quality until faces, gradients and fine textures still look natural at the rendered size.

Choose PNG for precision

PNG is appropriate for screenshots, charts, flat-color graphics and images that need transparency or exact pixel reproduction. A PNG can be larger than a comparable lossy file, but artifacts around text and one-pixel lines are usually more damaging than extra bytes.

Consider lossless WebP or AVIF

When your delivery pipeline and clients support them, lossless WebP or AVIF can retain crisp edges with fewer bytes than PNG. Keep a PNG fallback where platform compatibility is uncertain.

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

How many pixels should a website image be?

Start with CSS, not the camera or design file. Find the maximum CSS width at which the image will render, then generate practical candidates around your layout breakpoints. Include a larger candidate for high-device-pixel-ratio screens when sharpness matters, but do not ship a source substantially wider than its intended use.

Use width candidates, not one oversized original

A content column that reaches 1,200 CSS pixels might use 480, 800, 1,280 and 1,920 pixel files. Those numbers are examples, not universal breakpoints: derive your own set from the actual layout. Keep the aspect ratio consistent unless you deliberately need art direction with a separate crop.

Let the browser select the file

srcset lists available widths; sizes tells the browser how wide the image is expected to be. CSS still controls the displayed size.

<img
  src="hero-1280.jpg"
  srcset="hero-480.jpg 480w, hero-800.jpg 800w, hero-1280.jpg 1280w, hero-1920.jpg 1920w"
  sizes="(max-width: 700px) 100vw, (max-width: 1200px) 80vw, 1200px"
  width="1200"
  height="675"
  alt="Description of the subject and purpose">

The width and height attributes reserve the aspect-ratio space before the file arrives, reducing layout movement. They do not force the downloaded candidate; srcset and sizes handle that decision.

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

A practical compression workflow

  1. Classify the source. Identify it as a photograph, screenshot or diagram, vector artwork, transparency-heavy graphic or animation.
  2. Select a candidate format. Begin with the matrix above and decide whether a fallback is needed.
  3. Resize before encoding. Export to the largest actual display need. An oversized source wastes transfer; an undersized source cannot recover detail.
  4. Compare quality settings. Inspect faces, text, one-pixel rules, gradients and transparent edges at the rendered dimensions. Stop increasing compression when artifacts become visible.
  5. Generate width variants. Produce files around your layout’s real breakpoints and high-DPR needs.
  6. Wire responsive markup. Add srcset, an accurate sizes expression, intrinsic dimensions and meaningful alternative text.
  7. Measure representative loads. Test the largest likely contentful image on realistic phones, desktops and network conditions.

Hero images and Largest Contentful Paint

A hero image is often the page’s Largest Contentful Paint candidate. Sending a desktop-sized file to a phone delays that milestone, while an excessively compressed image harms the first visual impression. Match the largest candidate to the hero’s real desktop width, provide smaller candidates for narrow layouts, and verify the result with representative devices and network throttling. Reserve space with intrinsic dimensions so text and controls do not jump while the image loads.

Accessibility rules that apply to every format

Write alternative text for informative images

Describe the subject and purpose, not every visible detail. A product photo might need the product name and distinguishing feature; a chart needs the point it communicates. An image that conveys essential prose should not replace real HTML text, because text inside a bitmap is not selectable, searchable or zoomable.

Use an empty alternative for decoration

For a purely decorative flourish, use alt="" so assistive technology can skip it. SVG does not remove this responsibility: whether embedded with img or inline, communicate the vector’s purpose.

Operational decisions and edge cases

Art direction is different from resolution switching

srcset with width descriptors supplies the same composition at different sizes. If mobile needs a tighter crop or a different subject, use separate sources in picture rather than forcing one image to serve incompatible compositions.

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.
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

Do not confuse sizes with CSS

sizes is a download hint. It does not change the rendered width. Keep the media conditions synchronized with the layout rules in your CSS; an inaccurate value can make the browser fetch a file that is too large or too small.

Watch transparent edges and text

Lossy coding can create halos against a new background and blur small labels. Test transparency on the backgrounds users will actually see, and use lossless encoding for UI captures where a one-pixel change matters.

Animation may belong in video

For longer or photographic motion, video usually provides better compression and playback controls than an animated image. Keep an animated WebP or AVIF for short loops when an image element is the simplest integration.

Diagnosing slow or blurry images

The download is much larger than expected

  • Check whether a phone is receiving the desktop candidate; correct sizes and add a smaller width.
  • Confirm the source was resized before encoding.
  • Compare WebP or AVIF at the same visual quality, while retaining a fallback where necessary.

Text or edges look smeared

  • Switch a screenshot, diagram or logo to PNG or a lossless modern format.
  • Raise quality and inspect at the actual CSS size.
  • Ensure the source is not being enlarged beyond its intended width.

The image causes layout shift

  • Add matching width and height attributes or an equivalent aspect-ratio rule.
  • Check that alternate crops do not change the reserved ratio unexpectedly.

A modern file does not display

  • Verify the MIME type and file response.
  • Use the picture fallback pattern with JPEG or PNG.
  • Test the actual embedded browser or client, not only your desktop browser.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Capturing reference images and previews without running a browser

If you need screenshots of pages to evaluate formats, document responsive states or populate a visual catalog, ScreenshotNeo is the first screenshot API to try: it removes consent banners, popups and chat widgets before capture, bills only clean shots, and its paid plan starts at $5 for 3,000 shots.

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

Or skip the browser setup

Make one request to capture a page; the response can be PNG, JPEG, WebP or PDF. The service accepts options for full-page or element capture, device and viewport settings, retina scale, custom CSS and JavaScript, waits, blocking rules, headers and cookies, caching, signed links, asynchronous jobs and bulk capture. Bot checks, blank pages, timeouts and failed loads are not billed, and response headers identify the page verdict and billing status. An MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.

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 complete parameter reference in the ScreenshotNeo documentation. The free plan includes 1,000 screenshots each month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.

Observed format usage is not a recommendation

The HTTP Archive’s Web Almanac 2024 reported observed usage shares of JPG 32.4%, PNG 28.4%, GIF 16.8%, WebP 12.0%, SVG 6.4% and other or unknown 1.7%. These figures describe what sites used in 2024, not what a new site should choose. JPEG and PNG remain useful fallbacks while modern formats continue to grow.

Frequently Asked Questions

Should every image have an AVIF version?

No. Generate it where the byte savings justify the extra encoding and fallback complexity, then compare quality at the image’s real display size.

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

What does a high-DPR screen change?

It can benefit from a candidate with more physical pixels than the CSS width, but only when that extra detail is visible and the added transfer is justified.

Can CSS alone make an oversized image efficient?

No. CSS can scale the display, but the browser may still download an oversized source. Use width candidates with srcset and an accurate sizes hint.

Quick Recap

SaleBestseller No. 1
HTML and CSS: Design and Build Websites
HTML and CSS: Design and Build Websites
HTML CSS Design and Build Web Sites; Comes with secure packaging; It can be a gift option
$14.94
SaleBestseller No. 3
SaleBestseller No. 4
Web Design with HTML, CSS, JavaScript and jQuery Set
Web Design with HTML, CSS, JavaScript and jQuery Set
Brand: Wiley; Set of 2 Volumes
$35.05

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.