Diagnosing Missing srcset and sizes in Hugo Pipes to Eliminate Cumulative Layout Shift
A step‑by‑step diagnostic guide for Hugo sites where images lack srcset and sizes, causing cumulative layout shift. Covers template pipeline checks, Hugo Extended requirement, config fixes, and verification with Lighthouse.
27 Jul 2026, 05:23 UTC

Recognizable Condition
Pages built with Hugo render <img> tags that lack srcset and sizes attributes. Browsers cannot reserve space for the image, so content jumps when the image loads — a measurable Cumulative Layout Shift (CLS) above the 0.1 threshold.
Cause / Diagnostic Table
| Symptom | Likely Cause | Diagnostic Check |
|---|---|---|
No srcset or sizes in page source | Template does not invoke Hugo Pipes Resize, Fit, or Fill filters | Search templates for resources.Get followed by a pipe chain; verify a resize operation is present |
| Images served at original dimensions only | ResolveResources disabled in config.toml or missing mediaTypes entry | Check config.toml for enableGitInfo = true and build.writeStats = true; ensure imaging.resampleFilter is set |
WEBP/AVIF output missing despite .SrcSet call | Standard Hugo binary used instead of Hugo Extended | Run hugo version and confirm "extended" appears in the output |
Ordered Checks
- Inspect the image pipeline in the template. Open the layout file (e.g.,
layouts/_default/single.html) and locate the image handling block. It should resemble:
If the pipe chain stops at{{ $src := resources.Get .File.Path }} {{ $img := $src | resources.Resize "800x" | resources.Fill "800x450" }} <img src="{{ $img.RelPermalink }}" srcset="{{ $img.SrcSet }}" sizes="(max-width: 800px) 100vw, 800px" alt="{{ .Title }}">resources.Get, the resize step is missing. - Confirm
ResolveResourcesis enabled. Inconfig.toml(orconfig.yaml) ensure:
Absence of these settings can prevent resource resolution.[build] writeStats = true [imaging] resampleFilter = "Lanczos" - Verify Hugo Extended binary. Run in the project root:
Expected output includeshugo versionextended(e.g.,hugo v0.124.0+extended linux/amd64). Without it, WEBP, AVIF, and SVG codecs are unavailable. - Generate
srcsetandsizesattributes. After a successful resize, call.SrcSeton the processed resource and add asizesattribute that matches your CSS breakpoints. Example for a two‑column layout:sizes="(min-width: 1200px) 50vw, 100vw" - Clear the build cache and rebuild. Stale resources can hide fixes. Execute:
Run from the site root; this removeshugo --cleanDestinationDirpublic/and forces a fresh pipeline pass.
Fixes Tied to Findings
- Missing resize pipe → Insert
| resources.Resize "800x"(orFit/Fill) before rendering the<img>tag. - ResolveResources disabled → Add the
[build]and[imaging]sections shown above; restarthugo server. - Standard Hugo binary → Install Hugo Extended (e.g.,
brew install hugoon macOS or download theextendedtarball from GitHub releases). Replace the binary in your PATH. - Incorrect
sizesvalue → Alignsizeswith actual CSS media queries; test with Chrome DevTools device toolbar.
Escalation Criteria
If CLS remains above 0.1 after completing the checks:
- Audit every custom image shortcode (e.g.,
{{< figure >}}) for missing pipeline calls. - Confirm that all image formats required (WEBP, AVIF) are listed under
[mediaTypes]in config. - Run
hugo --gc --cleanDestinationDirto garbage‑collect unused resources. - Profile with Lighthouse (Chrome DevTools → Lighthouse → Performance) and note the “Avoid large layout shifts” audit. Persistent shifts may indicate CSS‑only layout issues (e.g., missing aspect‑ratio boxes) rather than Hugo pipeline problems.
Verification Steps
- Start the development server:
hugo server -D(run in project root, no elevated permissions). - Open the rendered page, view source, and search for
srcset=andsizes=on content images. - Run Lighthouse or web.dev/measure on the live URL; confirm CLS < 0.1 and that the “Properly size images” audit passes.
Limitations
Hugo Pipes image processing for modern formats (WEBP, AVIF, SVG) requires the Hugo Extended binary; the standard build cannot transcode these formats. The diagnostic steps assume a single‑language site; multilingual setups may need per‑language resource resolution.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.