Build an image carousel with semantic HTML for the slides and native buttons for navigation, then use JavaScript to track and display the active slide. The example below wraps from the last image to the first, announces the current position to screen readers, and honors reduced-motion preferences.
Build the carousel markup
Give the carousel a visible heading and an accessible name. Represent the slides as a list, and use real buttons for previous and next. The images below have distinct alternative text; describe each image’s content and purpose, and avoid repeating a nearby caption in the alt text when it adds no information.
<section class="carousel" aria-labelledby="gallery-title">
<h2 id="gallery-title">Featured places</h2>
<ul class="carousel__slides">
<li class="carousel__slide">
<img src="images/coast.jpg" alt="Rocky coastline beneath a cloudy sky">
</li>
<li class="carousel__slide">
<img src="images/forest.jpg" alt="Sunlight falling across a forest path">
</li>
<li class="carousel__slide">
<img src="images/city.jpg" alt="City rooftops at sunset">
</li>
</ul>
<div class="carousel__controls">
<button type="button" class="carousel__previous" aria-label="Previous image">
Previous
</button>
<button type="button" class="carousel__next" aria-label="Next image">
Next
</button>
</div>
<p class="carousel__status" aria-live="polite" aria-atomic="true">
Item 1 of 3
</p>
</section>
The live region reports the new position without moving keyboard focus. If the visible buttons use icons instead of text, retain meaningful accessible labels such as “Previous image” and “Next image.”
Style the slides and controls
This layout shows one slide at a time. The images scale to the available width while retaining their proportions. The active class is controlled by JavaScript.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
.carousel {
max-width: 48rem;
margin-inline: auto;
}
.carousel__slides {
list-style: none;
margin: 0;
padding: 0;
}
.carousel__slide {
display: none;
}
.carousel__slide.is-active {
display: block;
}
.carousel__slide img {
display: block;
width: 100%;
height: auto;
}
.carousel__controls {
display: flex;
gap: 0.75rem;
margin-top: 1rem;
}
@media (prefers-reduced-motion: no-preference) {
.carousel__slide img {
animation: carousel-enter 180ms ease-out;
}
@keyframes carousel-enter {
from { opacity: 0.7; }
to { opacity: 1; }
}
}
@media (prefers-reduced-motion: reduce) {
.carousel__slide img {
animation: none;
scroll-behavior: auto;
}
}
The reduced-motion rule avoids non-essential animation for people who have requested less motion. If you add transitions elsewhere, apply the same preference to them.
Add JavaScript navigation
Place this script after the carousel markup or load it with defer. It wraps at both ends: next from the last slide returns to the first, and previous from the first returns to the last. Wrapping is a design choice, not a requirement; another valid choice is to disable the button at an endpoint.
const carousel = document.querySelector('.carousel');
const slides = Array.from(carousel.querySelectorAll('.carousel__slide'));
const previousButton = carousel.querySelector('.carousel__previous');
const nextButton = carousel.querySelector('.carousel__next');
const status = carousel.querySelector('.carousel__status');
let activeIndex = 0;
function showSlide(index) {
activeIndex = (index + slides.length) % slides.length;
slides.forEach((slide, slideIndex) => {
const isActive = slideIndex === activeIndex;
slide.classList.toggle('is-active', isActive);
slide.hidden = !isActive;
});
status.textContent = `Item ${activeIndex + 1} of ${slides.length}`;
}
previousButton.addEventListener('click', () => {
showSlide(activeIndex - 1);
});
nextButton.addEventListener('click', () => {
showSlide(activeIndex + 1);
});
showSlide(activeIndex);
The script updates the displayed item and the polite status message, but it does not move focus. A user can activate next or previous repeatedly without having focus unexpectedly sent to a slide.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Optional: add direct slide pickers
Picker buttons let visitors jump to a particular slide. Give each a specific accessible name and indicate the selected slide, for example with aria-current="true". Add the following markup inside the carousel:
<div class="carousel__pickers" aria-label="Choose an image">
<button type="button" aria-label="Show image 1">1</button>
<button type="button" aria-label="Show image 2">2</button>
<button type="button" aria-label="Show image 3">3</button>
</div>
Then add this after the earlier JavaScript. Each picker is a separate tab stop, which can make keyboard navigation longer as the number of slides grows.
const pickers = Array.from(carousel.querySelectorAll('.carousel__pickers button'));
function showSlide(index) {
activeIndex = (index + slides.length) % slides.length;
slides.forEach((slide, slideIndex) => {
const isActive = slideIndex === activeIndex;
slide.classList.toggle('is-active', isActive);
slide.hidden = !isActive;
});
pickers.forEach((picker, pickerIndex) => {
if (pickerIndex === activeIndex) {
picker.setAttribute('aria-current', 'true');
} else {
picker.removeAttribute('aria-current');
}
});
status.textContent = `Item ${activeIndex + 1} of ${slides.length}`;
}
pickers.forEach((picker, index) => {
picker.addEventListener('click', () => showSlide(index));
});
Use one version of showSlide: if you add the pickers, replace the earlier function with this one so the status, slides, and selected picker stay in sync. A tabbed picker pattern can reduce tab stops, but it also requires implementing the expected tab-key behavior correctly.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Should you use JavaScript or CSS-only carousel features?
MDN documents CSS carousel techniques built around a scroll container and features such as scroll-snap-type, ::scroll-button(), ::scroll-marker-group, and ::scroll-marker. Scroll snapping can help scrolling settle at slide boundaries, and MDN’s examples include responsive carousels that show multiple items. The newer generated scroll buttons and markers are not a safe assumption for every target browser: check compatibility for the browsers your audience uses before relying on them.
| Consideration | JavaScript-controlled carousel | CSS carousel features |
|---|---|---|
| Browser support | Choose JavaScript when you need behavior across your supported browser set; test the implementation in that set. | Check compatibility for the specific CSS features and target browsers; support varies by feature. |
| State and behavior | Useful when you need explicit active-slide state, custom transitions, or behavior beyond scrolling. | Can provide scrolling, snapping, and generated navigation without custom JavaScript state for simpler cases. |
| Multiple items per view | Possible, but layout and the meaning of the active item are decisions you must implement. | Scroll-container layouts can show multiple items, including responsive examples documented by MDN. |
| Accessibility responsibilities | You still need semantic structure, named controls, keyboard access, appropriate announcements, and considered motion. | CSS does not make a carousel automatically accessible; provide semantics and check the behavior with your target assistive technologies. |
| Communicating the current item | A polite live region can announce the current position; picker controls can also expose selection. | Decide how users will identify the current item and ensure the controls and markers have meaningful names. |
MDN cautions that carousels can be brittle and challenging to implement with JavaScript. Its CSS approach can simplify scrolling, but choose based on required behavior and verified browser support, not on an assumption that either method is automatically accessible.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteAccessibility decisions to make before shipping
- Name the carousel and slides. A visible heading can label the containing section; provide slide names where they help users understand each item.
- Keep controls operable and predictable. Use native buttons, keep keyboard focus on the activated control during previous/next navigation, and make icon-only controls understandable to assistive technology.
- Announce manual changes. A polite live region such as “Item 2 of 5” informs screen-reader users of the current item without shifting focus.
- Be deliberate about rotation. If you add automatic rotation, provide a stop/restart control and put it first in the carousel’s tab sequence. Stop rotation when keyboard focus enters or the pointer hovers, and do not restart after focus has entered until the user explicitly asks.
- Respect motion preferences. Use
prefers-reduced-motionto remove or minimize non-essential movement. - Consider picker complexity. A group of individual picker buttons adds a tab stop per item; only use a tabbed-picker interaction if you can implement its keyboard behavior correctly.
Troubleshoot common problems
Every slide is visible
Check that the CSS hides inactive slides and that JavaScript applies is-active only to the selected item. The sample also sets the native hidden property on inactive slides.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
The buttons do nothing
Confirm the script runs after the carousel exists, the selectors match the markup, and the controls are inside the carousel section. Check the browser console for a null selector or syntax error.
The status announces the wrong count
Ensure all slide items are inside .carousel__slides and that the pickers, if present, correspond one-for-one with slides. The example computes the total from the slide list.
The next button fails at the last slide
The supplied function wraps the index with modulo arithmetic. If you replace it with endpoint disabling, update button disabled states whenever the active index changes and test both ends.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Keyboard focus jumps after a change
Do not call focus() on the new slide as part of ordinary previous/next navigation. Update the slide and status while leaving focus on the button the user activated.
Or skip the browser setup
If the task is to capture a finished carousel page rather than build its interaction, ScreenshotNeo can return a screenshot from one GET request. Its clean-shot process accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. It also offers an MCP server for AI agents, with take_screenshot, get_page_info, and capture_pdf tools.
Example cURL request (replace the sample URL with the page you want to capture):
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for response details and options. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Frequently Asked Questions
Does this carousel automatically rotate?
No. It changes slides only when a visitor activates a previous, next, or optional picker button.
Can one carousel show more than one image at a time?
Yes. The example uses one visible slide, but the layout can be adapted to show multiple items; define clearly what navigation advances and how the current position is communicated.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

