Open In App

HTML DOM Audio volume Property

The HTML DOM Audio volume property is used to set or return the current volume of the Audio element. The volume value 0.0 represents silent and 1.0 represents loudest. 

Syntax: 



audio.volume
audio.volume = number

Property Values: It contains a single property value number which represents the value of audio volume. The value of the volume is:

Return value: It returns a numeric value that represents the current volume of the Audio element. 



Example: The below program illustrates the Audio Volume property in HTML DOM: 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Audio Volume Property
    </title>
</head>
 
<body style="text-align: center">
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <h2 style="font-family: Impact">
        HTML DOM Audio Volume Property
    </h2>
    <br>
    <audio id="Test_Audio" controls>
        <source src=
                type="audio/ogg">
        <source src=
                type="audio/mpeg">
    </audio>
    <br>
    <button onclick="volume()" type="button">
        Return Volume
    </button>
    <button onclick="Set_vol1()" type="button">
        Set HalfVolume
    </button>
    <button onclick="Set_vol2()" type="button">
        Set Fullvolume
    </button>
    <br>
   
    <script>
        let gfg = document.getElementById("Test_Audio");
        function volume() {
            alert(gfg.volume);
        }
        function Set_vol1() {
            gfg.volume = 0.2;
        }
        function Set_vol2() {
            gfg.volume = 1.0;
        }
    </script>
</body>
 
</html>

Output:

 


Article Tags :