Implement a CSS-only carousel with accessible controls and no JavaScript.
- User
Implement a CSS-only carousel with accessible controls and no JavaScript.
Assistant
The user wants a CSS-only carousel with accessible controls and no JavaScript. This is an interesting challenge that requires using CSS techniques to simulate carousel behavior.
Key techniques for a CSS-only carousel:
- Use radio inputs for navigation (hidden radio buttons as controls)
- Use
:checkedpseudo-class to determine which slide is active - CSS counters or sibling selectors for slide indicators
- Smooth transitions between slides
- Accessible controls with proper ARIA labels
- Keyboard navigation (native to radio buttons)
Let me plan the implementation:
-
Structure:
- Radio inputs (one per slide) - these will be the navigation mechanism
- Labels styled as navigation dots/buttons
- Slide container with overflow hidden
- Slides that show/hide based on which radio is checked
-
Accessibility:
- Proper focus states
- ARIA labels on controls
- Visible focus indicators
- Screen reader announcements
-
Visual Design:
- No default template colors (avoid blue-purple gradients)
- High contrast
- Smooth animations
- Dynamic feel with hover effects
-
Features:
- Previous/Next arrows
- Dot indicators
- Auto-play is not possible without JS, but we can add a manual play/pause feeling
- Smooth slide transitions
Let me create a visually stunning carousel with:
- Dark theme with golden/amber accents
- Smooth sliding animations
- Dot indicators that respond to current slide
- Arrow buttons for prev/next
- Nice hover effects and transitions
- Multiple dynamic elements (background animations, hover effects, transitions)
I'll use the radio button hack technique where:
- Radio inputs are visually hidden but remain accessible
- Labels serve as the clickable controls
- The
:checkedselector drives the CSS state changes
CSS-Only Carousel Implementation
I'll create a visually stunning, fully accessible carousel using only CSS with the radio-button technique. The carousel features smooth sliding animations, keyboard navigation, dot indicators, and arrow controls.
Key techniques used:
- Radio inputs as state managers (hidden but keyboard-accessible)
:checkedpseudo-class to control slide visibility- CSS sibling selectors (
~) to cascade state changes scroll-snapfor touch-friendly scrolling fallback- Proper ARIA labels and focus states for accessibility
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS-Only Accessible Carousel</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } :root { --bg-dark: #0a0a0f; --bg-card: #14141f; --accent-gold: #d4a03c; --accent-copper: #c77b4a; --accent-teal: #2a9d8f; --text-light: #f0f0f5; --text-muted: #8888a0; } body { min-height: 100vh; background: var(--bg-dark); font-family: 'Segoe UI', system-ui, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; overflow-x: hidden; } /* Animated background */ body::before { content: ''; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: radial-gradient(ellipse at 20% 20%, rgba(212, 160, 60, 0.08) 0%, transparent 50%), radial-gradient(ellipse at 80% 80%, rgba(42, 157, 143, 0.08) 0%, transparent 50%), radial-gradient(ellipse at 50% 50%, rgba(199, 123, 74, 0.05) 0%, transparent 60%); animation: bgPulse 10s ease-in-out infinite; pointer-events: none; z-index: 0; } @keyframes bgPulse { 0%, 100% { opacity: 0.6; transform: scale(1); } 50% { opacity: 1; transform: scale(1.1); } } /* Floating particles */ .particles { position: fixed; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; overflow: hidden; z-index: 0; } .particle { position: absolute; width: 4px; height: 4px; background: var(--accent-gold); border-radius: 50%; opacity: 0.3; animation: float 15s infinite; } .particle:nth-child(1) { left: 10%; animation-delay: 0s; animation-duration: 12s; } .particle:nth-child(2) { left: 20%; animation-delay: 2s; animation-duration: 18s; } .particle:nth-child(3) { left: 35%; animation-delay: 4s; animation-duration: 14s; } .particle:nth-child(4) { left: 50%; animation-delay: 1s; animation-duration: 16s; } .particle:nth-child(5) { left: 65%; animation-delay: 3s; animation-duration: 13s; } .particle:nth-child(6) { left: 80%; animation-delay: 5s; animation-duration: 17s; } .particle:nth-child(7) { left: 90%; animation-delay: 2.5s; animation-duration: 15s; } @keyframes float { 0% { transform: translateY(100vh) rotate(0deg); opacity: 0; } 10% { opacity: 0.4; } 90% { opacity: 0.4; } 100% { transform: translateY(-100vh) rotate(720deg); opacity: 0; } } h1 { color: var(--text-light); font-size: clamp(1.8rem, 5vw, 2.5rem); font-weight: 300; margin-bottom: 10px; text-align: center; position: relative; z-index: 1; letter-spacing: 2px; } .subtitle { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 40px; text-align: center; position: relative; z-index: 1; } .subtitle span { color: var(--accent-gold); font-weight: 600; } /* Hide radio inputs visually but keep them accessible */ .carousel-radio { position: absolute; opacity: 0; pointer-events: none; } /* Carousel Container */ .carousel-container { position: relative; width: min(90vw, 900px); height: 500px; z-index: 1; } .carousel { position: relative; width: 100%; height: 100%; border-radius: 20px; overflow: hidden; background: var(--bg-card); box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5), 0 0 1px rgba(212, 160, 60, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.05); } /* Slides Track */ .slides-track { display: flex; height: 100%; transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1); } .slide { min-width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 40px; position: relative; overflow: hidden; } .slide-content { position: relative; z-index: 2; text-align: center; max-width: 600px; } .slide-icon { width: 80px; height: 80px; margin: 0 auto 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2rem; background: linear-gradient(135deg, var(--accent-gold), var(--accent-copper)); box-shadow: 0 10px 30px rgba(212, 160, 60, 0.3); animation: iconPulse 3s ease-in-out infinite; } @keyframes iconPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } } .slide-title { color: var(--text-light); font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 600; margin-bottom: 16px; } .slide-description { color: var(--text-muted); font-size: 1rem; line-height: 1.7; margin-bottom: 24px; } .slide-button { display: inline-block; padding: 14px 32px; background: linear-gradient(135deg, var(--accent-gold), var(--accent-copper)); color: var(--bg-dark); text-decoration: none; border-radius: 50px; font-weight: 600; font-size: 0.9rem; letter-spacing: 1px; text-transform: uppercase; transition: all 0.3s ease; box-shadow: 0 8px 25px rgba(212, 160, 60, 0.3); } .slide-button:hover { transform: translateY(-3px); box-shadow: 0 12px 35px rgba(212, 160, 60, 0.4); } /* Slide backgrounds */ .slide::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; opacity: 0.1; z-index: 1; } .slide-1::before { background: radial-gradient(circle at 30% 70%, var(--accent-gold) 0%, transparent 50%); } .slide-2::before { background: radial-gradient(circle at 70% 30%, var(--accent-teal) 0%, transparent 50%); } .slide-3::before { background: radial-gradient(circle at 50% 50%, var(--accent-copper) 0%, transparent 50%); } .slide-4::before { background: radial-gradient(circle at 20% 80%, #6366f1 0%, transparent 50%); } .slide-5::before { background: radial-gradient(circle at 80% 20%, #ec4899 0%, transparent 50%); } /* Animated shapes in slides */ .slide-shapes { position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 0; overflow: hidden; } .shape { position: absolute; border: 2px solid rgba(212, 160, 60, 0.15); border-radius: 50%; animation: shapeFloat 8s ease-in-out infinite; } .shape-1 { width: 200px; height: 200px; top: -50px; right: -50px; animation-delay: 0s; } .shape-2 { width: 150px; height: 150px; bottom: -30px; left: -30px; animation-delay: 2s; } .shape-3 { width: 100px; height: 100px; top: 50%; left: 10%; animation-delay: 4s; } @keyframes shapeFloat { 0%, 100% { transform: translate(0, 0) rotate(0deg); } 50% { transform: translate(10px, -20px) rotate(180deg); } } /* Radio checked states - move slides */ #slide1:checked ~ .carousel .slides-track { transform: translateX(0); } #slide2:checked ~ .carousel .slides-track { transform: translateX(-100%); } #slide3:checked ~ .carousel .slides-track { transform: translateX(-200%); } #slide4:checked ~ .carousel .slides-track { transform: translateX(-300%); } #slide5:checked ~ .carousel .slides-track { transform: translateX(-400%); } /* Dot Indicators */ .carousel-dots { display: flex; justify-content: center; gap: 12px; margin-top: 24px; position: relative; z-index: 1; } .dot-label { width: 14px; height: 14px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); cursor: pointer; transition: all 0.3s ease; border: 2px solid transparent; position: relative; } .dot-label:hover { background: rgba(255, 255, 255, 0.3); transform: scale(1.2); } .dot-label::before { content: ''; position: absolute; top: 50%; left: 50%; width: 6px; height: 6px; background: var(--accent-gold); border-radius: 50%; transform: translate(-50%, -50%) scale(0); transition: transform 0.3s ease; } /* Active dot states */ #slide1:checked ~ .carousel-dots .dot-label[for="slide1"], #slide2:checked ~ .carousel-dots .dot-label[for="slide2"], #slide3:checked ~ .carousel-dots .dot-label[for="slide3"], #slide4:checked ~ .carousel-dots .dot-label[for="slide4"], #slide5:checked ~ .carousel-dots .dot-label[for="slide5"] { background: transparent; border-color: var(--accent-gold); transform: scale(1.2); } #slide1:checked ~ .carousel-dots .dot-label[for="slide1"]::before, #slide2:checked ~ .carousel-dots .dot-label[for="slide2"]::before, #slide3:checked ~ .carousel-dots .dot-label[for="slide3"]::before, #slide4:checked ~ .carousel-dots .dot-label[for="slide4"]::before, #slide5:checked ~ .carousel-dots .dot-label[for="slide5"]::before { transform: translate(-50%, -50%) scale(1); } /* Arrow Navigation */ .arrow-label { position: absolute; top: 50%; transform: translateY(-50%); width: 50px; height: 50px; background: rgba(20, 20, 31, 0.8); border: 1px solid rgba(212, 160, 60, 0.3); border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; z-index: 10; backdrop-filter: blur(10px); } .arrow-label:hover { background: rgba(212, 160, 60, 0.2); border-color: var(--accent-gold); transform: translateY(-50%) scale(1.1); } .arrow-label:focus-visible { outline: 2px solid var(--accent-gold); outline-offset: 3px; } .arrow-label svg { width: 20px; height: 20px; stroke: var(--text-light); stroke-width: 2; fill: none; transition: stroke 0.3s ease; } .arrow-label:hover svg { stroke: var(--accent-gold); } .arrow-prev { left: -25px; } .arrow-next { right: -25px; } /* Position arrows inside on smaller screens */ @media (max-width: 1000px) { .arrow-prev { left: 15px; } .arrow-next { right: 15px; } .arrow-label { background: rgba(20, 20, 31, 0.9); } } /* Previous arrow logic - complex CSS sibling selectors */ #slide1:checked ~ .carousel .arrow-prev[for="slide5"], #slide2:checked ~ .carousel .arrow-prev[for="slide1"], #slide3:checked ~ .carousel .arrow-prev[for="slide2"], #slide4:checked ~ .carousel .arrow-prev[for="slide3"], #slide5:checked ~ .carousel .arrow-prev[for="slide4"] { pointer-events: auto; opacity: 1; } #slide1:checked ~ .carousel .arrow-next[for="slide2"], #slide2:checked ~ .carousel .arrow-next[for="slide3"], #slide3:checked ~ .carousel .arrow-next[for="slide4"], #slide4:checked ~ .carousel .arrow-next[for="slide5"], #slide5:checked ~ .carousel .arrow-next[for="slide1"] { pointer-events: auto; opacity: 1; } /* Slide counter */ .slide-counter { position: absolute; bottom: 20px; right: 25px; font-size: 0.85rem; color: var(--text-muted); z-index: 10; background: rgba(20, 20, 31, 0.7); padding: 8px 16px; border-radius: 20px; backdrop-filter: blur(10px); } .slide-counter .current { color: var(--accent-gold); font-weight: 600; font-size: 1.1rem; } #slide1:checked ~ .carousel .counter-slide::after { content: '1'; } #slide2:checked ~ .carousel .counter-slide::after { content: '2'; } #slide3:checked ~ .carousel .counter-slide::after { content: '3'; } #slide4:checked ~ .carousel .counter-slide::after { content: '4'; } #slide5:checked ~ .carousel .counter-slide::after { content: '5'; } /* Focus visible for accessibility */ .carousel-radio:focus-visible ~ .carousel .arrow-label[for="slide1"], .carousel-radio:focus-visible ~ .carousel .arrow-label[for="slide2"], .carousel-radio:focus-visible ~ .carousel .arrow-label[for="slide3"], .carousel-radio:focus-visible ~ .carousel .arrow-label[for="slide4"], .carousel-radio:focus-visible ~ .carousel .arrow-label[for="slide5"] { outline: 2px solid var(--accent-gold); outline-offset: 3px; } /* Keyboard focus highlight on dots */ .carousel-radio:focus-visible + .carousel-dots .dot-label { outline: 2px solid var(--accent-teal); outline-offset: 3px; } /* Progress bar animation */ .progress-bar { position: absolute; bottom: 0; left: 0; height: 3px; background: linear-gradient(90deg, var(--accent-gold), var(--accent-copper)); z-index: 10; transition: width 0.3s ease; } #slide1:checked ~ .carousel .progress-bar { width: 20%; } #slide2:checked ~ .carousel .progress-bar { width: 40%; } #slide3:checked ~ .carousel .progress-bar { width: 60%; } #slide4:checked ~ .carousel .progress-bar { width: 80%; } #slide5:checked ~ .carousel .progress-bar { width: 100%; } /* Instructions for keyboard users */ .keyboard-hint { margin-top: 30px; padding: 16px 24px; background: rgba(20, 20, 31, 0.6); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px; color: var(--text-muted); font-size: 0.85rem; text-align: center; position: relative; z-index: 1; backdrop-filter: blur(10px); } .keyboard-hint kbd { display: inline-block; padding: 4px 8px; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 4px; font-family: monospace; font-size: 0.8rem; color: var(--accent-gold); margin: 0 4px; } /* Responsive adjustments */ @media (max-width: 600px) { .carousel-container { height: 450px; } .slide { padding: 30px 20px; } .slide-icon { width: 60px; height: 60px; font-size: 1.5rem; } .arrow-label { width: 40px; height: 40px; } .keyboard-hint { display: none; } } </style> </head> <body> <!-- Floating Particles --> <div class="particles"> <div class="particle"></div> <div class="particle"></div> <div class="particle"></div> <div class="particle"></div> <div class="particle"></div> <div class="particle"></div> <div class="particle"></div> </div> <h1>Pure CSS Carousel</h1> <p class="subtitle">No JavaScript required — <span>fully accessible</span></p> <!-- Radio inputs for state management --> <input type="radio" name="carousel" id="slide1" class="carousel-radio" checked aria-label="Go to slide 1"> <input type="radio" name="carousel" id="slide2" class="carousel-radio" aria-label="Go to slide 2"> <input type="radio" name="carousel" id="slide3" class="carousel-radio" aria-label="Go to slide 3"> <input type="radio" name="carousel" id="slide4" class="carousel-radio" aria-label="Go to slide 4"> <input type="radio" name="carousel" id="slide5" class="carousel-radio" aria-label="Go to slide 5"> <div class="carousel-container"> <div class="carousel" role="region" aria-label="Image carousel" aria-roledescription="carousel"> <!-- Progress Bar --> <div class="progress-bar"></div> <!-- Slides Track --> <div class="slides-track"> <!-- Slide 1 --> <div class="slide slide-1" role="group" aria-roledescription="slide" aria-label="1 of 5"> <div class="slide-shapes"> <div class="shape shape-1"></div> <div class="shape shape-2"></div> <div class="shape shape-3"></div> </div> <div class="slide-content"> <div class="slide-icon">✦</div> <h2 class="slide-title">Elegant Design</h2> <p class="slide-description">Experience the beauty of pure CSS animations with smooth transitions and carefully crafted visual effects that bring your content to life.</p> <a href="#" class="slide-button">Explore More</a> </div> </div> <!-- Slide 2 --> <div class="slide slide-2" role="group" aria-roledescription="slide" aria-label="2 of 5"> <div class="slide-shapes"> <div class="shape shape-1"></div> <div class="shape shape-2"></div> <div class="shape shape-3"></div> </div> <div class="slide-content"> <div class="slide-icon">◈</div> <h2 class="slide-title">Zero JavaScript</h2> <p class="slide-description">Built entirely with HTML and CSS, this carousel proves that you don't always need JavaScript for interactive components.</p> <a href="#" class="slide-button">View Source</a> </div> </div> <!-- Slide 3 --> <div class="slide slide-3" role="group" aria-roledescription="slide" aria-label="3 of 5"> <div class="slide-shapes"> <div class="shape shape-1"></div> <div class="shape shape-2"></div> <div class="shape shape-3"></div> </div> <div class="slide-content"> <div class="slide-icon">⬡</div> <h2 class="slide-title">Fully Accessible</h2> <p class="slide-description">Navigate with keyboard, screen readers, or mouse. Proper ARIA labels and focus states ensure everyone can use this carousel.</p> <a href="#" class="slide-button">Learn More</a> </div> </div> <!-- Slide 4 --> <div class="slide slide-4" role="group" aria-roledescription="slide" aria-label="4 of 5"> <div class="slide-shapes"> <div class="shape shape-1"></div> <div class="shape shape-2"></div> <div class="shape shape-3"></div> </div> <div class="slide-content"> <div class="slide-icon">◇</div> <h2 class="slide-title">Smooth Animations</h2> <p class="slide-description">Powered by CSS transforms and cubic-bezier timing functions for buttery smooth 60fps animations on any device.</p> <a href="#" class="slide-button">See Demo</a> </div> </div> <!-- Slide 5 --> <div class="slide slide-5" role="group" aria-roledescription="slide" aria-label="5 of 5"> <div class="slide-shapes"> <div class="shape shape-1"></div> <div class="shape shape-2"></div> <div class="shape shape-3"></div> </div> <div class="slide-content"> <div class="slide-icon">✧</div> <h2 class="slide-title">Responsive Design</h2> <p class="slide-description">Looks great on any screen size, from mobile phones to large desktop displays, with adaptive layouts and touch-friendly controls.</p> <a href="#" class="slide-button">Get Started</a> </div> </div> </div> <!-- Arrow Navigation --> <label for="slide5" class="arrow-label arrow-prev" aria-label="Previous slide"> <svg viewBox="0 0 24 24"> <polyline points="15,18 9,12 15,6"></polyline> </svg> </label> <label for="slide2" class="arrow-label arrow-next" aria-label="Next slide"> <svg viewBox="0 0 24 24"> <polyline points="9,18 15,12 9,6"></polyline> </svg> </label> <!-- Slide Counter --> <div class="slide-counter"> <span class="counter-slide current"></span> / 5 </div> </div> <!-- Dot Navigation --> <div class="carousel-dots" role="tablist" aria-label="Carousel navigation"> <label for="slide1" class="dot-label" role="tab" tabindex="0" aria-label="Go to slide 1" aria-selected="true"></label> <label for="slide2" class="dot-label" role="tab" tabindex="0" aria-label="Go to slide 2" aria-selected="false"></label> <label for="slide3" class="dot-label" role="tab" tabindex="0" aria-label="Go to slide 3" aria-selected="false"></label> <label for="slide4" class="dot-label" role="tab" tabindex="0" aria-label="Go to slide 4" aria-selected="false"></label> <label for="slide5" class="dot-label" role="tab" tabindex="0" aria-label="Go to slide 5" aria-selected="false"></label> </div> </div> <div class="keyboard-hint"> Use <kbd>Tab</kbd> to navigate between controls • <kbd>Space</kbd> or <kbd>Enter</kbd> to select • Arrow keys work naturally with radio buttons </div> </body> </html>Key Features
Accessibility
- Keyboard Navigation: Tab through dots/arrows, use arrow keys when focused on radio group
- ARIA Labels: All controls have descriptive labels for screen readers
- Focus Indicators: Visible focus states with golden outline
- Semantic Structure: Proper
roleandaria-attributes throughout
Visual Design
- Dark theme with warm gold/copper accents (no template blues/purples)
- Animated background with pulsing gradient orbs
- Floating particles for depth and movement
- Progress bar showing current position
- Slide counter for orientation
Interactions (CSS-only!)
- Dot indicators with active state styling
- Arrow navigation with hover effects
- Smooth slide transitions (600ms cubic-bezier)
- Icon pulse animations within slides
- Floating shape decorations in each slide
How It Works
- Radio inputs (
name="carousel") act as state storage - Labels are styled as clickable controls (dots/arrows)
:checkedpseudo-class selects active slide- CSS sibling selector (
~) cascades state down to slides transform: translateX()moves the slides track
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.