DocsFiles & media
On this page

Add responsive images

Resize images and serve responsive sources.

Use Frontbacked image resizing when a theme needs smaller, cropped, or format-optimized versions of uploaded images. The browser still receives a normal image URL, but the URL points to a resized Frontbacked image.

Image resizing only works for Frontbacked-owned images, such as post upload file fields, site assets, logos, and theme assets. External image URLs are not transformed. When a source is external or invalid, the helper returns an empty string and logs a warning in development.

Basic Resize

Frontbacked.image.resize(source, options) accepts either a URL string or a file metadata object returned from Frontbacked uploads.

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

Use it in an attribute binding through a small wrapper function:

index.html
js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

FQL function calls pass the resolved value into the registered function. In the example above, $.image.resizeProductThumb() passes the current list item's image value to resizeProductThumb.

Responsive Images

Use Frontbacked.image.srcset(source, entries) when the browser should choose the best width for the viewport.

index.html
js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

Each srcset entry uses the same options as resize. Entries with a w value are emitted as width descriptors, such as 640w.

Options

At least one of w/width or h/height is required.

OptionValuesPurpose
w or width16 to 2400Target width in CSS pixels.
h or height16 to 2400Target height in CSS pixels.
fitscale-down, cover, crop, contain, pad, squeezeControls how the image fits the requested box. Defaults to scale-down.
f or formatauto, webp, avif, jpeg, pngOutput format. Use auto for normal theme images.
q or quality40 to 90Output quality. Defaults to 82.
dpr1 to 2Device pixel ratio multiplier for sharper images on dense screens.
g or gravityauto, center, top, bottom, left, right, top-left, top-right, bottom-left, bottom-right, faceCrop focus for cover and crop.
bg or background#ffffff or a simple color nameBackground color for fit: "pad".
enlargetrue or falseAllows upscaling. Defaults to false.

Continue with Prepare images for your layout.