{
  "format": "putcode/playground@1",
  "id": "2e493f66-a202-4740-9dae-b1a19ee3185f",
  "url": "https://putcode.dev/u/mighil/s/gk9eaejqgx",
  "title": "Responsive image carousel",
  "description": "A self-contained, responsive image carousel with smooth sliding, previous/next controls, clickable pagination dots, and optional autoplay. Replace the sample image sources with your own image URLs.",
  "category": "layouts",
  "tags": [
    "carousel",
    "images",
    "slideshow",
    "responsive",
    "javascript"
  ],
  "visibility": "public",
  "status": "published",
  "revision": 2,
  "author": "mighil",
  "forked_from": null,
  "created_at": "2026-12-02T14:33:46.614Z",
  "updated_at": "2026-12-02T14:34:34.922Z",
  "published_at": "2026-12-02T14:34:34.922Z",
  "source": {
    "html": "<section class=\"image-carousel\" aria-label=\"Image gallery\">\n  <div class=\"carousel-viewport\">\n    <div class=\"carousel-track\">\n      <figure class=\"carousel-slide\"><img src=\"https://picsum.photos/id/1015/1200/700\" alt=\"Mountain landscape\"></figure>\n      <figure class=\"carousel-slide\"><img src=\"https://picsum.photos/id/1016/1200/700\" alt=\"Forest landscape\"></figure>\n      <figure class=\"carousel-slide\"><img src=\"https://picsum.photos/id/1018/1200/700\" alt=\"Mountain lake\"></figure>\n      <figure class=\"carousel-slide\"><img src=\"https://picsum.photos/id/1020/1200/700\" alt=\"Coastal landscape\"></figure>\n    </div>\n  </div>\n  <button class=\"carousel-button carousel-prev\" type=\"button\" aria-label=\"Previous image\"><span aria-hidden=\"true\">&#10094;</span></button>\n  <button class=\"carousel-button carousel-next\" type=\"button\" aria-label=\"Next image\"><span aria-hidden=\"true\">&#10095;</span></button>\n  <div class=\"carousel-dots\" aria-label=\"Choose an image\"></div>\n  <p class=\"carousel-status\" aria-live=\"polite\"></p>\n</section>",
    "css": ".image-carousel {\n  --carousel-radius: 16px;\n  position: relative;\n  width: min(100%, 760px);\n  margin: 24px auto;\n  overflow: hidden;\n  border-radius: var(--carousel-radius);\n  background: #171717;\n  box-shadow: 0 12px 32px rgba(0,0,0,.18);\n}\n.carousel-viewport { width: 100%; overflow: hidden; }\n.carousel-track {\n  display: flex;\n  transition: transform 480ms cubic-bezier(.22,.7,.25,1);\n  will-change: transform;\n}\n.carousel-slide { flex: 0 0 100%; min-width: 0; margin: 0; aspect-ratio: 16/9; }\n.carousel-slide img { display: block; width: 100%; height: 100%; object-fit: cover; }\n.carousel-button {\n  position: absolute; top: 50%; z-index: 2;\n  display: grid; width: 44px; height: 44px; place-items: center;\n  transform: translateY(-50%); border: 1px solid rgba(255,255,255,.25);\n  border-radius: 50%; color: #fff; background: rgba(0,0,0,.58);\n  font: inherit; font-size: 18px; cursor: pointer;\n  transition: background 160ms ease, scale 160ms ease;\n}\n.carousel-button:hover { background: rgba(0,0,0,.85); scale: 1.06; }\n.carousel-button:focus-visible, .carousel-dots button:focus-visible {\n  outline: 3px solid #fff; outline-offset: 3px;\n}\n.carousel-prev { left: 14px; }\n.carousel-next { right: 14px; }\n.carousel-dots {\n  position: absolute; right: 0; bottom: 14px; left: 0;\n  display: flex; justify-content: center; gap: 8px;\n}\n.carousel-dots button {\n  width: 9px; height: 9px; padding: 0; border: 0; border-radius: 99px;\n  background: rgba(255,255,255,.58); cursor: pointer;\n  transition: width 180ms ease, background 180ms ease;\n}\n.carousel-dots button[aria-current=\"true\"] { width: 24px; background: #fff; }\n.carousel-status {\n  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;\n  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;\n}\n@media (max-width: 520px) {\n  .carousel-button { width: 36px; height: 36px; font-size: 15px; }\n  .carousel-prev { left: 9px; } .carousel-next { right: 9px; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .carousel-track, .carousel-button, .carousel-dots button { transition: none; }\n}",
    "js": "(() => {\n  const carousel = document.querySelector(\".image-carousel\");\n  if (!carousel) return;\n  const track = carousel.querySelector(\".carousel-track\");\n  const slides = Array.from(carousel.querySelectorAll(\".carousel-slide\"));\n  const dotsContainer = carousel.querySelector(\".carousel-dots\");\n  const status = carousel.querySelector(\".carousel-status\");\n  const previous = carousel.querySelector(\".carousel-prev\");\n  const next = carousel.querySelector(\".carousel-next\");\n  if (!slides.length) return;\n\n  let currentIndex = 0;\n  let autoplayId;\n\n  const dots = slides.map((_, index) => {\n    const dot = document.createElement(\"button\");\n    dot.type = \"button\";\n    dot.setAttribute(\"aria-label\", `Show image ${index + 1}`);\n    dot.addEventListener(\"click\", () => { showSlide(index); restartAutoplay(); });\n    dotsContainer.appendChild(dot);\n    return dot;\n  });\n\n  function showSlide(index) {\n    currentIndex = (index + slides.length) % slides.length;\n    track.style.transform = `translateX(-${currentIndex * 100}%)`;\n    dots.forEach((dot, i) => {\n      if (i === currentIndex) dot.setAttribute(\"aria-current\", \"true\");\n      else dot.removeAttribute(\"aria-current\");\n    });\n    status.textContent = `Image ${currentIndex + 1} of ${slides.length}`;\n  }\n\n  function stopAutoplay() { window.clearInterval(autoplayId); }\n  function startAutoplay() {\n    stopAutoplay();\n    if (slides.length > 1) autoplayId = window.setInterval(() => showSlide(currentIndex + 1), 4000);\n  }\n  function restartAutoplay() { startAutoplay(); }\n\n  previous.addEventListener(\"click\", () => { showSlide(currentIndex - 1); restartAutoplay(); });\n  next.addEventListener(\"click\", () => { showSlide(currentIndex + 1); restartAutoplay(); });\n  carousel.addEventListener(\"mouseenter\", stopAutoplay);\n  carousel.addEventListener(\"mouseleave\", startAutoplay);\n  carousel.addEventListener(\"focusin\", stopAutoplay);\n  carousel.addEventListener(\"focusout\", startAutoplay);\n\n  showSlide(0);\n  startAutoplay();\n})();"
  }
}