Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

HTML | DOM Audio volume Property

  • Last Updated : 30 Jul, 2019

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:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

  • 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:




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

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
Recommended Articles
Page :