Dev Helpers
← Back

Captioned responsive photo

Import and render <CaptionedResponsivePhoto /> in a React project. Provide public/studio.jpg or pass your own image source.

Open this example in the interactive library

Live preview

Source code

// components/CaptionedResponsivePhoto.tsx

export default function CaptionedResponsivePhoto({
  src = "/studio.jpg",
  caption = "Inside the studio",
}: { src?: string; caption?: string } = {}) {
  return (
    <figure>
      <img
        src={src}
        alt={caption}
        loading="lazy"
        style={{ maxWidth: "100%", height: "auto" }}
      />
      <figcaption>{caption}</figcaption>
    </figure>
  );
}