How to display play pause and mute buttons in HTML5 ? Last Updated : 12 Mar, 2024 Comments Improve Suggest changes Like Article Like Report To display play, pause, and mute buttons in an audio file through HTML5, we can use JavaScript methods such as "play()", "pause()" and ".muted". With this feature of audio display with only play, pause, and mute buttons, we're essentially giving the user control over the playback of the audio file according to their preference. Syntax to display Audio Buttons:play() - It is used to start the current playing audio pause() - It is used to pause the current playing audio.muted - It mutes the current playing audio. To unmute, use it's negation.Approach to Display Play, Pause, and Mute ButtonUse an audio tag to specify the path and give it an ID (such as "music" in the below example).After that, create 3 buttons for play, pause, and mute the audio and also specify "onClick" eventListener to each button.Now, take the instance of the audio file in the script through ".getElementById" and store it in a variable.Create three functions for different actions (play, pause, and mute) as described below, and apply "play()", "pause()", and ".muted" on that variable that has the audio file's instance.Call these functions from individual "onClick" events of the respective buttons (play, pause, and mute).Example: Illustration of Audio display only plays pause and mute buttons in HTML5. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>How to Audio display only play pause and mute buttons in HTML5 </title> <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"> <style> button { border: 3px solid #b1b3b4; background-color: #287bd3; color: white; padding: 10px 20px; margin: 20px; transition: all 0.3s ease; cursor: pointer; outline: none; border-radius: 5px; } button:hover { background-color: #0056b3; border-color: #afcff2; } button:active { transform: scale(0.95); } i { margin-left: 7px; } </style> </head> <body> <h2>Audio display only play pause and mute buttons </h2> <!-- audio file --> <audio id="music"> <source src="sample.mp3" type="audio/mp3"> </audio> <!-- button to play --> <button onclick="playAudio()" type="button"> Play <i class="fa-solid fa-play"></i> </button> <!-- button to pause --> <button onclick="pauseAudio()" type="button"> Pause <i class="fa-solid fa-pause"></i> </button> <!-- button to mute --> <button onclick="muteAudio()" type="button"> Mute <i class="fa-solid fa-volume-xmark"></i> </button> <!-- javascript code --> <script> // get element from html var audioT = document.getElementById("music"); // use play() method to play music function playAudio() { audioT.play(); } // use pause() method to play music function pauseAudio() { audioT.pause(); } // use muted to pause music function muteAudio() { audioT.muted = !audioT.muted; } </script> </body> </html> Output: Output Comment More infoAdvertise with us Next Article How to display play pause and mute buttons in HTML5 ? V vivekchaudharyy Follow Improve Article Tags : HTML HTML-Questions Similar Reads How to display video controls in HTML5 ? The HTML <video> controls attribute is used to display video controls in HTML5. It is a Boolean attribute that adds video controls like volume, pause, and play. HTML5 commonly uses formats such as OGG, MP4, OGM, and OGV because browser support for these formats varies. Syntax <video control 3 min read How to Add Autoplay Video in HTML? Web design often has a feature of including a video that starts to play as soon as the web page loads. This effect can be achieved using HTML5 <video> element with the autoplay attribute. In this way, videos start playing without any user interaction hence improving the multimedia experience o 2 min read How to Autoplay Videos in HTML? Autoplay is a feature that automatically starts a video when the page loads. While it can be convenient for certain scenarios, it's essential to use as it avoids annoying users or consuming excessive bandwidth.We will discuss different approaches to autoplay videos in HTML:Table of ContentUsing the 2 min read How to make Sound only Play Once in HTML5 Audio ? In HTML5, we can validate the audio playing by using the proper event handling and control manipulation. In this article, we will explore two different approaches to create sound that only plays once in HTML5 Audio. Table of Content Using JavaScript Event ListenersUsing onended AttributeUsing JavaSc 2 min read How To Autoplay Youtube Video in HTML To embed and play YouTube videos in HTML, you can use the <iframe> tag with the YouTube embed URL. Furthermore, to autoplay a YouTube video in HTML, you need to add some specific parameters in the URL to control autoplay and muting. Autoplay: (autoplay=1) in the URL automatically starts playin 2 min read How to make a Disable Buttons using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be making a Disable Button using jQuery Mobile. Approach: First, add jQuery Mobile scripts needed for your project. <link rel="stylesheet 1 min read How to add controls to an audio in HTML5 ? In this article, we will learn how to add controls to audio in HTML5. The HTML <audio> controls attribute is used to specify the control to play audio which means it allows embedding an HTML5 music player with audio controls straight into the webpage. The current HTML5 most commonly used ogg, 2 min read How to pause/play animation using CSS ? CSS helps to animate HTML elements without using JavaScript. You can play and pause the animation applied to HTML elements using animation-play-state property of CSS.The animation-play-state property has 2 values:paused - Pauses an ongoing animation.running - Starts a paused animation (default value 2 min read How to Embed Audio and Video in HTML? HTML stands for HyperText Markup Language. It is used to design web pages using a markup language. It is a combination of Hypertext and Markup language. HTML uses predefined tags and elements that tell the browser how to properly display the content on the screen. So, in this article, we will learn 4 min read How to Hide Audio Controls in HTML5 ? In HTML5, the <audio> element embeds audio content into web pages. By default, it comes with built-in controls like play, pause, and volume adjustment. However, there might be scenarios where you want to hide these controls for a cleaner or more customized user experience. This article explore 3 min read Like