Key Properties
PropertyTypeDescription
srcstring URL of the audio file. ▾
JS
audio.src = 'song.mp3';
audio.load(); // reload after src change
volumenumber 0.0 (silent) to 1.0 (full volume). ▾
JS
audio.volume = 0.3; // 30% volume
mutedboolean Mute/unmute without changing the volume property. ▾
JS
audio.muted = true;
loopboolean If true, audio restarts automatically when it ends. ▾
JS
audio.loop = true;  // great for background music
currentTimenumber Playback position in seconds. Set it to seek. ▾
JS
audio.currentTime = 0;  // restart from beginning
audio.currentTime = 60; // skip to 1 minute
pausedboolean True if not playing. Read-only. ▾
JS
if (audio.paused) audio.play();
else audio.pause();
Common Methods
MethodReturnsDescription
play()Promise Start playback. Returns a Promise. ▾

Tip: you can create an Audio object without an HTML element at all.

JS
// Without any HTML element:
const sfx = new Audio('click.mp3');
sfx.play();

// From the DOM:
audio.play().catch(e => console.log('Blocked:', e));
pause()void Pause playback. ▾
JS
audio.pause();
Quick Examples
JS
// Play a sound effect on button click (no HTML audio element needed)
const click = new Audio('click.mp3');
document.querySelector('button').addEventListener('click', () => {
  click.currentTime = 0; // rewind so it plays even if still playing
  click.play();
});

// Background music with volume control
const music = document.querySelector('audio');
music.loop = true;
music.volume = 0.4;
music.play();

document.querySelector('#vol-slider').addEventListener('input', (e) => {
  music.volume = e.target.value / 100;
});
Related Elements
Related Properties
Related Methods