Image Dimensions
Injects width/height attributes on images from disk metadata at build time.
The imageDimensions feature reads image file headers at build time and injects width and height attributes onto local <img> elements, preventing Cumulative Layout Shift (CLS) by letting the browser reserve space before the image loads.
Functional since zfb next.38
Through zfb 0.1.0-next.35 this feature was a no-op for public-directory absolute paths — an image such as :
export default defineConfig({
markdown: {
features: {
imageDimensions: {},
},
},
});Behavior
For each image element, the feature:
Skips elements that already carry a
widthorheightattribute.Ignores remote URLs (
http:,/ / https:,/ / /) and/ data:URLs.Resolves the
srcto an absolute file path on disk.For raster formats, reads only the image file header and injects the resolved dimensions.
For SVG, reads the intrinsic size from the markup instead of a header probe: an explicit
width/heightpair when present, otherwise theviewBox.Emits a build warning if the file is missing or unrecognized.
Supported formats: PNG, JPEG, GIF, WebP, AVIF (header-probed), and SVG (dimensions read from markup, not a header probe).
Path resolution
| Path form | Resolves against |
|---|---|
Absolute (/) | the public directory |
Relative (.) | the markdown file's directory |
Remote / data: | skipped silently |
Options
| Option | Default | Description |
|---|---|---|
skipRemote | true | When false, remote images are probed during the build instead of being skipped. |
Syntax
A standard markdown image is all that is required — no special syntax:
The output for a 400×300 PNG is:
<img src="/img/hero.png" alt="Hero image" width="400" height="300" />