Skip to content
Related Articles

Related Articles

How to preload an audio in HTML5 ?
  • Difficulty Level : Expert
  • Last Updated : 15 Mar, 2021

In this article, we will preload audio in HTML. We use preload=”auto” attribute to preload the audio file. The HTML Audio Preload Attribute is used to specify how the author thinks the audio should be loaded when the page loads. The audio preload attribute allows the author to indicate to the browser how the user experience of a website should be implemented. n some instances, this attribute can be ignored.

You have to know about HTML <audio> preload Attribute

Note: If autoplay is present, then the preload attribute is ignored.

Below are the examples that illustrates the use of preload attribute.

Example-1: When preload =” auto” 



HTML




<!DOCTYPE html>
<html>
<body>
  <h1>GFG</h1>
  <p>Hit the button for audio</p>
  <audio controls preload="auto">
     <source src="gfg.ogg" type="audio/ogg">
     <source src="gfg.mp3" type="audio/mpeg">
  </audio>
</body>
    
</html>

Output:

Example 1

Example 2: When preload = “none” :

HTML




<!DOCTYPE html>
<html>
    
<body>
  <h1>GFG</h1>
  <p>Hit the button for audio</p>
  
  <audio controls preload="none">
     <source src="gfg.ogg" type="audio/ogg">
     <source src="gfg.mp3" type="audio/mpeg">
  </audio>
</body>
    
</html>

Output:

Example 2

My Personal Notes arrow_drop_up
Recommended Articles
Page :