HTML Audio

The audio element is used to embed sound content in web pages. It allows you to include audio files directly into your HTML documents and provides several attributes to control audio playback.

Audio Element Attributes

The audio element comes with several attributes to help you control the playback and appearance of your audio content:

Attribute Description Example
src Specifies the URL of the audio file.
Try yourself
        
            <audio src="/media/audio/sample.mp3" controls></audio>
        
    
controls Specifies that audio controls should be displayed (such as play/pause buttons).
Try yourself
        
            <audio controls>
    <source src="/media/audio/sample.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>
        
    
autoplay Specifies that the audio will start playing as soon as it is ready.
Try yourself
        
            <audio src="/media/audio/sample.mp3" autoplay></audio>
        
    
loop Specifies that the audio will start over again, every time it is finished.
Try yourself
        
            <audio src="/media/audio/sample.mp3" loop autoplay></audio>
        
    

Using the Audio Element

Below are examples of how you can use the audio element in your HTML documents:

Example: Basic Audio
Try yourself
        
            <audio controls>
    <source src="/media/audio/sample.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>
        
    

This example shows an audio element with basic controls for play, pause, and volume adjustment.


Example: Autoplay Audio
Try yourself
        
            <audio src="/media/audio/sample.mp3" autoplay></audio>
        
    

This example shows an audio element that starts playing automatically when the page loads.


Important Notes

Here are some important notes and best practices for using the audio element: