Grok 4.1 Fast· xai
Frontier Reasoning Traces
Design a custom range slider for controlling audio volume using HTML, JS, and CSS.
- User
Design a custom range slider for controlling audio volume using HTML, JS, and CSS.
- Assistant
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Custom Audio Volume Slider</title> <style> body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 100vh; margin: 0; color: white; padding: 20px; box-sizing: border-box; } audio { margin-bottom: 30px; width: 300px; max-width: 100%; } .controls { display: flex; flex-direction: column; align-items: center; gap: 20px; } .play-btn { background: rgba(255, 255, 255, 0.2); border: none; color: white; padding: 12px 24px; font-size: 18px; border-radius: 50px; cursor: pointer; transition: all 0.3s ease; backdrop-filter: blur(10px); } .play-btn:hover { background: rgba(255, 255, 255, 0.3); transform: scale(1.05); } .volume-container { display: flex; align-items: center; gap: 15px; background: rgba(255, 255, 255, 0.1); padding: 15px 25px; border-radius: 50px; backdrop-filter: blur(20px); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); } .volume-icon { font-size: 24px; min-width: 30px; text-align: center; transition: all 0.2s ease; } #volumeSlider { -webkit-appearance: none; appearance: none; width: 150px; height: 6px; background: rgba(255, 255, 255, 0.2); outline: none; border-radius: 10px; cursor: pointer; transition: background 0.3s ease; } #volumeSlider:hover { background: rgba(255, 255, 255, 0.3); } #volumeSlider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 24px; height: 24px; background: linear-gradient(135deg, #ff6b6b, #feca57); border-radius: 50%; cursor: pointer; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); transition: all 0.3s ease; } #volumeSlider::-webkit-slider-thumb:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); } #volumeSlider::-moz-range-thumb { width: 24px; height: 24px; background: linear-gradient(135deg, #ff6b6b, #feca57); border: none; border-radius: 50%; cursor: pointer; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); transition: all 0.3s ease; } #volumeSlider::-moz-range-thumb:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); } #volumeSlider::-webkit-slider-runnable-track { height: 6px; background: rgba(255, 255, 255, 0.2); border-radius: 10px; } #volumeSlider::-moz-range-track { height: 6px; background: rgba(255, 255, 255, 0.2); border-radius: 10px; } .volume-value { font-size: 16px; font-weight: 500; min-width: 45px; text-align: center; } @media (max-width: 480px) { .volume-container { padding: 12px 20px; gap: 12px; } #volumeSlider { width: 120px; } } </style> </head> <body> <!-- Replace 'your-audio-file.mp3' with your audio source. For demo, you can use a public URL like 'https://www.soundjay.com/misc/sounds/bell-ringing-05.wav' --> <audio id="audio" controls preload="metadata" src="your-audio-file.mp3"> Your browser does not support the audio element. </audio> <div class="controls"> <button class="play-btn" id="playBtn">▶️ Play / Pause</button> <div class="volume-container"> <span class="volume-icon" id="volumeIcon">🔊</span> <input type="range" id="volumeSlider" min="0" max="100" value="50"> <span class="volume-value" id="volumeValue">50%</span> </div> </div> <script> const audio = document.getElementById('audio'); const slider = document.getElementById('volumeSlider'); const volumeIcon = document.getElementById('volumeIcon'); const volumeValue = document.getElementById('volumeValue'); const playBtn = document.getElementById('playBtn'); // Initialize volume function updateVolume(vol) { audio.volume = vol / 100; volumeValue.textContent = vol + '%'; // Update icon based on volume level if (vol === 0) { volumeIcon.textContent = '🔇'; } else if (vol < 33) { volumeIcon.textContent = '🔈'; } else if (vol < 67) { volumeIcon.textContent = '🔉'; } else { volumeIcon.textContent = '🔊'; } } // Slider event listener slider.addEventListener('input', (e) => { updateVolume(parseInt(e.target.value)); }); // Play/Pause button playBtn.addEventListener('click', () => { if (audio.paused) { audio.play().catch(e => console.error('Playback failed:', e)); playBtn.textContent = '⏸️ Pause'; } else { audio.pause(); playBtn.textContent = '▶️ Play'; } }); // Sync slider with audio volume on load or change (e.g., via native controls) audio.addEventListener('loadedmetadata', () => { slider.value = audio.volume * 100; updateVolume(slider.value); }); // Initial setup updateVolume(slider.value); </script> </body> </html>This is a fully functional, responsive custom range slider for audio volume control. Key features:
- Custom styling: Gradient thumb with hover effects, glassy backdrop design, cross-browser compatible (WebKit & Firefox).
- Dynamic icons: Changes emoji based on volume (mute 🔇, low 🔈, medium 🔉, high 🔊).
- Real-time updates: Slider syncs with
<audio>volume, shows percentage. - Play/Pause button: For easy testing.
- Mobile-friendly: Scales on small screens.
- Demo-ready: Replace
srcwith your audio file. Built-in<audio controls>for fallback.
Copy-paste into an HTML file and open in a browser to test!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.