HTML Basics

HTML Introduction HTML Basic HTML Comments HTML Tags/Elements HTML Attributes HTML Formatting HTML Block and Inline HTML Charsets HTML Classes HTML Colors HTML Div HTML Headings HTML Id HTML Iframes HTML Images HTML File Paths HTML Tables HTML Layout HTML Lists HTML Links <a> HTML Paragraphs HTML Quotations HTML JavaScript HTML Emojis HTML URL Encode HTML Entities HTML Computercode HTML Symbols HTML Styles

HTML Forms

HTML Forms HTML Form Elements HTML Form Attributes HTML Input Attributes HTML Input Regex HTML Input Form Attributes HTML Input Types

HTML SEO

HTML Head HTML Page Title HTML Responsive HTML Semantics HTML Favicon

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Audio HTML Video

HTML Reference

a abbr acronym address applet area article aside audio b base basefont bdi bdo big blockquote body br button canvas caption center cite code col colgroup data datalist dd del details dfn dialog dir div dl DOCTYPE dt em embed fieldset figcaption figure font footer form frame frameset h1_-_h6 head header hgroup hr html i iframe img input ins kbd label legend li link main map mark menu meta meter nav noframes noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script search section select small source span strike strong style sub summary sup svg table tbody td template textarea tfoot th thead time title tr track tt u ul var video wbr

HTML Audio Tutorial

HTML Audio is used to embed sound content in a webpage. It allows you to easily add music, podcasts, or any other audio file to your website.

Basic HTML Audio Usage

To add audio to your webpage, you can use the <audio> tag. Here is a simple example:

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

In the above example, we have an <audio> tag with the attribute controls which adds an audio player with play, pause, and volume controls. Inside the <audio> tag, we have a <source> tag with the path to the audio file and the type of audio file.

Supported Audio Formats

HTML Audio supports multiple audio formats such as MP3, WAV, and OGG. It is recommended to include multiple sources to ensure compatibility across different browsers. Here is an example:

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

Adding Audio without Controls

If you want to add audio without controls, you can omit the controls attribute. Here is an example:

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

Autoplaying Audio

If you want the audio to start playing automatically when the page loads, you can add the autoplay attribute. Keep in mind that autoplaying audio can be intrusive, so use it sparingly. Here is an example:

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

Looping Audio

If you want the audio to loop continuously, you can add the loop attribute. This will make the audio play again once it finishes. Here is an example:

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

Summary

HTML Audio is a powerful tool for adding sound content to your website. By using the <audio> tag, you can easily embed audio files and customize their playback behavior. Experiment with different attributes and formats to create a unique audio experience for your users.