HTML <audio> Element

To play an audio file in HTML, use the <audio> element:

Example:


        <audio controls>
            <source src="horse.ogg" type="audio/ogg">
            <source src="horse.mp3" type="audio/mp3">
        </audio>
            

The controls attribute adds audio controls, like play, pause, and volume.

HTML <audio> Autoplay and Muted:

To start an audio file automatically, use the autoplay and muted attributes:


        <audio autoplay muted>
            

HTML <video> Element

The HTML <video> element is used to show a video on a web page:

Example:


        <video width="320" height="240" controls>
            <source src="movie.mp4" type="video/mp4">
            <source src="movie.ogg" type="video/ogg">
        </video>
            

The controls attribute adds video controls, like play, pause, and volume.

It is a good idea to always include width and height attributes. If height and width are not set, the page might flicker while the video loads.