Snippets Gallery

Bootstrap 5 Expanding Image Gallery on Hover

An image gallery of five panels that expand smoothly on hover, tap or keyboard focus to reveal a caption.

Bootstrap 5 No jQuery Apr 2020 2.6K views

<section class="wdw-stage">
  <div class="container" style="max-width: 1100px">
    <div class="text-center mb-4">
      <span class="wdw-eyebrow">Gallery</span>
      <h2 class="wdw-heading display-6 mt-1 mb-2">Five places worth the trip</h2>
      <p class="wdw-muted mb-0">Hover, tap or focus a panel to expand it.</p>
    </div>
    <div class="eg-gallery d-flex flex-column flex-md-row gap-2 gap-md-3" id="egGallery" role="group" aria-label="Image gallery">
    <button type="button" class="eg-panel btn border-0 p-0 position-relative overflow-hidden rounded-4" aria-pressed="false" style="--eg-img:url('https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=crop&w=1000&q=70')">
      <span class="eg-label position-absolute bottom-0 start-0 end-0 p-3 d-flex flex-column text-start text-white"><span class="eg-num small fw-bold opacity-75">01</span><span class="eg-title fw-bold">Valley</span><span class="eg-sub small">Yosemite, USA</span></span>
    </button>
    <button type="button" class="eg-panel btn border-0 p-0 position-relative overflow-hidden rounded-4" aria-pressed="false" style="--eg-img:url('https://images.unsplash.com/photo-1469474968028-56623f02e42e?auto=format&fit=crop&w=1000&q=70')">
      <span class="eg-label position-absolute bottom-0 start-0 end-0 p-3 d-flex flex-column text-start text-white"><span class="eg-num small fw-bold opacity-75">02</span><span class="eg-title fw-bold">Ridge</span><span class="eg-sub small">Scottish Highlands</span></span>
    </button>
    <button type="button" class="eg-panel btn border-0 p-0 position-relative overflow-hidden rounded-4 is-active" aria-pressed="true" style="--eg-img:url('https://images.unsplash.com/photo-1441974231531-c6227db76b6e?auto=format&fit=crop&w=1000&q=70')">
      <span class="eg-label position-absolute bottom-0 start-0 end-0 p-3 d-flex flex-column text-start text-white"><span class="eg-num small fw-bold opacity-75">03</span><span class="eg-title fw-bold">Forest</span><span class="eg-sub small">Black Forest, DE</span></span>
    </button>
    <button type="button" class="eg-panel btn border-0 p-0 position-relative overflow-hidden rounded-4" aria-pressed="false" style="--eg-img:url('https://images.unsplash.com/photo-1501785888041-af3ef285b470?auto=format&fit=crop&w=1000&q=70')">
      <span class="eg-label position-absolute bottom-0 start-0 end-0 p-3 d-flex flex-column text-start text-white"><span class="eg-num small fw-bold opacity-75">04</span><span class="eg-title fw-bold">Lake</span><span class="eg-sub small">Dolomites, Italy</span></span>
    </button>
    <button type="button" class="eg-panel btn border-0 p-0 position-relative overflow-hidden rounded-4" aria-pressed="false" style="--eg-img:url('https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?auto=format&fit=crop&w=1000&q=70')">
      <span class="eg-label position-absolute bottom-0 start-0 end-0 p-3 d-flex flex-column text-start text-white"><span class="eg-num small fw-bold opacity-75">05</span><span class="eg-title fw-bold">Hills</span><span class="eg-sub small">Faroe Islands</span></span>
    </button>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.