Dev Helpers
← Back

Captioned figure with sizes

Place this file at components/CaptionedFigureWithSizes.tsx in an App Router project. Provide public/studio.jpg or pass your own image source.

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>
  );
}