Image component dimensions
Scope: Next.js 16.x candidate, App Router, Cache Components disabled, TypeScript. Source walkthroughs and expected outcomes; no framework build or browser execution has been verified.
What you will learn
- Reserve layout space
- Choose meaningful alt text
Detail cover — partial JSX with import
import Image from "next/image";export function Cover() { return <Image src="/covers/moss.png" width={240} height={360} alt="" style={{ maxWidth: "100%", height: "auto" }} />; }A proportional decorative cover occupies reserved space and can shrink on narrow screens.
How it works
The numeric width and height describe intrinsic dimensions or their ratio, not a command that the CSS box must always be exactly that size. The example uses a 480 × 720 source and a 240 × 360 intrinsic ratio. CSS can shrink the rendered box while preserving the ratio. Static raster imports can provide dimensions automatically. Alternative text describes information conveyed by an image; a decorative cover next to an identical book title can use empty alt. If the cover itself conveys unique content, describe that content instead.
Static import — alternative component in app/
import Image from "next/image";import moss from "../public/covers/moss.png";export function Cover() { return <Image src={moss} alt="" style={{ width: 120, height: "auto" }} />; }The import supplies intrinsic dimensions; CSS sets a smaller displayed width. The actual optimizer and layout require framework/browser tests.
Common mistake
Using width 240 and height 240 for a 2:3 cover declares the wrong ratio and can distort or shift the layout. Do not invent alt text or repeat adjacent text just to fill the required prop.
Try it yourself
For a 600 × 900 cover, choose a proportional width of 180px and calculate height 270px. Explain what happens if CSS makes the image narrower.
Further reading
Next lesson: Responsive image sizes.