HTML | DOM Audio volume Property

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

Syntax:

  • It returns the volume property.
    audio.volume
  • It sets the volume property.
    audio.volume = number

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



  • 1.0: It is the highest volume. It is the default value.
  • 0.5: It is used to specify half volume.
  • 0.0: It is used to specify zero volume/mute/silent.

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

Below program illustrates the Audio Volume property in HTML DOM:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>
        var 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>

chevron_right


Output:

  • Before Clicking on the Button:
  • After Clicking on Return Volume Button:
  • After Clicking on SetHalfVolume Button:
  • After Clicking on SetFullVolume Button:


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.