Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Audio in HTML

Audio in HTML

? Audio in HTML

HTML provides the <audio> element to embed audio files directly into a webpage. It supports playback controls and multiple formats.


? Basic Syntax

<audio controls>  <source src="audiofile.mp3" type="audio/mpeg">  Your browser does not support the audio element.</audio>
  • <audio>: The main tag for embedding audio.

  • <source>: Specifies the audio file and format.

  • "controls": Adds playback controls like play/pause/volume.

  • Fallback text: Shown if the browser doesn’t support the <audio> tag.


? Common Audio Formats and MIME Types

FormatMIME TypeDescription
.mp3audio/mpegWidely supported
.oggaudio/oggOpen format, good quality
.wavaudio/wavUncompressed, large files

? Tip: Use multiple formats to ensure browser compatibility.

<audio controls>  <source src="sound.ogg" type="audio/ogg">  <source src="sound.mp3" type="audio/mpeg">  Your browser does not support the audio element.</audio>

?? HTML <audio> Attributes

AttributeDescriptionExample
controlsDisplays playback controls<audio controls>
autoplayPlays audio automatically (not recommended without mute)<audio autoplay>
loopRepeats the audio indefinitely<audio loop>
mutedStarts audio in muted state<audio muted>
preloadSpecifies if/how the audio should be loaded<audio preload="auto">

Preload options:

  • none: Audio is not preloaded.

  • metadata: Only metadata (like length) is preloaded.

  • auto: Whole audio file may be downloaded when the page loads.


? Example: Background Music (Muted & Autoplay)

<audio autoplay loop muted>  <source src="bg-music.mp3" type="audio/mpeg"></audio>

? Accessibility Tip

Add a title or aria-label to the audio player if it's critical to content:

<audio controls aria-label="Pronunciation of the word">  <source src="word.mp3" type="audio/mpeg"></audio>

Would you like help embedding audio with custom play/pause buttons using JavaScript?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql