Course Content
HTML Forms
HTML forms are an essential part of web development and provide a way for users to input and submit data to a server. Forms allow users to enter data such as text, numbers, checkboxes, radio buttons, and more. When a user submits a form, the data is typically sent to a server for further processing.
0/6
HTML Graphics
HTML provides various ways to incorporate graphics into web pages.
0/2
HTML Media
HTML provides built-in support for embedding and displaying various types of media content on web pages.
0/5
HTML APIs
HTML APIs, also known as browser APIs or web APIs, are a set of interfaces and methods provided by web browsers to interact with and manipulate web content, access device features, and perform various tasks. These APIs are implemented in JavaScript and are accessible to web developers when creating web applications. Here are some commonly used HTML APIs:
0/5
HTML Examples
Creating a Simple Web Page, Adding Links and Images and more
0/4
HTML5 for Free | HTML5 – Unleashing the Potential of Web Development
About Lesson

HTML provides the <audio> element for embedding and playing audio content on a web page. Here’s how to use the <audio> element in HTML:

  1. Basic <audio> Element:
    To embed an audio file on a web page, use the <audio> element and specify the audio source using the src attribute. Example:
<audio src="audio.mp3" controls></audio>

The src attribute specifies the URL or file path of the audio file. The controls attribute adds playback controls (play, pause, volume, etc.) to the audio player.

  1. Multiple Audio Sources:
    To ensure compatibility across different browsers and devices, you can provide multiple audio sources using the <source> element within the <audio> element. The browser will automatically select the appropriate source based on compatibility. Example:
<audio controls>
  <source src="audio.mp3" type="audio/mpeg">
  <source src="audio.ogg" type="audio/ogg">
</audio>

In this example, two audio sources (MP3 and Ogg) are provided, each with its corresponding MIME type.

  1. Audio Attributes:
    The <audio> element supports various attributes to control audio playback and appearance. Some commonly used attributes include:
  • controls: Adds playback controls to the audio player.
  • autoplay: Specifies that the audio should start playing automatically.
  • loop: Specifies that the audio should loop and repeat playback.
  • muted: Specifies that the audio should start playing with muted sound.
  • preload: Specifies whether the audio should be preloaded (auto, metadata, or none).
  • volume: Specifies the volume level of the audio player (0.0 to 1.0).

Example:

<audio src="audio.mp3" controls autoplay loop muted preload="auto" volume="0.8"></audio>
  1. Audio Controls:
    The <audio> element provides default controls for play, pause, volume, and seeking. However, you can customize the appearance and behavior of the controls using CSS and JavaScript.
  2. Audio Formats and Browser Support:
    Different browsers support different audio formats. To ensure broad compatibility, it is recommended to provide audio sources in multiple formats (e.g., MP3, Ogg). The browser will select the supported format automatically.
  3. Audio Events and JavaScript:
    You can interact with the <audio> element and control its behavior through JavaScript. The <audio> element exposes events like play, pause, ended, timeupdate, etc., which can be handled using JavaScript to perform custom actions or implement advanced functionality.

Remember to consider different audio formats and provide fallback options for unsupported browsers or devices to ensure a seamless audio playback experience.

Join the conversation