Load, Play, and Pause Audio or Songs in your HTML website 🎡

Kiki AI
2 min readJan 10, 2021

--

Playing Audio during your HMTL website can really spice up your site.

πŸ‘ THANKS: I appreciate your claps cause it takes time to write these free articles.

0.) (Pre-req) Drag the audio file into your Code πŸ’»

Ensure you have an audio file (ex: .mp3) accesible in your code.

1.) Use this code to load and play/pause the audio🌳

let audio = new Audio('YOUR_AUDIO_FILE.mp3');// Play Audio
audio.play();
// Pause Audio
audio.pause();
// Reload audio from beggining
audio.load()

Go to the W3 Schools Audio Object docs for more properties/methods.

Thanks for reading! πŸ‘ Please leave a clap if this helped. Also…

⚠️ πŸ’» IMPORTANT: If you’re building a website, it’s important you also think about:

1. πŸŽ₯ Embedding a Youtube video into your website

2. πŸ‘₯ Adding a thumbnail for sharing on social media:

3. βœ… Free resources for images, icons, and more on your website

4. πŸ–Ό Adding an icon to your website tab (HTML, favicon)

--

--

Kiki AI
Kiki AI

Written by Kiki AI

26K+ Reads ✍🏼 Passionate about tech, AI and impact πŸ‘Œ Views are all my own.

No responses yet