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.
| Value | Effect |
|---|---|
source | Caps 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.
| Source | Request | Canvas without fill-max | Canvas with fill-max=source |
|---|---|---|---|
| 300×200 | w=400&h=400 | 400×400 | 300×200 |
| 300×200 | w=400&h=150 | 400×150 | 300×150 |
| 300×200 | w=400 | 400×267 | 300×200 |
| 532×800 | w=800&h=800 | 800×800 | 532×800 |
| 4200×2800 | w=400&h=400 | 400×400 | 400×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.
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.
Interactions
- Fit mode.
fill-maxonly applies withfit=fillmax, including whenfillmaxis reached through a fallback such asfit=facearea,fillmax. With any other fit mode, such asfit=fill, it is ignored. - Fill parameters.
fillandfill-colorfill the space that remains in the capped canvas, in the same way they fill the full canvas. Everyfillmode, includingblurandgradient, is sized from the capped canvas. - Padding. Padding added with the
padparameter comes out of the capped canvas, as it does out ofw×h. - Aspect ratio. When
aris combined with bothwandh, the canvas is the smallestarbox aroundw×h, capped at the smallestarbox around the source. This can be larger than the canvasarproduces on its own, which is sized around the fitted image. With only one ofworh, or with neither, the canvas thatarproduces applies.



