Load, Play, and Pause Audio or Songs in your HTML website ๐ŸŽต

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)

--

--

26K+ Reads โœ๐Ÿผ Co-founder & CTO @Connect Earth. Ex-Amazon ๐Ÿ‘จโ€๐Ÿ’ป Passionate about sustainability and software๐Ÿ‘Œ Views are all my own.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nicolas Carmont

26K+ Reads โœ๐Ÿผ Co-founder & CTO @Connect Earth. Ex-Amazon ๐Ÿ‘จโ€๐Ÿ’ป Passionate about sustainability and software๐Ÿ‘Œ Views are all my own.