Imgix APIsRendering APIFillFill Max

Fill Max

fill-max

The fill-max parameter keeps each side of the canvas of an image resized with fit=fillmax no larger than the source image. By default, fit=fillmax never enlarges the image, but it still pads the canvas out to the full w × h box. With fill-max=source, each side of the canvas is the smaller of the requested size and the source size, so a small image is never padded beyond its own dimensions.

ValueEffect
sourceCaps each axis of the canvas at the source image’s size. The value is case-insensitive.

When fill-max is absent, the canvas is the full box, as it is today. Any other value is ignored.

How the canvas is sized

With fill-max=source, the canvas is the smaller of the requested size and the source size on each axis: min(source width, w) × min(source height, h). The image itself is sized exactly as it is without the parameter. Only the padding around it changes.

The source size is measured after any rect crop. The cap is also applied in output pixels, so w and h are multiplied by dpr first.

SourceRequestCanvas without fill-maxCanvas with fill-max=source
300×200w=400&h=400400×400300×200
300×200w=400&h=150400×150300×150
300×200w=400400×267300×200
532×800w=800&h=800800×800532×800
4200×2800w=400&h=400400×400400×400

The last row shows the limit of the parameter. When the source is at least as large as the box on both axes, there is nothing to cap, so fill-max=source has no effect.

Because the canvas can be smaller than w × h, the output no longer always matches the requested dimensions. Don’t rely on exact dimensions for page layout when you use this parameter.

fit=fillmax pads the 300×200 source out to a 400×400 canvas
sandbox-demo
fill-max=source keeps the canvas at 300×200, with no padding
sandbox-demo

The cap applies to each axis on its own. When only one axis of the source is smaller than the box, the other axis stays at the requested size, and the padding shrinks on one axis only.

Without fill-max, the canvas is 400×150
sandbox-demo
fill-max=source narrows the canvas to 300×150
sandbox-demo

Interactions

  • Fit mode. fill-max only applies with fit=fillmax, including when fillmax is reached through a fallback such as fit=facearea,fillmax. With any other fit mode, such as fit=fill, it is ignored.
  • Fill parameters. fill and fill-color fill the space that remains in the capped canvas, in the same way they fill the full canvas. Every fill mode, including blur and gradient, is sized from the capped canvas.
  • Padding. Padding added with the pad parameter comes out of the capped canvas, as it does out of w × h.
  • Aspect ratio. When ar is combined with both w and h, the canvas is the smallest ar box around w × h, capped at the smallest ar box around the source. This can be larger than the canvas ar produces on its own, which is sized around the fitted image. With only one of w or h, or with neither, the canvas that ar produces applies.