Skip to content

Instantly share code, notes, and snippets.

@AppLoidx
Last active March 23, 2025 15:27
Show Gist options
  • Save AppLoidx/2f5fca393c72609b01d9550fe93d57f5 to your computer and use it in GitHub Desktop.
Save AppLoidx/2f5fca393c72609b01d9550fe93d57f5 to your computer and use it in GitHub Desktop.
Way to autoplay audio on html5

This is the method I use to automatically play the audio on the page when I open it

  1. Creating iframe with empty audio:
<iframe src="assets/music/silence.mp3" allow="autoplay" id="audio" style="display:none"></iframe>

You can use this sound: silence

  1. Add audio tag with your original sound:
    <audio id="player" preload="auto" autoplay loop>
            <source src="assets/music/loop.mp3" type="audio/mp3">
    </audio>

I found this solution on stackoverflow

This is my examples (they have a background sound):

@bagussatoto
Copy link

How to use that script, if there is no use of boolean

@bajinganbangsatt
Copy link

does this work without the control button for mp3 assets on github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment