Skip to content

shadcn.io is an independent project built on shadcn/ui

Volume Controls Button Group for Svelte

Volume controls that start at 50 percent: mute, down, and up, plus a row that shows the level or Muted.

UI library: Ark UI

Volume starts at 50 percent, not muted. Down and up move by 10, and the level stays between 0 and 100. Reaching 0 mutes, and turning it up unmutes. The second row is minus, the level or the word Muted, and plus. That middle button does not change the volume.

Use steps when the level only needs coarse changes. A precise level is a Slider. In Svelte, Ark UI does not change the player's volume.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Button Group anatomy: root, group, button, separator

Usage

<div class="flex flex-col gap-4"><ButtonGroup aria-label="Volume"><Button aria-label={isMuted ? "Unmute" : "Mute"} aria-pressed={isMuted} onclick={toggleMuted} size="icon-sm" variant="outline">{#if isMuted}<VolumeXIcon aria-hidden="true" />{:else}<Volume2Icon aria-hidden="true" />{/if}</Button><Button aria-label="Volume down" onclick={decreaseVolume} size="icon-sm" variant="outline"><VolumeIcon aria-hidden="true" /></Button><Button aria-label="Volume up" onclick={increaseVolume} size="icon-sm" variant="outline"><Volume2Icon aria-hidden="true" /></Button></ButtonGroup><ButtonGroup aria-label="Volume"><Button aria-label="Volume down" onclick={decreaseVolume} size="sm" variant="outline">-</Button><Button size="sm" variant="outline">{#if isMuted}{"Muted"}{:else}{`${volume}%`}{/if}</Button><Button aria-label="Volume up" onclick={increaseVolume} size="sm" variant="outline">+</Button></ButtonGroup></div>

FAQ

What is tracked?

A volume from 0 to 100, starting at 50, and a muted flag. Down subtracts 10 and stops at 0; up adds 10 and stops at 100.

How does mute change the icon?

The mute button shows VolumeXIcon when muted and Volume2Icon otherwise. Its aria-label reads Unmute or Mute, and aria-pressed reports the muted state.

What happens at 0?

Volume down to 0 turns mute on. Volume up always turns it off.

How are the icon and symbol buttons named?

Volume down and Volume up are aria-labels on both rows, so the - and + buttons aren't read as bare symbols.

Does the middle button do anything?

No. It shows the level, such as 50%, or Muted, and has no handler. Use ButtonGroupText instead if you don't want it to take focus.

Should this be a slider?

For fine control, yes: a Slider sets any level in one drag. Buttons suit quick steps and small spaces.

API Reference

Button Group

Sets aria-label="Volume". The rest is on the Button Group page.

Button

Sets aria-label={isMuted ? "Unmute" : "Mute"}, aria-pressed={isMuted}, onclick={toggleMuted}, size="icon-sm", variant="outline" and aria-label="Volume down". The rest is on the Button page.