We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

The gain property of the GainNode interface is an a-rate AudioParam representing the amount of gain to apply.


var audioCtx = new AudioContext();
var gainNode = audioCtx.createGain();
gainNode.gain.value = 0.5;


An AudioParam.

Note: Though the AudioParam returned is read-only, the value it represents is not.


The following example shows basic usage of an AudioContext to create a GainNode, which is then used to mute and unmute the audio when a Mute button is clicked by changing the gain property value.

The below snippet wouldn't work as is — for a complete working example, check out our Voice-change-O-matic demo (view source.)

  <a class="mute">Mute button</a>
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var gainNode = audioCtx.createGain();
var mute = document.querySelector('.mute');
var source;

if (navigator.mediaDevices.getUserMedia) {
 navigator.mediaDevices.getUserMedia (
   // constraints - only audio needed for this app
     audio: true

   // Success callback
   function(stream) {
     source = audioCtx.createMediaStreamSource(stream);


   // Error callback
   function(err) {
     console.log('The following gUM error occured: ' + err);
} else {
   console.log('getUserMedia not supported on your browser!');



mute.onclick = voiceMute;

function voiceMute() {
  if(mute.id == "") {
    gainNode.gain.value = 0;
    mute.id = "activated";
    mute.innerHTML = "Unmute";
  } else {
    gainNode.gain.value = 1;
    mute.id = "";
    mute.innerHTML = "Mute";


Specification Status Comment
Web Audio API
The definition of 'gain' in that specification.
Working Draft  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support14 Yes25 No156
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic support Yes14 Yes26 No15 ?

See also

Document Tags and Contributors

 Contributors to this page: fscholz, erikadoyle, chrisdavidmills
 Last updated by: fscholz,