Accessible slideshow
Real previous and next buttons, slides named for screen readers in a polite live region, and no autoplay, so there is nothing to pause.
CL-0065 fixesChecked 2026-10-151. The prompt
Not yet run against a named assistant · 99 words · CC-BY-4.0Write an image slideshow in plain JavaScript with no autoplay. Put each slide in a figure with role="group", aria-roledescription="slide" and an aria-label such as "2 of 5", inside a wrapper with aria-live="polite" and aria-atomic="false". Give the container aria-roledescription="carousel" and a label that does not contain the word carousel. Give every image its own alt text. Use real <button> elements for Previous and Next, wrap at both ends, and hide inactive slides with the hidden attribute. Add a short fade that a prefers-reduced-motion: reduce media query switches off. Support several slideshows on one page, and add an MIT licence comment.
What a one-line prompt gets you
Representative output for “an image slideshow in JavaScript” and nothing else, written by the editors to show the pattern. It runs. It also leaves these gaps.
- 1 It changes every three seconds and cannot be stopped.WCAG 2.2 success criterion 2.2.2 requires a way to pause, stop or hide auto-updating content that starts automatically alongside other content, and the W3C notes there is no five-second exception for auto-updating. The reviewed slideshow does not autoplay.Prompt line: “Write an image slideshow in plain JavaScript with no autoplay.”
- 2 There are no controls.A reader who wants the next picture can only wait for it. The reviewed slideshow has native Previous and Next buttons that wrap at both ends.Prompt line: “Use real <button> elements for Previous and Next, wrap at both ends.”
- 3 Screen readers are not told anything changed.Swapping the src of one image announces nothing. The reviewed slides sit in a polite live region and each has a name such as 2 of 3, as the WAI-ARIA carousel pattern describes.Prompt line: “Inside a wrapper with aria-live="polite" and aria-atomic="false".”
- 4 The images have no alt text.Only file names exist, and the alt never changes when the picture does. The reviewed markup gives every image its own description.Prompt line: “Give every image its own alt text.”
- 5 It carries no licence.Nothing records who wrote it or on what terms. The reviewed script starts with an MIT licence line and a credit.Prompt line: “Add an MIT licence comment.”
Install it
Questions and answers
Has this prompt been tested with an assistant?
Not yet. The editors wrote the prompt to describe the reviewed code, which they wrote and tested with AI assistance and re-ran in a scripted DOM test on 2026-10-15. Nobody has run the prompt against a named assistant, so compare any answer with the code above.
Should a slideshow autoplay?
Not by default. WCAG 2.2 success criterion 2.2.2 requires a pause, stop or hide mechanism for auto-updating content that starts automatically and sits alongside other content. A slideshow that waits for the reader needs no such control.
Does pausing on hover count as a pause button?
Not on its own. The W3C Understanding document for 2.2.2 says content that stops only while focus rests on it, and restarts when focus moves away, is not a mechanism for the user to pause.
What if a client insists on autoplay?
Follow the WAI-ARIA carousel pattern: a button that stops and restarts rotation, first in the carousel's Tab order, with a label that changes to match its action; rotation that stops when keyboard focus enters and does not restart unless asked; rotation that stops on hover; and the live region set to off while rotating.
What does prefers-reduced-motion change here?
MDN describes the media feature as detecting a device setting to minimise non-essential motion, and notes that scaling or panning large objects can trigger vestibular discomfort. The only animation is a short fade, and the media query removes it for anyone who asked for less motion.
Why use the hidden attribute?
The WAI-ARIA carousel pattern warns that the screen reader experience is confusing when slides that are not visible are hidden incorrectly, for example by being displayed off-screen. The script hides inactive slides with the hidden attribute rather than moving them aside.
Why do the buttons keep focus?
The carousel pattern notes that activating the next and previous controls does not move focus, so a reader can press Next as many times as they like. The reviewed buttons only change which slide is visible.
Do slideshow images need alt text if they have captions?
Yes. The caption is shown to everyone; alt text replaces the image for readers who cannot see it. Write both, and do not repeat the caption word for word in the alt.
Can I use the slideshow on a commercial site?
Yes. The code is MIT licensed, so you can use and change it in paid work; keep the licence line or credit CodeLifter in your notices.
