gohugoio/hugo · error
must provide Width and Height
Error message
must provide Width and Height
What it means
For the Crop, Fill, and Fit actions Hugo needs an exact target box, so both width and height must be supplied. The switch at config.go:319-322 returns this error when either dimension is zero for those actions.
Solutions
- Supply both width and height for Crop/Fill/Fit, e.g. `{{ $img.Fill "300x200" }}`.
- Switch to `.Resize` if you want aspect-ratio-preserving scaling with a single dimension.
- Re-check the action semantics: Resize needs one, Crop/Fill/Fit need both.
Example fix
{{/* before */}}
{{ $img.Fill "300x" }}
{{/* after */}}
{{ $img.Fill "300x200" }} Defensive patterns
Strategy: validation
Validate before calling
switch action {
case "crop", "fill", "fit":
if width == 0 || height == 0 { return errors.New("must provide Width and Height") }
} Prevention
- Crop/Fill/Fit always need both dimensions.
- Use Resize when you want aspect-ratio-preserving single-dimension scaling.
When it happens
Trigger: Calling `.Crop`, `.Fill`, or `.Fit` with only one dimension, e.g. `{{ $img.Crop "100x" }}` or `{{ $img.Fit "q80" }}` (no box at all).
Common situations: Assuming Crop/Fill/Fit preserve aspect ratio like Resize (they don't — they need a box); forgetting the height token; passing only a `q` token.
Related errors
- invalid image dimensions
- must provide Width or Height
- quality ranges from 1 to 100 inclusive
- width or height are not supported for this action
- 'pager size' must be a positive integer
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/fc75e83b868a6e5f.
Report an issue: GitHub.
Appendix: source
Thrown at resources/images/config.go:321
if len(widthHeight) == 2 {
second := widthHeight[1]
if second != "" {
c.Height, err = strconv.Atoi(second)
if err != nil {
return c, err
}
}
}
} else {
return c, errors.New("invalid image dimensions")
}
}
}
switch c.Action {
case ActionCrop, ActionFill, ActionFit:
if c.Width == 0 || c.Height == 0 {
return c, errors.New("must provide Width and Height")
}
case ActionResize:
if c.Width == 0 && c.Height == 0 {
return c, errors.New("must provide Width or Height")
}
default:
if c.Width != 0 || c.Height != 0 {
return c, errors.New("width or height are not supported for this action")
}
}
if err := c.init(defaults.Config, sourceFormat); err != nil {
return c, err
}
if mainImageVersionNumber > 0 {
options = append(options, strconv.Itoa(mainImageVersionNumber))
}View on GitHub (pinned to 52c9bd7908)