Open this example in the interactive library
Source code
// components/CaptionedFigureWithSizes.tsx
import Image from "next/image";
export default function CaptionedFigureWithSizes({
src = "/studio.jpg",
alt = "Inside the studio",
}: { src?: string; alt?: string } = {}) {
return (
<figure>
<Image
src={src}
alt={alt}
width={800}
height={600}
sizes="(max-width: 640px) 90vw, 480px"
style={{ width: "min(100%,480px)", height: "auto" }}
/>
<figcaption>{alt}</figcaption>
</figure>
);
}
