Background music can instantly enhance the user experience on a website—especially for portfolios, creative studios, or immersive brand storytelling. But modern browsers block autoplay audio by default, making it tricky to implement.
In this guide, I’ll show you exactly how to add autoplay background music to your WordPress Elementor website, with a smart fallback play button in case autoplay is blocked by the browser. Best of all, no plugin is required.
🎯 What You’ll Learn:
- How to upload your audio file
- Embed autoplay audio with custom code
- Ensure browser compatibility with a play button fallback
- Style the button to appear fixed at the bottom-left
📥 Step 1: Upload Your Audio File
- Go to your WordPress Dashboard.
- Navigate to Media > Add New.
- Upload your
.mp3
file. - Click on the uploaded file and copy the File URL.
For example:
http://yourdomain.com/wp-content/uploads/2025/05/background-music.mp3
🧩 Step 2: Add Custom HTML to Elementor
- Open your Elementor editor.
- Drag and drop an HTML widget to your page (ideally in the header, hero, or global section).
- Paste the following code:
<audio id="bgm-player" autoplay loop>
<source src="http://yourdomain.com/wp-content/uploads/2025/05/background-music.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
const player = document.getElementById('bgm-player');
document.addEventListener('DOMContentLoaded', () => {
player.volume = 0.5; // Set volume level (0.0 to 1.0)
const playPromise = player.play();
if (playPromise !== undefined) {
playPromise.catch(() => {
// If autoplay is blocked, show a button
const btn = document.createElement('button');
btn.textContent = "🔊 Play Music";
btn.style.position = 'fixed';
btn.style.bottom = '20px';
btn.style.left = '20px';
btn.style.zIndex = '9999';
btn.style.padding = '10px 15px';
btn.style.backgroundColor = '#6e41e2';
btn.style.color = '#fff';
btn.style.border = 'none';
btn.style.borderRadius = '8px';
btn.style.cursor = 'pointer';
btn.style.boxShadow = '0 2px 8px rgba(0,0,0,0.2)';
btn.style.fontSize = '14px';
document.body.appendChild(btn);
btn.addEventListener('click', () => {
player.play();
btn.remove();
});
});
}
});
</script>
NOTE: 💡 Replace the src
URL with your own uploaded audio file URL.
🎨 Optional: Customize the Button
You can tweak:
- Button text (e.g., “🎶 Tap to Play”)
- Colors to match your brand
- Position (bottom-left, bottom-right, etc.)
🧪 Final Result
- Music plays automatically if browser allows.
- If blocked, users will see a clean, fixed-position play button.
- Once clicked, the button disappears and music starts looping in the background.
✅ Bonus Tips
- Use a compressed audio file to reduce page load.
- Keep volume modest (0.2–0.5) to avoid overwhelming users.
- Consider using ambient or instrumental tracks for minimal distraction.
- Don’t forget mobile users — some browsers (especially on iOS) block autoplay entirely without user interaction.
💬 Final Thoughts
Adding background music to your Elementor website can dramatically improve the atmosphere and engagement of your content. With this simple code snippet, you can bypass autoplay restrictions with grace and style — without needing any heavy plugins.
Have questions or want to style the button more creatively? Let me know in the comments!