---
title: "Gallery Item"
description: "Presents one image with a caption and enlarged-view action - the picture opens a large view in a native modal dialog."
slug: "gallery-item"
---

import { DocPage, PageHeader, SkillPanel, SourceFiles, DocLink, SkillField, SkillText, SkillRow, ApiPill } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="gallery-item" title="Gallery Item" component="gallery-item">
  Presents one image with a caption and enlarged-view action - the picture opens a large view in a native modal dialog. Part of the <DocLink href="website-media.html">Media</DocLink> blocks.
</PageHeader>

<SkillPanel component="gallery-item">
  <SkillField label="Native basis">
<SkillText>A <code>&lt;figure&gt;</code>: a <code>&lt;button commandfor command="show-modal"&gt;</code> around the thumbnail, a <code>&lt;figcaption&gt;</code>, and a <code>&lt;dialog&gt;</code> with the large picture, its caption and a close button in a <code>&lt;form method="dialog"&gt;</code>.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure" title="media with its caption"><code>&lt;figure&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog" title="native dialog; method=&quot;dialog&quot; forms close it"><code>&lt;dialog&gt;</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#command" title="a button opens a dialog declaratively"><code>commandfor / command</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/@starting-style" title="entry animations"><code>@starting-style</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit" title="pictures crop instead of stretching"><code>object-fit</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.mk-gallery-item</code>
    <code>.mk-gallery-item-open</code>
    <code>.mk-gallery-item-zoom</code>
    <code>.mk-gallery-item-caption</code>
    <code>.mk-gallery-item-viewer</code>
    <code>.mk-gallery-item-viewer-inner</code>
    <code>.mk-gallery-item-close</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Data attributes">
<SkillText><code>data-variant</code>: <code>overlay</code>, <code>framed</code>.</SkillText>
  </SkillField>
</SkillPanel>

```html example label="Default" hint="The picture is a button with commandfor / command=&quot;show-modal&quot;: it opens the large view in a native modal <dialog> (focus trap, Escape, backdrop - all built in). The close button sits in a method=&quot;dialog&quot; form. Click a picture." previewStyle="align-items:stretch;"
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 1.25rem; width: 100%">
  <figure class="mk-gallery-item">
    <button
      class="mk-gallery-item-open"
      type="button"
      commandfor="gi-1"
      command="show-modal"
      aria-label="Enlarge: Harbour at dawn"
    >
      <img src="images/photos/s-gal-harbour-800x600.webp" alt="Harbour at dawn" />
      <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
    </button>
    <figcaption class="mk-gallery-item-caption">Harbour at dawn <span>Lisbon, 2026</span></figcaption>
    <dialog class="mk-gallery-item-viewer" id="gi-1" aria-label="Harbour at dawn">
      <div class="mk-gallery-item-viewer-inner">
        <img src="images/photos/s-gal-harbour-1600x1200.webp" alt="Harbour at dawn" />
        <p>Harbour at dawn <span>Lisbon, 2026</span></p>
        <form method="dialog"
          ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
        ></form>
      </div>
    </dialog>
  </figure>
  <figure class="mk-gallery-item">
    <button
      class="mk-gallery-item-open"
      type="button"
      commandfor="gi-2"
      command="show-modal"
      aria-label="Enlarge: Hills after rain"
    >
      <img src="images/photos/s-gal-hills-800x600.webp" alt="Hills after rain" />
      <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
    </button>
    <figcaption class="mk-gallery-item-caption">Hills after rain <span>Sintra, 2026</span></figcaption>
    <dialog class="mk-gallery-item-viewer" id="gi-2" aria-label="Hills after rain">
      <div class="mk-gallery-item-viewer-inner">
        <img src="images/photos/s-gal-hills-1600x1200.webp" alt="Hills after rain" />
        <p>Hills after rain <span>Sintra, 2026</span></p>
        <form method="dialog"
          ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
        ></form>
      </div>
    </dialog>
  </figure>
  <figure class="mk-gallery-item">
    <button
      class="mk-gallery-item-open"
      type="button"
      commandfor="gi-3"
      command="show-modal"
      aria-label="Enlarge: Tram 28"
    >
      <img src="images/photos/s-gal-street-800x600.webp" alt="Tram 28" />
      <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
    </button>
    <figcaption class="mk-gallery-item-caption">Tram 28 <span>Alfama, 2025</span></figcaption>
    <dialog class="mk-gallery-item-viewer" id="gi-3" aria-label="Tram 28">
      <div class="mk-gallery-item-viewer-inner">
        <img src="images/photos/s-gal-street-1600x1200.webp" alt="Tram 28" />
        <p>Tram 28 <span>Alfama, 2025</span></p>
        <form method="dialog"
          ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
        ></form>
      </div>
    </dialog>
  </figure>
</div>
```

```html example label="Overlay" hint="data-variant='overlay': the caption slides over the picture on hover or keyboard focus." previewStyle="align-items:stretch;"
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 0.75rem; width: 100%">
  <figure class="mk-gallery-item" data-variant="overlay">
    <button
      class="mk-gallery-item-open"
      type="button"
      commandfor="gi-4"
      command="show-modal"
      aria-label="Enlarge: Morning market"
    >
      <img src="images/photos/s-gal-o1-800x600.webp" alt="Morning market" />
      <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
    </button>
    <figcaption class="mk-gallery-item-caption">Morning market <span>Porto</span></figcaption>
    <dialog class="mk-gallery-item-viewer" id="gi-4" aria-label="Morning market">
      <div class="mk-gallery-item-viewer-inner">
        <img src="images/photos/s-gal-o1-1600x1200.webp" alt="Morning market" />
        <p>Morning market <span>Porto</span></p>
        <form method="dialog"
          ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
        ></form>
      </div>
    </dialog>
  </figure>
  <figure class="mk-gallery-item" data-variant="overlay">
    <button
      class="mk-gallery-item-open"
      type="button"
      commandfor="gi-5"
      command="show-modal"
      aria-label="Enlarge: Blue hour"
    >
      <img src="images/photos/s-gal-o2-800x600.webp" alt="Blue hour" />
      <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
    </button>
    <figcaption class="mk-gallery-item-caption">Blue hour <span>Cascais</span></figcaption>
    <dialog class="mk-gallery-item-viewer" id="gi-5" aria-label="Blue hour">
      <div class="mk-gallery-item-viewer-inner">
        <img src="images/photos/s-gal-o2-1600x1200.webp" alt="Blue hour" />
        <p>Blue hour <span>Cascais</span></p>
        <form method="dialog"
          ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
        ></form>
      </div>
    </dialog>
  </figure>
  <figure class="mk-gallery-item" data-variant="overlay">
    <button
      class="mk-gallery-item-open"
      type="button"
      commandfor="gi-6"
      command="show-modal"
      aria-label="Enlarge: Lighthouse"
    >
      <img src="images/photos/s-gal-o3-800x600.webp" alt="Lighthouse" />
      <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
    </button>
    <figcaption class="mk-gallery-item-caption">Lighthouse <span>Cabo da Roca</span></figcaption>
    <dialog class="mk-gallery-item-viewer" id="gi-6" aria-label="Lighthouse">
      <div class="mk-gallery-item-viewer-inner">
        <img src="images/photos/s-gal-o3-1600x1200.webp" alt="Lighthouse" />
        <p>Lighthouse <span>Cabo da Roca</span></p>
        <form method="dialog"
          ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
        ></form>
      </div>
    </dialog>
  </figure>
</div>
```

```html example label="Framed" hint="data-variant='framed': a white print frame with a shadow, turned a little - it straightens on hover." previewStyle="align-items:stretch;"
<div style="display: flex; flex-wrap: wrap; gap: 2rem; justify-content: center; padding: 1rem; width: 100%">
  <div style="width: 14rem"
    ><figure class="mk-gallery-item" data-variant="framed">
      <button
        class="mk-gallery-item-open"
        type="button"
        commandfor="gi-7"
        command="show-modal"
        aria-label="Enlarge: Summer, 1998"
      >
        <img src="images/photos/s-gal-f1-800x600.webp" alt="Summer, 1998" />
        <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
      </button>
      <figcaption class="mk-gallery-item-caption">Summer, 1998 <span>Algarve</span></figcaption>
      <dialog class="mk-gallery-item-viewer" id="gi-7" aria-label="Summer, 1998">
        <div class="mk-gallery-item-viewer-inner">
          <img src="images/photos/s-gal-f1-1600x1200.webp" alt="Summer, 1998" />
          <p>Summer, 1998 <span>Algarve</span></p>
          <form method="dialog"
            ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
          ></form>
        </div>
      </dialog> </figure
  ></div>
  <div style="width: 14rem"
    ><figure class="mk-gallery-item" data-variant="framed">
      <button
        class="mk-gallery-item-open"
        type="button"
        commandfor="gi-8"
        command="show-modal"
        aria-label="Enlarge: The old house"
      >
        <img src="images/photos/s-gal-f2-800x600.webp" alt="The old house" />
        <span class="mk-gallery-item-zoom" aria-hidden="true"><i data-lucide="maximize-2"></i></span>
      </button>
      <figcaption class="mk-gallery-item-caption">The old house <span>Évora</span></figcaption>
      <dialog class="mk-gallery-item-viewer" id="gi-8" aria-label="The old house">
        <div class="mk-gallery-item-viewer-inner">
          <img src="images/photos/s-gal-f2-1600x1200.webp" alt="The old house" />
          <p>The old house <span>Évora</span></p>
          <form method="dialog"
            ><button class="mk-gallery-item-close" aria-label="Close"><i data-lucide="x"></i></button
          ></form>
        </div>
      </dialog> </figure
  ></div>
</div>
```

<SourceFiles component="gallery-item" section="css" />

</DocPage>
