The user wants a custom range slider for controlling audio volume. This is a great opportunity to create something visually striking and interactive. Let me think about what would make this stand out:
Let me create a distinctive volume slider that feels like professional audio equipment with:
Let me code this up with proper accessibility, animations, and polish.
I'll create a premium, audio-focused volume slider with a dark professional aesthetic, multiple interactions, and smooth animations.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Volume Control</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<style>
:root {
--bg: #0a0a0f;
--bg-elevated: #12121a;
--fg: #e8e8ed;
--muted: #6b6b7a;
--accent: #00d4aa;
--accent-dim: rgba(0, 212, 170, 0.15);
--accent-glow: rgba(0, 212, 170, 0.4);
--border: #2a2a35;
--track: #1a1a24;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
margin: 0;
overflow-x: hidden;
}
/* Background texture */
.bg-texture {
position: fixed;
inset: 0;
background-image:
radial-gradient(ellipse at 50% 0%, rgba(0, 212, 170, 0.08) 0%, transparent 50%),
radial-gradient(circle at 20% 80%, rgba(0, 100, 200, 0.05) 0%, transparent 40%);
pointer-events: none;
z-index: 0;
}
.bg-grid {
position: fixed;
inset: 0;
background-image:
linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
background-size: 40px 40px;
pointer-events: none;
z-index: 0;
}
/* Typography */
.mono {
font-family: 'JetBrains Mono', monospace;
}
/* Custom Range Slider */
.volume-slider {
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 8px;
background: transparent;
cursor: pointer;
position: relative;
z-index: 2;
}
.volume-slider::-webkit-slider-runnable-track {
width: 100%;
height: 8px;
background: var(--track);
border-radius: 4px;
border: 1px solid var(--border);
}
.volume-slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 24px;
height: 24px;
background: var(--fg);
border-radius: 50%;
margin-top: -9px;
box-shadow:
0 0 0 3px var(--bg-elevated),
0 0 20px var(--accent-glow);
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.volume-slider::-webkit-slider-thumb:hover {
transform: scale(1.15);
box-shadow:
0 0 0 3px var(--bg-elevated),
0 0 30px var(--accent-glow);
}
.volume-slider::-webkit-slider-thumb:active {
transform: scale(1.05);
}
.volume-slider::-moz-range-track {
width: 100%;
height: 8px;
background: var(--track);
border-radius: 4px;
border: 1px solid var(--border);
}
.volume-slider::-moz-range-thumb {
width: 24px;
height: 24px;
background: var(--fg);
border: none;
border-radius: 50%;
box-shadow:
0 0 0 3px var(--bg-elevated),
0 0 20px var(--accent-glow);
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.volume-slider::-moz-range-thumb:hover {
transform: scale(1.15);
}
.volume-slider:focus-visible {
outline: none;
}
.volume-slider:focus-visible::-webkit-slider-thumb {
box-shadow:
0 0 0 3px var(--accent),
0 0 30px var(--accent-glow);
}
/* Track fill */
.slider-track {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 8px;
background: linear-gradient(90deg, var(--accent), rgba(0, 212, 170, 0.7));
border-radius: 4px;
pointer-events: none;
z-index: 1;
transition: width 0.05s linear;
}
.slider-track::after {
content: '';
position: absolute;
inset: -4px;
background: var(--accent);
filter: blur(12px);
opacity: 0.3;
border-radius: 4px;
}
/* Speaker icon animation */
.speaker-icon {
transition: transform 0.2s ease;
}
.speaker-icon:hover {
transform: scale(1.1);
}
.sound-wave {
opacity: 0;
transition: opacity 0.2s ease;
}
.sound-wave.active {
opacity: 1;
}
/* Vertical slider */
.vertical-slider {
writing-mode: vertical-lr;
direction: rtl;
width: 8px;
height: 200px;
}
.vertical-slider::-webkit-slider-runnable-track {
width: 8px;
height: 100%;
}
.vertical-slider::-webkit-slider-thumb {
margin-top: auto;
margin-left: -9px;
}
/* Rotary knob */
.rotary-knob {
width: 100px;
height: 100px;
border-radius: 50%;
background:
conic-gradient(from 135deg, var(--track) 0deg, var(--track) 270deg, transparent 270deg);
position: relative;
cursor: grab;
transition: box-shadow 0.2s ease;
}
.rotary-knob:hover {
box-shadow: 0 0 40px var(--accent-glow);
}
.rotary-knob:active {
cursor: grabbing;
}
.rotary-knob-inner {
position: absolute;
inset: 8px;
border-radius: 50%;
background: var(--bg-elevated);
border: 2px solid var(--border);
display: flex;
align-items: center;
justify-content: center;
}
.rotary-indicator {
width: 4px;
height: 20px;
background: var(--accent);
border-radius: 2px;
position: absolute;
top: 12px;
transform-origin: center 30px;
box-shadow: 0 0 10px var(--accent);
}
/* Entrance animations */
@keyframes fadeSlideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes scaleIn {
from {
opacity: 0;
transform: scale(0.9);
}
to {
opacity: 1;
transform: scale(1);
}
}
.animate-in {
animation: fadeSlideUp 0.6s ease forwards;
}
.animate-in-delay-1 {
animation: fadeSlideUp 0.6s ease 0.1s forwards;
opacity: 0;
}
.animate-in-delay-2 {
animation: fadeSlideUp 0.6s ease 0.2s forwards;
opacity: 0;
}
.animate-in-delay-3 {
animation: scaleIn 0.5s ease 0.3s forwards;
opacity: 0;
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* Volume meter */
.volume-meter {
display: flex;
gap: 3px;
align-items: flex-end;
height: 32px;
}
.meter-bar {
width: 4px;
background: var(--border);
border-radius: 2px;
transition: background 0.1s ease, height 0.1s ease;
}
.meter-bar.active {
background: var(--accent);
box-shadow: 0 0 8px var(--accent-glow);
}
.meter-bar.overload {
background: #ff4444;
box-shadow: 0 0 8px rgba(255, 68, 68, 0.5);
}
</style>
</head>
<body class="relative">
<div class="bg-texture"></div>
<div class="bg-grid"></div>
<main class="relative z-10 min-h-screen flex flex-col items-center justify-center p-6">
<!-- Header -->
<header class="text-center mb-16 animate-in">
<p class="mono text-xs tracking-widest text-[var(--muted)] uppercase mb-3">Audio Interface</p>
<h1 class="text-4xl md:text-5xl font-bold tracking-tight mb-2">Volume Control</h1>
<p class="text-[var(--muted)]">Professional audio slider components</p>
</header>
<!-- Main Slider -->
<section class="w-full max-w-xl mb-20 animate-in-delay-1">
<div class="bg-[var(--bg-elevated)] border border-[var(--border)] rounded-2xl p-8 relative overflow-hidden">
<!-- Glow effect -->
<div class="absolute inset-0 bg-gradient-to-b from-[var(--accent-dim)] to-transparent opacity-50 pointer-events-none"></div>
<div class="relative">
<!-- Header row -->
<div class="flex items-center justify-between mb-6">
<div class="flex items-center gap-4">
<!-- Mute button -->
<button
id="muteBtn"
class="speaker-icon w-12 h-12 rounded-xl bg-[var(--track)] border border-[var(--border)] flex items-center justify-center hover:border-[var(--accent)] transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)]"
aria-label="Toggle mute"
>
<svg id="speakerSvg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon>
<!-- Sound waves -->
<path id="wave1" class="sound-wave" d="M15.54 8.46a5 5 0 0 1 0 7.07"></path>
<path id="wave2" class="sound-wave" d="M19.07 4.93a10 10 0 0 1 0 14.14"></path>
<!-- Mute X -->
<line id="muteX" x1="23" y1="9" x2="17" y2="15" style="display:none" stroke="var(--accent)"></line>
<line id="muteX2" x1="17" y1="9" x2="23" y2="15" style="display:none" stroke="var(--accent)"></line>
</svg>
</button>
<div>
<p class="font-medium">Master Volume</p>
<p class="text-sm text-[var(--muted)]">System output</p>
</div>
</div>
<div class="text-right">
<p id="volumeDisplay" class="mono text-2xl font-medium text-[var(--accent)]">75</p>
<p class="text-xs text-[var(--muted)]">%</p>
</div>
</div>
<!-- Slider container -->
<div class="relative py-4">
<div id="sliderTrack" class="slider-track" style="width: 75%"></div>
<input
type="range"
id="volumeSlider"
class="volume-slider"
min="0"
max="100"
value="75"
aria-label="Volume slider"
>
</div>
<!-- Scale markers -->
<div class="flex justify-between mt-2 px-1">
<span class="mono text-xs text-[var(--muted)]">0</span>
<span class="mono text-xs text-[var(--muted)]">25</span>
<span class="mono text-xs text-[var(--muted)]">50</span>
<span class="mono text-xs text-[var(--muted)]">75</span>
<span class="mono text-xs text-[var(--muted)]">100</span>
</div>
<!-- Bottom row -->
<div class="flex items-center justify-between mt-6 pt-6 border-t border-[var(--border)]">
<!-- Volume meter -->
<div id="volumeMeter" class="volume-meter" aria-hidden="true">
<!-- Bars generated by JS -->
</div>
<!-- Keyboard hint -->
<div class="flex items-center gap-2 text-xs text-[var(--muted)]">
<kbd class="mono px-2 py-1 bg-[var(--track)] rounded border border-[var(--border)]">←→</kbd>
<span>to adjust</span>
</div>
</div>
</div>
</div>
</section>
<!-- Alternative sliders -->
<section class="w-full max-w-4xl animate-in-delay-2">
<h2 class="text-lg font-medium mb-6 text-center text-[var(--muted)]">Alternative Styles</h2>
<div class="grid md:grid-cols-2 gap-6">
<!-- Vertical Slider -->
<div class="bg-[var(--bg-elevated)] border border-[var(--border)] rounded-2xl p-6 flex flex-col items-center">
<p class="text-sm text-[var(--muted)] mb-4">Vertical</p>
<div class="relative h-56 flex items-center gap-6">
<div class="relative h-48">
<div id="verticalTrack" class="absolute bottom-0 left-1/2 -translate-x-1/2 w-2 bg-gradient-to-t from-[var(--accent)] to-[rgba(0,212,170,0.5)] rounded-full" style="height: 60%"></div>
<input
type="range"
id="verticalSlider"
class="vertical-slider"
min="0"
max="100"
value="60"
aria-label="Vertical volume slider"
>
</div>
<div class="flex flex-col justify-between h-48 text-xs mono text-[var(--muted)]">
<span>100</span>
<span>75</span>
<span>50</span>
<span>25</span>
<span>0</span>
</div>
</div>
<p id="verticalDisplay" class="mono text-lg mt-4 text-[var(--accent)]">60%</p>
</div>
<!-- Rotary Knob -->
<div class="bg-[var(--bg-elevated)] border border-[var(--border)] rounded-2xl p-6 flex flex-col items-center">
<p class="text-sm text-[var(--muted)] mb-4">Rotary</p>
<div
id="rotaryKnob"
class="rotary-knob"
role="slider"
aria-label="Rotary volume knob"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="50"
tabindex="0"
>
<div class="rotary-knob-inner">
<div id="rotaryIndicator" class="rotary-indicator" style="transform: rotate(-45deg)"></div>
</div>
</div>
<p id="rotaryDisplay" class="mono text-lg mt-4 text-[var(--accent)]">50%</p>
<p class="text-xs text-[var(--muted)] mt-2">Drag to adjust</p>
</div>
</div>
</section>
</main>
<script>
// State
let volume = 75;
let previousVolume = 75;
let isMuted = false;
let rotaryValue = 50;
let isDraggingRotary = false;
// Elements
const slider = document.getElementById('volumeSlider');
const sliderTrack = document.getElementById('sliderTrack');
const volumeDisplay = document.getElementById('volumeDisplay');
const muteBtn = document.getElementById('muteBtn');
const wave1 = document.getElementById('wave1');
const wave2 = document.getElementById('wave2');
const muteX = document.getElementById('muteX');
const muteX2 = document.getElementById('muteX2');
const volumeMeter = document.getElementById('volumeMeter');
const verticalSlider = document.getElementById('verticalSlider');
const verticalTrack = document.getElementById('verticalTrack');
const verticalDisplay = document.getElementById('verticalDisplay');
const rotaryKnob = document.getElementById('rotaryKnob');
const rotaryIndicator = document.getElementById('rotaryIndicator');
const rotaryDisplay = document.getElementById('rotaryDisplay');
// Initialize volume meter bars
function initVolumeMeter() {
const barCount = 20;
volumeMeter.innerHTML = '';
for (let i = 0; i < barCount; i++) {
const bar = document.createElement('div');
bar.className = 'meter-bar';
bar.style.height = `${4 + (i * 1.4)}px`;
volumeMeter.appendChild(bar);
}
}
// Update volume meter
function updateVolumeMeter(value) {
const bars = volumeMeter.querySelectorAll('.meter-bar');
const activeCount = Math.floor((value / 100) * bars.length);
bars.forEach((bar, index) => {
bar.classList.remove('active', 'overload');
if (index < activeCount) {
bar.classList.add('active');
if (index >= bars.length - 2) {
bar.classList.add('overload');
}
}
});
}
// Update sound waves visibility
function updateSoundWaves(value) {
if (isMuted || value === 0) {
wave1.classList.remove('active');
wave2.classList.remove('active');
muteX.style.display = 'block';
muteX2.style.display = 'block';
} else {
muteX.style.display = 'none';
muteX2.style.display = 'none';
wave1.classList.add('active');
if (value > 50) {
wave2.classList.add('active');
} else {
wave2.classList.remove('active');
}
}
}
// Update slider visual
function updateSlider(value) {
const clampedValue = Math.max(0, Math.min(100, value));
sliderTrack.style.width = `${clampedValue}%`;
volumeDisplay.textContent = Math.round(clampedValue);
updateVolumeMeter(clampedValue);
updateSoundWaves(clampedValue);
}
// Slider input handler
slider.addEventListener('input', (e) => {
volume = parseInt(e.target.value);
if (volume > 0) {
previousVolume = volume;
isMuted = false;
}
updateSlider(volume);
});
// Keyboard controls for slider
slider.addEventListener('keydown', (e) => {
const step = e.shiftKey ? 10 : 5;
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') {
e.preventDefault();
volume = Math.min(100, volume + step);
slider.value = volume;
updateSlider(volume);
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') {
e.preventDefault();
volume = Math.max(0, volume - step);
slider.value = volume;
updateSlider(volume);
}
});
// Mute button
muteBtn.addEventListener('click', () => {
isMuted = !isMuted;
if (isMuted) {
previousVolume = volume;
volume = 0;
slider.value = 0;
} else {
volume = previousVolume || 50;
slider.value = volume;
}
updateSlider(volume);
});
// Vertical slider
verticalSlider.addEventListener('input', (e) => {
const val = parseInt(e.target.value);
verticalTrack.style.height = `${val}%`;
verticalDisplay.textContent = `${val}%`;
});
// Rotary knob
function updateRotaryKnob(value) {
const clampedValue = Math.max(0, Math.min(100, value));
rotaryValue = clampedValue;
// Map 0-100 to -135deg to 135deg
const rotation = (clampedValue / 100) * 270 - 135;
rotaryIndicator.style.transform = `rotate(${rotation}deg)`;
rotaryDisplay.textContent = `${Math.round(clampedValue)}%`;
rotaryKnob.setAttribute('aria-valuenow', Math.round(clampedValue));
}
function handleRotaryDrag(e) {
if (!isDraggingRotary) return;
const rect = rotaryKnob.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
let clientX, clientY;
if (e.touches) {
clientX = e.touches[0].clientX;
clientY = e.touches[0].clientY;
} else {
clientX = e.clientX;
clientY = e.clientY;
}
const angle = Math.atan2(clientY - centerY, clientX - centerX);
const degrees = (angle * 180 / Math.PI) + 90;
// Map -135 to 135 degrees to 0-100
let normalizedDegrees = degrees;
if (normalizedDegrees > 180) normalizedDegrees -= 360;
if (normalizedDegrees >= -135 && normalizedDegrees <= 135) {
const value = ((normalizedDegrees + 135) / 270) * 100;
updateRotaryKnob(value);
}
}
rotaryKnob.addEventListener('mousedown', () => {
isDraggingRotary = true;
});
rotaryKnob.addEventListener('touchstart', () => {
isDraggingRotary = true;
}, { passive: true });
document.addEventListener('mousemove', handleRotaryDrag);
document.addEventListener('touchmove', handleRotaryDrag, { passive: true });
document.addEventListener('mouseup', () => {
isDraggingRotary = false;
});
document.addEventListener('touchend', () => {
isDraggingRotary = false;
});
// Keyboard controls for rotary
rotaryKnob.addEventListener('keydown', (e) => {
const step = e.shiftKey ? 10 : 5;
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') {
e.preventDefault();
updateRotaryKnob(rotaryValue + step);
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') {
e.preventDefault();
updateRotaryKnob(rotaryValue - step);
}
});
// Scroll wheel for rotary
rotaryKnob.addEventListener('wheel', (e) => {
e.preventDefault();
const delta = e.deltaY > 0 ? -5 : 5;
updateRotaryKnob(rotaryValue + delta);
}, { passive: false });
// Initialize
initVolumeMeter();
updateSlider(volume);
updateRotaryKnob(rotaryValue);
// Initialize vertical slider
verticalTrack.style.height = '60%';
</script>
</body>
</html>